示例#1
0
MongoServer::~MongoServer()
{
    clearDatabases();
    _client->stopAndDelete();

    // MongoWorker "_client" does not deleted here, because it is now owned by
    // another thread (call to moveToThread() made in MongoWorker constructor).
    // It will be deleted by this thread by means of "deleteLater()", which
    // is also specified in MongoWorker constructor.
}
示例#2
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);
        }
    }
示例#3
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));
    }
示例#4
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;
}
void SQLToolWidget::connectToServer(void)
{
	try
	{
		if(connections_cmb->currentIndex()==connections_cmb->count()-1 &&
				ConnectionsConfigWidget::openConnectionsConfiguration(connections_cmb, true))
		{
			emit s_connectionsUpdateRequest();
		}
		else
		{
			Connection *conn=reinterpret_cast<Connection *>(connections_cmb->itemData(connections_cmb->currentIndex()).value<void *>());
			clearDatabases();

			if(conn)
			{
				import_helper.setConnection(*conn);
				DatabaseImportForm::listDatabases(import_helper, database_cmb);
				import_helper.closeConnection();

				if(sender()==connections_cmb && conn->isAutoBrowseDB())
				{
					database_cmb->setCurrentText(conn->getConnectionParam(Connection::PARAM_DB_NAME));
					browseDatabase();
				}
			}

			database_cmb->setEnabled(database_cmb->count() > 1);
			refresh_tb->setEnabled(database_cmb->isEnabled());
		}
	}
	catch(Exception &e)
	{
		throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
	}
}
示例#6
0
MongoServer::~MongoServer()
{
    clearDatabases();
    delete _connectionRecord;
    _connectionRecord=NULL;
}