Search in sources :

Example 66 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class PostgreDataSource method openConnection.

// //////////////////////////////////////////
// Connections
@Override
protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @Nullable JDBCExecutionContext context, @NotNull String purpose) throws DBCException {
    final DBPConnectionConfiguration conConfig = getContainer().getActualConnectionConfiguration();
    JDBCRemoteInstance instance = context == null ? null : context.getOwnerInstance();
    Connection pgConnection;
    if (instance != null) {
        log.debug("Initiate connection to " + getServerType().getServerTypeName() + " database [" + instance.getName() + "@" + conConfig.getHostName() + "] for " + purpose);
    }
    if (instance instanceof PostgreDatabase && instance.getName() != null && !CommonUtils.equalObjects(instance.getName(), conConfig.getDatabaseName())) {
        // If database was changed then use new name for connection
        final DBPConnectionConfiguration originalConfig = new DBPConnectionConfiguration(conConfig);
        try {
            // Patch URL with new database name
            if (CommonUtils.isEmpty(conConfig.getUrl()) || !CommonUtils.isEmpty(conConfig.getHostName())) {
                conConfig.setDatabaseName(instance.getName());
                conConfig.setUrl(getContainer().getDriver().getDataSourceProvider().getConnectionURL(getContainer().getDriver(), conConfig));
            }
            // else {
            // String url = conConfig.getUrl();
            // }
            pgConnection = super.openConnection(monitor, context, purpose);
        } finally {
            conConfig.setDatabaseName(originalConfig.getDatabaseName());
            conConfig.setUrl(originalConfig.getUrl());
        }
    } else {
        pgConnection = super.openConnection(monitor, context, purpose);
    }
    if (getServerType().supportsClientInfo() && !getContainer().getPreferenceStore().getBoolean(ModelPreferences.META_CLIENT_NAME_DISABLE)) {
        // Provide client info. Not supported by Redshift?
        try {
            pgConnection.setClientInfo(JDBCConstants.APPLICATION_NAME_CLIENT_PROPERTY, DBUtils.getClientApplicationName(getContainer(), context, purpose));
        } catch (Throwable e) {
            // just ignore
            log.debug(e);
        }
    }
    return pgConnection;
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) Connection(java.sql.Connection)

Example 67 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class PostgreDataSource method initializeRemoteInstance.

@Override
protected void initializeRemoteInstance(@NotNull DBRProgressMonitor monitor) throws DBException {
    activeDatabaseName = getContainer().getConnectionConfiguration().getBootstrap().getDefaultCatalogName();
    if (CommonUtils.isEmpty(activeDatabaseName)) {
        activeDatabaseName = getContainer().getConnectionConfiguration().getDatabaseName();
    }
    if (CommonUtils.isEmpty(activeDatabaseName)) {
        activeDatabaseName = PostgreConstants.DEFAULT_DATABASE;
    }
    databaseCache = new DatabaseCache();
    DBPConnectionConfiguration configuration = getContainer().getActualConnectionConfiguration();
    final boolean showNDD = CommonUtils.getBoolean(configuration.getProviderProperty(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB), false);
    List<PostgreDatabase> dbList = new ArrayList<>();
    if (!showNDD) {
        PostgreDatabase defDatabase = new PostgreDatabase(monitor, this, activeDatabaseName);
        dbList.add(defDatabase);
    } else {
        loadAvailableDatabases(monitor, configuration, dbList);
    }
    databaseCache.setCache(dbList);
    // Initiate default context
    getDefaultInstance().checkInstanceConnection(monitor, false);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 68 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class ConnectionPageWithAuth method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    DBPDataSourceContainer activeDataSource = getSite().getActiveDataSource();
    DBPAuthModelDescriptor selectedAuthModel = null;
    DBPConnectionConfiguration configuration = activeDataSource.getConnectionConfiguration();
    if (site.isNew() && CommonUtils.isEmpty(configuration.getUserName())) {
        configuration.setUserName(activeDataSource.getDriver().getDefaultUser());
    }
    String dsModelId = configuration.getAuthModelId();
    if (dsModelId != null) {
        selectedAuthModel = DBWorkbench.getPlatform().getDataSourceProviderRegistry().getAuthModel(dsModelId);
    }
    authModelSelector.loadSettings(getSite().getActiveDataSource(), selectedAuthModel, getDefaultAuthModelId(activeDataSource));
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPAuthModelDescriptor(org.jkiss.dbeaver.model.connection.DBPAuthModelDescriptor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 69 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class BigQueryConnectionPage method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    if (projectText != null) {
        String databaseName = connectionInfo.getDatabaseName();
        if (CommonUtils.isEmpty(databaseName)) {
            // $NON-NLS-1$
            databaseName = "";
        }
        projectText.setText(databaseName);
    }
    String additionalProjects = connectionInfo.getProperty(BigQueryConstants.DRIVER_PROP_ADDITIONAL_PROJECTS);
    if (additionalProjects != null) {
        extraProjectsText.setText(additionalProjects);
    }
    if (usernameText != null) {
        usernameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
    }
    if (authTypeCombo != null) {
        authTypeCombo.select(CommonUtils.toInt(connectionInfo.getProperty(BigQueryConstants.DRIVER_PROP_OAUTH_TYPE)));
    }
    String keyPath = connectionInfo.getProperty(BigQueryConstants.DRIVER_PROP_OAUTH_PVT_KEYPATH);
    if (keyPath != null && authCertFile != null) {
        authCertFile.setText(keyPath);
    }
    if (hostText != null) {
        if (CommonUtils.isEmpty(connectionInfo.getHostName())) {
            hostText.setText(BigQueryConstants.DEFAULT_HOST_NAME);
        } else {
            hostText.setText(connectionInfo.getHostName());
        }
    }
    if (portText != null) {
        if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
            portText.setText(String.valueOf(connectionInfo.getHostPort()));
        } else if (site.getDriver().getDefaultPort() != null) {
            portText.setText(site.getDriver().getDefaultPort());
        } else {
            // $NON-NLS-1$
            portText.setText("");
        }
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 70 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by dbeaver.

the class DB2ConnectionPage method saveSettings.

@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
    DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
    if (hostText != null) {
        connectionInfo.setHostName(hostText.getText().trim());
    }
    if (portText != null) {
        connectionInfo.setHostPort(portText.getText().trim());
    }
    if (dbText != null) {
        connectionInfo.setDatabaseName(dbText.getText().trim());
    }
    super.saveSettings(dataSource);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Aggregations

DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)172 DBException (org.jkiss.dbeaver.DBException)25 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)18 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)16 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)14 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)12 ArrayList (java.util.ArrayList)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 GridData (org.eclipse.swt.layout.GridData)10 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Button (org.eclipse.swt.widgets.Button)8 Group (org.eclipse.swt.widgets.Group)8 Label (org.eclipse.swt.widgets.Label)8 DBPDataSourceFolder (org.jkiss.dbeaver.model.DBPDataSourceFolder)7 Map (java.util.Map)6 Properties (java.util.Properties)6 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)6 File (java.io.File)5