Search in sources :

Example 46 with DBPConnectionConfiguration

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

the class ConfigImportWizard method adaptConnectionUrl.

protected void adaptConnectionUrl(ImportConnectionInfo connectionInfo) throws DBException {
    String sampleURL = connectionInfo.getDriverInfo().getSampleURL();
    if (connectionInfo.getDriver() != null) {
        sampleURL = connectionInfo.getDriver().getSampleURL();
    }
    // connectionInfo.getDriver()
    String url = connectionInfo.getUrl();
    if (url != null) {
        // Parse url
        final JDBCURL.MetaURL metaURL = JDBCURL.parseSampleURL(sampleURL);
        int sourceOffset = 0;
        List<String> urlComponents = metaURL.getUrlComponents();
        for (int i = 0, urlComponentsSize = urlComponents.size(); i < urlComponentsSize; i++) {
            String component = urlComponents.get(i);
            if (component.length() > 2 && component.charAt(0) == '{' && component.charAt(component.length() - 1) == '}' && metaURL.getAvailableProperties().contains(component.substring(1, component.length() - 1))) {
                // Property
                int partEnd;
                if (i < urlComponentsSize - 1) {
                    // Find next component
                    final String nextComponent = urlComponents.get(i + 1);
                    partEnd = url.indexOf(nextComponent, sourceOffset);
                    if (partEnd == -1) {
                        if (nextComponent.equals(":")) {
                            // Try to find another divider - dbvis sometimes contains bad sample URLs (e.g. for Oracle)
                            partEnd = url.indexOf("/", sourceOffset);
                        }
                        if (partEnd == -1) {
                            if (connectionInfo.getHost() == null) {
                                throw new DBException("Can't parse URL '" + url + "' with pattern '" + sampleURL + "'. String '" + nextComponent + "' not found after '" + component);
                            } else {
                                // We have connection properties anyway
                                url = null;
                                break;
                            }
                        }
                    }
                } else {
                    partEnd = url.length();
                }
                String propertyValue = url.substring(sourceOffset, partEnd);
                switch(component) {
                    case "{host}":
                        connectionInfo.setHost(propertyValue);
                        break;
                    case "{port}":
                        connectionInfo.setPort(propertyValue);
                        break;
                    case "{database}":
                        connectionInfo.setDatabase(propertyValue);
                        break;
                    default:
                        if (connectionInfo.getHost() == null) {
                            throw new DBException("Unsupported property " + component);
                        }
                }
                sourceOffset = partEnd;
            } else {
                // Static string
                sourceOffset += component.length();
            }
        }
    }
    if (url == null) {
        if (connectionInfo.getDriver() == null) {
            throw new DBCException("Can't detect target driver for '" + connectionInfo.getAlias() + "'");
        }
        if (connectionInfo.getHost() == null) {
            throw new DBCException("No URL and no host name - can't import connection '" + connectionInfo.getAlias() + "'");
        }
        // No URL - generate from props
        DBPConnectionConfiguration conConfig = new DBPConnectionConfiguration();
        conConfig.setHostName(connectionInfo.getHost());
        conConfig.setHostPort(connectionInfo.getPort());
        conConfig.setDatabaseName(connectionInfo.getDatabase());
        url = connectionInfo.getDriver().getDataSourceProvider().getConnectionURL(connectionInfo.getDriver(), conConfig);
        connectionInfo.setUrl(url);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBCException(org.jkiss.dbeaver.model.exec.DBCException) JDBCURL(org.jkiss.dbeaver.model.impl.jdbc.JDBCURL)

Example 47 with DBPConnectionConfiguration

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

the class PostgreConnectionPageAdvanced method loadSettings.

@Override
public void loadSettings() {
    // Load values from new connection info
    DBPPreferenceStore globalPrefs = DBWorkbench.getPlatform().getPreferenceStore();
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    setTitle(site.getActiveDataSource().getDriver().getName());
    showNonDefault.setSelection(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB), globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_NON_DEFAULT_DB)));
    showTemplates.setSelection(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_SHOW_TEMPLATES_DB), globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_TEMPLATES_DB)));
    showTemplates.setEnabled(showNonDefault.getSelection());
    showUnavailable.setSelection(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_SHOW_UNAVAILABLE_DB), globalPrefs.getBoolean(PostgreConstants.PROP_SHOW_UNAVAILABLE_DB)));
    showUnavailable.setEnabled(showNonDefault.getSelection());
    ddPlainBehaviorCombo.select(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_DD_PLAIN_STRING), globalPrefs.getBoolean(PostgreConstants.PROP_DD_PLAIN_STRING)) ? 0 : 1);
    ddTagBehaviorCombo.select(CommonUtils.getBoolean(connectionInfo.getProviderProperty(PostgreConstants.PROP_DD_TAG_STRING), globalPrefs.getBoolean(PostgreConstants.PROP_DD_TAG_STRING)) ? 0 : 1);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 48 with DBPConnectionConfiguration

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

the class ConnectionPageNetworkHandler method setConnectionConfigProfile.

private void setConnectionConfigProfile(String profileName) {
    activeProfile = CommonUtils.isEmpty(profileName) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileName);
    DBPDataSourceContainer dataSource = site.getActiveDataSource();
    DBPConnectionConfiguration cfg = dataSource.getConnectionConfiguration();
    String oldProfileId = cfg.getConfigProfileName();
    saveSettings(site.getActiveDataSource());
    if (activeProfile != null) {
        cfg.setConfigProfile(activeProfile);
        handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
        if (handlerConfiguration == null) {
            handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, dataSource);
        }
    } else {
        cfg.setConfigProfile(null);
    }
    site.firePropertyChange(this, PROP_CONFIG_PROFILE, oldProfileId, activeProfile == null ? null : activeProfile.getProfileName());
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 49 with DBPConnectionConfiguration

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

the class ConnectionPageNetworkHandler method updateProfileList.

private void updateProfileList() {
    DBPConnectionConfiguration cfg = site.getActiveDataSource().getConnectionConfiguration();
    String profileId = cfg.getConfigProfileName();
    activeProfile = CommonUtils.isEmpty(profileId) ? null : site.getProject().getDataSourceRegistry().getNetworkProfile(profileId);
    // Refresh profile list
    profileCombo.removeAll();
    profileCombo.add("");
    for (DBWNetworkProfile profile : site.getProject().getDataSourceRegistry().getNetworkProfiles()) {
        profileCombo.add(profile.getProfileName());
        if (CommonUtils.equalObjects(profileId, profile.getProfileName())) {
            profileCombo.select(profileCombo.getItemCount() - 1);
        }
    }
    // Update settings from profile
    if (activeProfile != null) {
    }
    // Update page controls
    handlerConfiguration = cfg.getHandler(handlerDescriptor.getId());
    if (handlerConfiguration == null) {
        handlerConfiguration = new DBWHandlerConfiguration(handlerDescriptor, site.getActiveDataSource());
    }
    useHandlerCheck.setSelection(handlerConfiguration.isEnabled());
    configurator.loadSettings(handlerConfiguration);
    enableHandlerContent();
}
Also used : DBWNetworkProfile(org.jkiss.dbeaver.model.net.DBWNetworkProfile) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)

Example 50 with DBPConnectionConfiguration

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

the class ConnectionPageGeneral method saveSettings.

@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
    if (dataSourceDescriptor != null && !activated) {
        // No changes anyway
        return;
    }
    final DBPConnectionConfiguration confConfig = dataSource.getConnectionConfiguration();
    String name = connectionNameChanged ? connectionNameText.getText() : generateConnectionName(getWizard().getPageSettings());
    dataSource.setName(name);
    dataSource.setFolder(dataSourceFolder);
    if (connectionTypeCombo.getSelectionIndex() >= 0) {
        confConfig.setConnectionType(connectionTypeCombo.getItem(connectionTypeCombo.getSelectionIndex()));
    }
    DataSourceDescriptor dsDescriptor = (DataSourceDescriptor) dataSource;
    final String description = descriptionText.getText();
    if (description.isEmpty()) {
        dsDescriptor.setDescription(null);
    } else {
        dsDescriptor.setDescription(description);
    }
    if (this.navigatorSettings == null) {
        this.navigatorSettings = new DataSourceNavigatorSettings(getWizard().getSelectedNavigatorSettings());
    }
    dsDescriptor.setNavigatorSettings(this.navigatorSettings);
    dsDescriptor.setConnectionReadOnly(this.readOnlyConnection.getSelection());
    dsDescriptor.setModifyPermissions(this.accessRestrictions);
    for (FilterInfo filterInfo : filters) {
        if (filterInfo.filter != null) {
            dataSource.setObjectFilter(filterInfo.type, null, filterInfo.filter);
        }
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DataSourceNavigatorSettings(org.jkiss.dbeaver.registry.DataSourceNavigatorSettings) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

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