예제 #1
0
bool ossimElevManager::loadElevationPath(const ossimFilename& path)
{
   bool result = false;
   ossimElevationDatabase* database = ossimElevationDatabaseRegistry::instance()->open(path);
   
   if(!database&&path.isDir())
   {
      ossimDirectory dir;
      
      if(dir.open(path))
      {
         ossimFilename file;
         dir.getFirst(file, ossimDirectory::OSSIM_DIR_DIRS);
         do
         {
            database = ossimElevationDatabaseRegistry::instance()->open(file);
            if(database)
            {
               result = true;
               addDatabase(database);
            }
         }while(dir.getNext(file));
      }
   }
   else if(database)
   {
      result = true;
      addDatabase(database);
   }
   
   return result;
}
예제 #2
0
/*!
 * \brief Database::Database
 * \param path path to sql database file
 */
Database::Database(QString path, QString driver) : QSqlDatabase(addDatabase(driver))
{
  setHostName("localhost");
  setDatabaseName(path);
  Q_ASSERT(open());
  query = QSqlQuery(*this);
}
예제 #3
0
int DbManager::addDatabase(QString driver, QString host, QString user,
                           QString pswd, QString dbnm, QString alias,
                           bool usesOdbc, bool save) {
    SqlWrapper *wrapper = PluginManager::availableWrapper(driver);
    if (usesOdbc) {
        driver = "QODBC";
    }

    // need to store what plugin what used
    QString plid = wrapper ? wrapper->plid() : "";
    return addDatabase(driver, host, user, pswd, dbnm, alias, plid, save);
}
예제 #4
0
    void MongoServer::handle(EstablishConnectionResponse *event) {
        if (event->isError()) {
            _isConnected = false;

            std::stringstream ss("Unknown error");
            auto eventErrorReason = event->errorReason;
            if (EstablishConnectionResponse::ErrorReason::MongoSslConnection == eventErrorReason)
            {
                auto reason = ConnectionFailedEvent::SslConnection;
                ss.clear();
                ss << "Cannot connect to the MongoDB at " << connectionRecord()->getFullAddress()
                    << ".\n\nError:\n" << "SSL connection failure: " << event->error().errorMessage();
                _app->fireConnectionFailedEvent(_handle, _connectionType, ss.str(), reason);
            }
            else
            {
                auto reason = (EstablishConnectionResponse::ErrorReason::MongoAuth == eventErrorReason) ?
                    ConnectionFailedEvent::MongoAuth : ConnectionFailedEvent::MongoConnection;
                ss.clear();
                ss << "Cannot connect to the MongoDB at " << connectionRecord()->getFullAddress()
                    << ".\n\nError:\n" << event->error().errorMessage();
                _app->fireConnectionFailedEvent(_handle, _connectionType, ss.str(), reason);
            }

            // When connection cannot be established, we should cleanup this instance of MongoServer if it wasn't
            // shown in UI (i.e. it is not a Secondary connection that is used for shells tab)
            if (_connectionType == ConnectionPrimary || _connectionType == ConnectionTest)
            {
                _app->closeServer(this);
            }

            return;
        }

        const ConnectionInfo &info = event->info();
        _version = info._version;
        _storageEngineType = info._storageEngineType;
        _isConnected = true;

        _bus->publish(new ConnectionEstablishedEvent(this, _connectionType));

        // Do nothing if this is not a "primary" connection
        if (_connectionType != ConnectionPrimary)
            return;

        clearDatabases();
        for (std::vector<std::string>::const_iterator it = info._databases.begin(); it != info._databases.end(); ++it) {
            const std::string &name = *it;
            MongoDatabase *db  = new MongoDatabase(this, name);
            addDatabase(db);
        }
    }
예제 #5
0
void MainWindow::onNewDatabase()
{
	QString databaseName = getNewDatabaseName();
	if(databaseName.length() == 0)
	{
		QMessageBox::critical(this,
				tr("Sqlite"),
				tr("Invalid file name!"));
		return;
	}
	qDebug() << databaseName;
	createDatabase(databaseName);
	addDatabase(databaseName);
}
예제 #6
0
    void MongoServer::handle(LoadDatabaseNamesResponse *event) {
        if (event->isError()) {
            _bus->publish(new DatabaseListLoadedEvent(this, event->error()));
            return;
        }

        clearDatabases();
        for (std::vector<std::string>::iterator it = event->databaseNames.begin(); it != event->databaseNames.end(); ++it) {
            const std::string &name = *it;
            MongoDatabase *db  = new MongoDatabase(this, name);
            addDatabase(db);
        }

        _bus->publish(new DatabaseListLoadedEvent(this, _databases));
    }
예제 #7
0
void MongoServer::handle(EstablishConnectionResponse *event)
{
    const ConnectionInfo &info = event->info();
    _isConnected = !event->isError();
    if (event->isError()) {
        AppRegistry::instance().bus()->publish(new ConnectionFailedEvent(this, event->error()));
    } else if (_visible) {
        AppRegistry::instance().bus()->publish(new ConnectionEstablishedEvent(this));
        clearDatabases();
        for(std::vector<std::string>::const_iterator it = info._databases.begin(); it != info._databases.end(); ++it) {
            const std::string &name = *it;
            MongoDatabase *db  = new MongoDatabase(this, name);
            addDatabase(db);
        }
    }
    _version = info._version;
}
예제 #8
0
String DatabaseTracker::fullPathForDatabaseNoLock(SecurityOrigin* origin, const String& name, bool createIfNotExists)
{
    ASSERT(!m_databaseGuard.tryLock());

    String originIdentifier = origin->databaseIdentifier();
    String originPath = this->originPath(origin);

    // Make sure the path for this SecurityOrigin exists
    if (createIfNotExists && !SQLiteFileSystem::ensureDatabaseDirectoryExists(originPath))
        return String();

    // See if we have a path for this database yet
    if (!m_database.isOpen())
        return String();
    SQLiteStatement statement(m_database, "SELECT path FROM Databases WHERE origin=? AND name=?;");

    if (statement.prepare() != SQLITE_OK)
        return String();

    statement.bindText(1, originIdentifier);
    statement.bindText(2, name);

    int result = statement.step();

    if (result == SQLITE_ROW)
        return SQLiteFileSystem::appendDatabaseFileNameToPath(originPath, statement.getColumnText(0));
    if (!createIfNotExists)
        return String();

    if (result != SQLITE_DONE) {
        LOG_ERROR("Failed to retrieve filename from Database Tracker for origin %s, name %s", originIdentifier.ascii().data(), name.ascii().data());
        return String();
    }
    statement.finalize();

    String fileName = generateDatabaseFileName();

    if (!addDatabase(origin, name, fileName))
        return String();

    // If this origin's quota is being tracked (open handle to a database in this origin), add this new database
    // to the quota manager now
    String fullFilePath = SQLiteFileSystem::appendDatabaseFileNameToPath(originPath, fileName);

    return fullFilePath;
}
예제 #9
0
/*!
 * \brief Database::Database
 * \param path Path to SQL Database file
 * \param driver QString identifier for the specific flavor of SQL we are using.
 */
Database::Database(QString path, QString driver) : QSqlDatabase(addDatabase(driver))
{
    setHostName("localhost");
    setDatabaseName(path);

    // If the database successfully opens
    if(open())
    {
        qDebug() << "Database opened successfully";
    }
    else
    {
        // Output the last error message from the database
        qDebug() << this->lastError().text();
    }

    //  This is for activating foreign key support.
    QSqlQuery query;
    query.exec("PRAGMA foreign_keys = ON;");
}
예제 #10
0
파일: server.cpp 프로젝트: joonhwan/Waffle
//-----------------------------------------------------------------------------
DatabasePtr Server::addDatabase()
{
    DatabasePtr database(new Database());
    addDatabase(database);
    return database;
}
예제 #11
0
/**
 * Method to the load (recreate) the state of an object from a keyword
 * list.  Return true if ok or false on error.
 */
bool ossimElevManager::loadState(const ossimKeywordlist& kwl, const char* prefix)
{
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
      << "DEBUG ossimElevManager::loadState: Entered..."
      << std::endl;
   }
   if(!ossimElevSource::loadState(kwl, prefix))
   {
      return false;
   }
   ossimString copyPrefix(prefix);
   ossimString elevationOffset = kwl.find(copyPrefix, "elevation_offset");
   ossimString defaultHeightAboveEllipsoid = kwl.find(copyPrefix, "default_height_above_ellipsoid");
   ossimString useGeoidIfNull = kwl.find(copyPrefix, "use_geoid_if_null");
   ossimString elevRndRbnSize = kwl.find(copyPrefix, "threads");

   if(!elevationOffset.empty())
   {
      m_elevationOffset = elevationOffset.toDouble();
   }
   if(!defaultHeightAboveEllipsoid.empty())
   {
      m_defaultHeightAboveEllipsoid = defaultHeightAboveEllipsoid.toDouble();
   }
   if(!useGeoidIfNull.empty())
   {
      m_useGeoidIfNullFlag = useGeoidIfNull.toBool();
   }

   ossim_uint32 numThreads = 1;
   if(!elevRndRbnSize.empty())
   {
      if (elevRndRbnSize.contains("yes") || elevRndRbnSize.contains("true"))
         numThreads = ossim::getNumberOfThreads();
      else if (elevRndRbnSize.contains("no") || elevRndRbnSize.contains("false"))
         numThreads = 1;
      else
      {
         numThreads = elevRndRbnSize.toUInt32();
         numThreads = numThreads > 0 ? numThreads : 1;
      }
   }
   setRoundRobinMaxSize(numThreads);

   ossimString regExpression =  ossimString("^(") + copyPrefix + "elevation_source[0-9]+.)";
   vector<ossimString> keys = kwl.getSubstringKeyList( regExpression );
   long numberOfSources = (long)keys.size();
   ossim_uint32 offset = (ossim_uint32)(copyPrefix+"elevation_source").size();
   ossim_uint32 idx = 0;
   std::vector<int> theNumberList(numberOfSources);
   for(idx = 0; idx < theNumberList.size();++idx)
   {
      ossimString numberStr(keys[idx].begin() + offset,
                            keys[idx].end());
      theNumberList[idx] = numberStr.toInt();
   }
   std::sort(theNumberList.begin(), theNumberList.end());
   
   for(idx=0;idx < theNumberList.size();++idx)
   {
      ossimString newPrefix = copyPrefix;
      newPrefix += ossimString("elevation_source");
      newPrefix += ossimString::toString(theNumberList[idx]);
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG ossimElevManager::loadState:"
         << "\nLooking for key:  " << newPrefix
         << std::endl;
      }

      //---
      // Check for enabled key first.  Default, if not found is true for
      // legacy compatibility.
      //---
      bool enabled = true;
      std::string key = newPrefix.string();
      key += ".";
      key += ossimKeywordNames::ENABLED_KW;
      std::string value = kwl.findKey( key );
      if ( value.size() )
      {
         enabled = ossimString(value).toBool();
      }

      if ( enabled )
      {
         // first check if new way is supported
         ossimRefPtr<ossimElevationDatabase> database =
            ossimElevationDatabaseRegistry::instance()->createDatabase(kwl, newPrefix+".");
         if(database.valid())
         {
            if (traceDebug())
            {
               ossimNotify(ossimNotifyLevel_DEBUG)
                  << "DEBUG ossimElevManager::loadState:"
                  << "\nadding elevation database:  "
                  << database->getClassName()
                  << ": " << database->getConnectionString()
                  << std::endl;
            }  
            addDatabase(database.get());
         }
         else
         {
            // if not new elevation load verify the old way by
            // looking at the filename
            //
            ossimString fileKey = newPrefix;
            fileKey += ".";
            fileKey += ossimKeywordNames::FILENAME_KW;
            ossimString lookup = kwl.find(prefix, fileKey.c_str());
            if (!lookup.empty())
            {
               loadElevationPath(ossimFilename(lookup));
            } // end if lookup
         }
      }

   } // end for loop

   return true;
}
예제 #12
0
/**
 * Method to the load (recreate) the state of an object from a keyword
 * list.  Return true if ok or false on error.
 */
bool ossimElevManager::loadState(const ossimKeywordlist& kwl,
                                 const char* prefix)
{
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
      << "DEBUG ossimElevManager::loadState: Entered..."
      << std::endl;
   }
   if(!ossimElevSource::loadState(kwl, prefix))
   {
      return false;
   }
   ossimString copyPrefix(prefix);
   ossimString elevationOffset = kwl.find(copyPrefix, "elevation_offset");
   ossimString defaultHeightAboveEllipsoid = kwl.find(copyPrefix, "default_height_above_ellipsoid");
   ossimString useGeoidIfNull = kwl.find(copyPrefix, "use_geoid_if_null");

   if(!elevationOffset.empty())
   {
      m_elevationOffset = elevationOffset.toDouble();
   }
   if(!defaultHeightAboveEllipsoid.empty())
   {
      m_defaultHeightAboveEllipsoid = defaultHeightAboveEllipsoid.toDouble();
   }
   if(!useGeoidIfNull.empty())
   {
      m_useGeoidIfNullFlag = useGeoidIfNull.toBool();
   }
   ossimString regExpression =  ossimString("^(") + copyPrefix + "elevation_source[0-9]+.)";
   vector<ossimString> keys =
   kwl.getSubstringKeyList( regExpression );
   long numberOfSources = (long)keys.size();
   ossim_uint32 offset = (ossim_uint32)(copyPrefix+"elevation_source").size();
   ossim_uint32 idx = 0;
   std::vector<int> theNumberList(numberOfSources);
   for(idx = 0; idx < theNumberList.size();++idx)
   {
      ossimString numberStr(keys[idx].begin() + offset,
                            keys[idx].end());
      theNumberList[idx] = numberStr.toInt();
   }
   std::sort(theNumberList.begin(), theNumberList.end());
   
   for(idx=0;idx < theNumberList.size();++idx)
   {
      ossimString newPrefix = copyPrefix;
      newPrefix += ossimString("elevation_source");
      newPrefix += ossimString::toString(theNumberList[idx]);
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG ossimElevManager::loadState:"
         << "\nLooking for key:  " << newPrefix
         << std::endl;
      }
      // first check if new way is supported
      //
      ossimRefPtr<ossimElevationDatabase> database = ossimElevationDatabaseRegistry::instance()->createDatabase(kwl, newPrefix+".");
      if(database.valid())
      {
        if (traceDebug())
        {
           ossimNotify(ossimNotifyLevel_DEBUG)
           << "DEBUG ossimElevManager::loadState:"
           << "\nadding elevation database:  "
           << database->getClassName()
           << ": " << database->getConnectionString()
           << std::endl;
        }  
        addDatabase(database.get());
      }
      else
      {
         // if not new elevation load verify the old way by
         // looking at the filename
         //
         ossimString fileKey = newPrefix;
         fileKey += ".";
         fileKey += ossimKeywordNames::FILENAME_KW;
         ossimString lookup = kwl.find(prefix, fileKey.c_str());
         if (!lookup.empty())
         {
            loadElevationPath(ossimFilename(lookup));
         } // end if lookup
      }
   } // end for loop
   return true;
}