Search in sources :

Example 41 with DBPConnectionConfiguration

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

the class OracleConnectionExtraPage method loadSettings.

@Override
public void loadSettings() {
    // oraHomeSelector.setVisible(isOCI);
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    Map<String, String> providerProperties = connectionInfo.getProviderProperties();
    // Settings
    final Object nlsLanguage = providerProperties.get(OracleConstants.PROP_SESSION_LANGUAGE);
    if (nlsLanguage != null) {
        languageCombo.setText(nlsLanguage.toString());
    }
    final Object nlsTerritory = providerProperties.get(OracleConstants.PROP_SESSION_TERRITORY);
    if (nlsTerritory != null) {
        territoryCombo.setText(nlsTerritory.toString());
    }
    nlsDateFormat.setText(CommonUtils.toString(providerProperties.get(OracleConstants.PROP_SESSION_NLS_DATE_FORMAT)));
    nlsTimestampFormat.setText(CommonUtils.toString(providerProperties.get(OracleConstants.PROP_SESSION_NLS_TIMESTAMP_FORMAT)));
    nlsLengthFormat.setText(CommonUtils.toString(providerProperties.get(OracleConstants.PROP_SESSION_NLS_LENGTH_FORMAT)));
    nlsCurrencyFormat.setText(CommonUtils.toString(providerProperties.get(OracleConstants.PROP_SESSION_NLS_CURRENCY_FORMAT)));
    final Object checkSchemaContent = providerProperties.get(OracleConstants.PROP_CHECK_SCHEMA_CONTENT);
    if (checkSchemaContent != null) {
        hideEmptySchemasCheckbox.setSelection(CommonUtils.getBoolean(checkSchemaContent, false));
    }
    showDBAAlwaysCheckbox.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_ALWAYS_SHOW_DBA), false));
    useDBAViewsCheckbox.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_ALWAYS_USE_DBA_VIEWS), false));
    useSysSchemaCheckbox.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_METADATA_USE_SYS_SCHEMA), false));
    useSimpleConstraints.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_METADATA_USE_SIMPLE_CONSTRAINTS), false));
    useRuleHint.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_USE_RULE_HINT), false));
    useOptimizerHint.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_USE_META_OPTIMIZER), false));
    useAlternativeTableMetadataQuery.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_METADATA_USE_ALTERNATIVE_TABLE_QUERY), false));
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 42 with DBPConnectionConfiguration

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

the class SSHTunnelConfiguratorUI method testTunnelConnection.

private void testTunnelConnection() {
    DBWHandlerConfiguration configuration = new DBWHandlerConfiguration(savedConfiguration);
    configuration.setProperties(Collections.emptyMap());
    saveSettings(configuration);
    DBPDataSourceContainer dataSource = configuration.getDataSource();
    if (dataSource != null) {
        configuration.resolveDynamicVariables(new DataSourceVariableResolver(dataSource, dataSource.getConnectionConfiguration()));
    } else {
        configuration.resolveDynamicVariables(SystemVariablesResolver.INSTANCE);
    }
    try {
        final String[] tunnelVersions = new String[2];
        UIUtils.runInProgressDialog(monitor -> {
            monitor.beginTask("Instantiate SSH tunnel", 2);
            SSHTunnelImpl tunnel = new SSHTunnelImpl();
            DBPConnectionConfiguration connectionConfig = new DBPConnectionConfiguration();
            connectionConfig.setHostName("localhost");
            connectionConfig.setHostPort(configuration.getStringProperty(DBWHandlerConfiguration.PROP_PORT));
            try {
                monitor.subTask("Initialize tunnel");
                tunnel.initializeHandler(monitor, DBWorkbench.getPlatform(), configuration, connectionConfig);
                monitor.worked(1);
                // Get info
                tunnelVersions[0] = tunnel.getImplementation().getClientVersion();
                tunnelVersions[1] = tunnel.getImplementation().getServerVersion();
                // Close it
                monitor.subTask("Close tunnel");
                tunnel.closeTunnel(monitor);
                monitor.worked(1);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
            monitor.done();
        });
        MessageDialog.openInformation(hostText.getShell(), ModelMessages.dialog_connection_wizard_start_connection_monitor_success, "Connected!\n\nClient version: " + tunnelVersions[0] + "\nServer version: " + tunnelVersions[1]);
    } catch (InvocationTargetException ex) {
        DBWorkbench.getPlatformUI().showError(CoreMessages.dialog_connection_wizard_start_dialog_error_title, null, GeneralUtils.makeExceptionStatus(ex.getTargetException()));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) SSHTunnelImpl(org.jkiss.dbeaver.model.net.ssh.SSHTunnelImpl) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 43 with DBPConnectionConfiguration

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

the class SSHImplementationAbstract method initTunnel.

@Override
public DBPConnectionConfiguration initTunnel(DBRProgressMonitor monitor, DBPPlatform platform, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo) throws DBException, IOException {
    String dbPortString = connectionInfo.getHostPort();
    if (CommonUtils.isEmpty(dbPortString)) {
        dbPortString = configuration.getDriver().getDefaultPort();
        if (CommonUtils.isEmpty(dbPortString)) {
            throw new DBException("Database port not specified and no default port number for driver '" + configuration.getDriver().getName() + "'");
        }
    }
    String sshAuthType = configuration.getStringProperty(SSHConstants.PROP_AUTH_TYPE);
    String sshHost = configuration.getStringProperty(DBWHandlerConfiguration.PROP_HOST);
    int sshPortNum = configuration.getIntProperty(DBWHandlerConfiguration.PROP_PORT);
    int aliveInterval = configuration.getIntProperty(SSHConstants.PROP_ALIVE_INTERVAL);
    int connectTimeout = configuration.getIntProperty(SSHConstants.PROP_CONNECT_TIMEOUT);
    String sshLocalHost = CommonUtils.toString(configuration.getProperty(SSHConstants.PROP_LOCAL_HOST));
    int sshLocalPort = configuration.getIntProperty(SSHConstants.PROP_LOCAL_PORT);
    String sshRemoteHost = CommonUtils.toString(configuration.getProperty(SSHConstants.PROP_REMOTE_HOST));
    int sshRemotePort = configuration.getIntProperty(SSHConstants.PROP_REMOTE_PORT);
    // String aliveCount = properties.get(SSHConstants.PROP_ALIVE_COUNT);
    if (CommonUtils.isEmpty(sshHost)) {
        throw new DBException("SSH host not specified");
    }
    if (sshPortNum == 0) {
        throw new DBException("SSH port not specified");
    }
    if (CommonUtils.isEmpty(configuration.getUserName())) {
        configuration.setUserName(System.getProperty(StandardConstants.ENV_USER_NAME));
    }
    if (sshLocalPort == 0) {
        if (savedLocalPort != 0) {
            sshLocalPort = savedLocalPort;
        } else if (platform != null) {
            sshLocalPort = SSHUtils.findFreePort(platform);
        }
    }
    if (CommonUtils.isEmpty(sshRemoteHost)) {
        sshRemoteHost = connectionInfo.getHostName();
    }
    if (sshRemotePort == 0 && configuration.getDriver() != null) {
        sshRemotePort = CommonUtils.toInt(connectionInfo.getHostPort());
    }
    SSHConstants.AuthType authType = SSHConstants.AuthType.PASSWORD;
    if (sshAuthType != null) {
        authType = SSHConstants.AuthType.valueOf(sshAuthType);
    }
    File privKeyFile = null;
    String privKeyPath = configuration.getStringProperty(SSHConstants.PROP_KEY_PATH);
    if (authType == SSHConstants.AuthType.PUBLIC_KEY) {
        if (CommonUtils.isEmpty(privKeyPath)) {
            throw new DBException("Private key path is empty");
        }
        privKeyFile = new File(privKeyPath);
        if (!privKeyFile.exists()) {
            throw new DBException("Private key file '" + privKeyFile.getAbsolutePath() + "' doesn't exist");
        }
    }
    if (authType == SSHConstants.AuthType.AGENT) {
        try {
            agentProxy = new AgentProxy(new PageantConnector());
            log.debug("SSH: Connected with pageant");
        } catch (Exception e) {
            log.debug("pageant connect exception", e);
        }
        if (agentProxy == null) {
            try {
                USocketFactory udsf = new JNAUSocketFactory();
                agentProxy = new AgentProxy(new SSHAgentConnector(udsf));
                log.debug("SSH: Connected with ssh-agent");
            } catch (Exception e) {
                log.debug("ssh-agent connection exception", e);
            }
        }
        if (agentProxy == null) {
            throw new DBException("Unable to initialize SSH agent");
        }
    }
    if (connectTimeout == 0) {
        connectTimeout = SSHConstants.DEFAULT_CONNECT_TIMEOUT;
    }
    monitor.subTask("Initiating tunnel at '" + sshHost + "'");
    setupTunnel(monitor, configuration, sshHost, aliveInterval, sshPortNum, privKeyFile, connectTimeout, sshLocalHost, sshLocalPort, sshRemoteHost, sshRemotePort);
    savedLocalPort = sshLocalPort;
    savedConfiguration = configuration;
    savedConnectionInfo = connectionInfo;
    connectionInfo = new DBPConnectionConfiguration(connectionInfo);
    // Replace database host/port and URL
    if (CommonUtils.isEmpty(sshLocalHost)) {
        connectionInfo.setHostName(SSHConstants.LOCALHOST_NAME);
    } else {
        connectionInfo.setHostName(sshLocalHost);
    }
    connectionInfo.setHostPort(Integer.toString(sshLocalPort));
    if (configuration.getDriver() != null) {
        // Driver can be null in case of orphan tunnel config (e.g. in network profile)
        String newURL = configuration.getDriver().getDataSourceProvider().getConnectionURL(configuration.getDriver(), connectionInfo);
        connectionInfo.setUrl(newURL);
    }
    return connectionInfo;
}
Also used : DBException(org.jkiss.dbeaver.DBException) AgentProxy(com.jcraft.jsch.agentproxy.AgentProxy) JNAUSocketFactory(com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory) IOException(java.io.IOException) DBException(org.jkiss.dbeaver.DBException) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) JNAUSocketFactory(com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory) USocketFactory(com.jcraft.jsch.agentproxy.USocketFactory) SSHAgentConnector(com.jcraft.jsch.agentproxy.connector.SSHAgentConnector) PageantConnector(com.jcraft.jsch.agentproxy.connector.PageantConnector) File(java.io.File)

Example 44 with DBPConnectionConfiguration

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

the class BigQueryConnectionPage method saveSettings.

@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
    DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
    if (projectText != null) {
        connectionInfo.setDatabaseName(projectText.getText().trim());
    }
    if (extraProjectsText != null) {
        connectionInfo.setProperty(BigQueryConstants.DRIVER_PROP_ADDITIONAL_PROJECTS, extraProjectsText.getText().trim());
    }
    if (usernameText != null) {
        connectionInfo.setUserName(usernameText.getText().trim());
    }
    if (authTypeCombo != null) {
        connectionInfo.setProperty(BigQueryConstants.DRIVER_PROP_OAUTH_TYPE, String.valueOf(authTypeCombo.getSelectionIndex()));
    }
    if (authCertFile != null) {
        connectionInfo.setProperty(BigQueryConstants.DRIVER_PROP_OAUTH_PVT_KEYPATH, authCertFile.getText().trim());
    }
    if (hostText != null) {
        connectionInfo.setHostName(hostText.getText().trim());
    }
    if (portText != null) {
        connectionInfo.setHostPort(portText.getText().trim());
    }
    super.saveSettings(dataSource);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 45 with DBPConnectionConfiguration

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

the class AthenaConnectionPage method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    if (awsRegionCombo != null) {
        awsRegionCombo.removeAll();
        for (AWSRegion region : AWSRegion.values()) {
            awsRegionCombo.add(region.getId());
        }
        if (!CommonUtils.isEmpty(connectionInfo.getServerName())) {
            awsRegionCombo.setText(connectionInfo.getServerName());
        }
        if (awsRegionCombo.getText().isEmpty()) {
            awsRegionCombo.setText(AWSRegion.us_west_1.getId());
        }
    }
    if (s3LocationText != null) {
        String databaseName = connectionInfo.getDatabaseName();
        if (CommonUtils.isEmpty(databaseName)) {
            // $NON-NLS-1$
            databaseName = "s3://";
        }
        s3LocationText.setText(databaseName);
    }
    if (accessKeyText != null) {
        accessKeyText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
    }
    if (passwordText != null) {
        passwordText.setText(CommonUtils.notEmpty(connectionInfo.getUserPassword()));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) AWSRegion(org.jkiss.dbeaver.ext.athena.model.AWSRegion)

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