Search in sources :

Example 46 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class PrefPageProjectNetworkProfiles method enableHandlerContent.

private void enableHandlerContent(NetworkHandlerDescriptor descriptor) {
    HandlerBlock handlerBlock = configurations.get(descriptor);
    DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(selectedProfile);
    handlerBlock.useHandlerCheck.setSelection(handlerConfiguration != null && handlerConfiguration.isEnabled());
    if (handlerConfiguration != null && handlerConfiguration.isEnabled()) {
        if (handlerBlock.blockEnableState != null) {
            handlerBlock.blockEnableState.restore();
            handlerBlock.blockEnableState = null;
        }
    } else if (handlerBlock.blockEnableState == null) {
        handlerBlock.blockEnableState = ControlEnableState.disable(handlerBlock.blockControl);
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)

Example 47 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class PrefPageProjectNetworkProfiles method createHandlerTab.

private void createHandlerTab(final NetworkHandlerDescriptor descriptor) {
    IObjectPropertyConfigurator<DBWHandlerConfiguration> configurator;
    try {
        String implName = descriptor.getHandlerType().getImplName();
        UIPropertyConfiguratorDescriptor configDescriptor = UIPropertyConfiguratorRegistry.getInstance().getDescriptor(implName);
        if (configDescriptor == null) {
            return;
        }
        configurator = configDescriptor.createConfigurator();
    } catch (DBException e) {
        log.error("Can't create network configurator '" + descriptor.getId() + "'", e);
        return;
    }
    allHandlers.add(descriptor);
    TabItem tabItem = new TabItem(handlersFolder, SWT.NONE);
    tabItem.setText(descriptor.getLabel());
    tabItem.setToolTipText(descriptor.getDescription());
    tabItem.setData(descriptor);
    Composite composite = new Composite(handlersFolder, SWT.NONE);
    tabItem.setControl(composite);
    composite.setLayout(new GridLayout(1, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    final Button useHandlerCheck = UIUtils.createCheckbox(composite, NLS.bind(CoreMessages.dialog_tunnel_checkbox_use_handler, descriptor.getLabel()), false);
    useHandlerCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (selectedProfile == null) {
                useHandlerCheck.setSelection(false);
                UIUtils.showMessageBox(getShell(), "No profile", "Select existing profile or create a new one", SWT.ICON_INFORMATION);
                return;
            }
            HandlerBlock handlerBlock = configurations.get(descriptor);
            DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(selectedProfile);
            if (handlerConfiguration == null) {
                handlerConfiguration = new DBWHandlerConfiguration(descriptor, null);
                handlerBlock.loadedConfigs.put(selectedProfile, handlerConfiguration);
            }
            handlerConfiguration.setEnabled(useHandlerCheck.getSelection());
            enableHandlerContent(descriptor);
        }
    });
    Composite handlerComposite = UIUtils.createPlaceholder(composite, 1);
    configurations.put(descriptor, new HandlerBlock(configurator, handlerComposite, useHandlerCheck));
    handlerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    configurator.createControl(handlerComposite, this::updateApplyButton);
    enableHandlerContent(descriptor);
}
Also used : DBException(org.jkiss.dbeaver.DBException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) UIPropertyConfiguratorDescriptor(org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 48 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class PrefPageProjectNetworkProfiles method saveHandlerSettings.

/**
 * Saves state of UI controls to handler configuration
 */
private void saveHandlerSettings() {
    if (selectedProfile == null) {
        return;
    }
    for (TabItem handlerTab : handlersFolder.getItems()) {
        NetworkHandlerDescriptor handler = (NetworkHandlerDescriptor) handlerTab.getData();
        HandlerBlock handlerBlock = configurations.get(handler);
        DBWHandlerConfiguration handlerConfiguration = handlerBlock.loadedConfigs.get(selectedProfile);
        if (handlerBlock.useHandlerCheck.getSelection()) {
            if (handlerConfiguration == null) {
                handlerConfiguration = new DBWHandlerConfiguration(handler, null);
            }
            handlerConfiguration.setProperties(Collections.emptyMap());
            handlerBlock.configurator.saveSettings(handlerConfiguration);
        }
    }
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) NetworkHandlerDescriptor(org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor)

Example 49 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class SQLServerDataSource method getAllConnectionProperties.

@Override
protected Properties getAllConnectionProperties(@NotNull DBRProgressMonitor monitor, JDBCExecutionContext context, String purpose, DBPConnectionConfiguration connectionInfo) throws DBCException {
    Properties properties = super.getAllConnectionProperties(monitor, context, purpose, connectionInfo);
    if (!getContainer().getPreferenceStore().getBoolean(ModelPreferences.META_CLIENT_NAME_DISABLE)) {
        // App name
        properties.put(SQLServerUtils.isDriverJtds(getContainer().getDriver()) ? SQLServerConstants.APPNAME_CLIENT_PROPERTY : SQLServerConstants.APPLICATION_NAME_CLIENT_PROPERTY, CommonUtils.truncateString(DBUtils.getClientApplicationName(getContainer(), context, purpose), 64));
    }
    fillConnectionProperties(connectionInfo, properties);
    SQLServerAuthentication authSchema = SQLServerUtils.detectAuthSchema(connectionInfo);
    authSchema.getInitializer().initializeAuthentication(connectionInfo, properties);
    final DBWHandlerConfiguration sslConfig = getContainer().getActualConnectionConfiguration().getHandler(SQLServerConstants.HANDLER_SSL);
    if (sslConfig != null && sslConfig.isEnabled()) {
        initSSL(monitor, properties, sslConfig);
    }
    return properties;
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) Properties(java.util.Properties)

Example 50 with DBWHandlerConfiguration

use of org.jkiss.dbeaver.model.net.DBWHandlerConfiguration in project dbeaver by serge-rider.

the class MySQLDataSource method getInternalConnectionProperties.

@Override
protected Map<String, String> getInternalConnectionProperties(DBRProgressMonitor monitor, DBPDriver driver, JDBCExecutionContext context, String purpose, DBPConnectionConfiguration connectionInfo) throws DBCException {
    Map<String, String> props = new LinkedHashMap<>(MySQLDataSourceProvider.getConnectionsProps());
    final DBWHandlerConfiguration sslConfig = getContainer().getActualConnectionConfiguration().getHandler(MySQLConstants.HANDLER_SSL);
    if (sslConfig != null && sslConfig.isEnabled()) {
        try {
            initSSL(monitor, props, sslConfig);
        } catch (Exception e) {
            throw new DBCException("Error configuring SSL certificates", e);
        }
    } else {
        // Newer MySQL servers/connectors requires explicit SSL disable
        props.put("useSSL", "false");
    }
    String serverTZ = connectionInfo.getProviderProperty(MySQLConstants.PROP_SERVER_TIMEZONE);
    if (CommonUtils.isEmpty(serverTZ) && inServerTimezoneHandle) /*&& getContainer().getDriver().getId().equals(MySQLConstants.DRIVER_ID_MYSQL8)*/
    {
        serverTZ = "UTC";
    }
    if (!CommonUtils.isEmpty(serverTZ)) {
        props.put("serverTimezone", serverTZ);
    }
    if (!isMariaDB()) {
        // Hacking different MySQL drivers zeroDateTimeBehavior property (#4103)
        String zeroDateTimeBehavior = connectionInfo.getProperty(MySQLConstants.PROP_ZERO_DATETIME_BEHAVIOR);
        if (zeroDateTimeBehavior == null) {
            try {
                Driver driverInstance = (Driver) driver.getDriverInstance(monitor);
                if (driverInstance != null) {
                    if (driverInstance.getMajorVersion() >= 8) {
                        props.put(MySQLConstants.PROP_ZERO_DATETIME_BEHAVIOR, "CONVERT_TO_NULL");
                    } else {
                        props.put(MySQLConstants.PROP_ZERO_DATETIME_BEHAVIOR, "convertToNull");
                    }
                }
            } catch (Exception e) {
                log.debug("Error setting MySQL " + MySQLConstants.PROP_ZERO_DATETIME_BEHAVIOR + " property default");
            }
        }
    }
    return props;
}
Also used : DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) Driver(java.sql.Driver) DBCException(org.jkiss.dbeaver.model.exec.DBCException) DBCException(org.jkiss.dbeaver.model.exec.DBCException) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException) DBException(org.jkiss.dbeaver.DBException)

Aggregations

DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)64 DBException (org.jkiss.dbeaver.DBException)20 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)12 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)12 NetworkHandlerDescriptor (org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor)12 SQLException (java.sql.SQLException)8 DBWNetworkProfile (org.jkiss.dbeaver.model.net.DBWNetworkProfile)8 DBRShellCommand (org.jkiss.dbeaver.model.runtime.DBRShellCommand)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 GridData (org.eclipse.swt.layout.GridData)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Nullable (org.jkiss.code.Nullable)6 DBPDataSourceOrigin (org.jkiss.dbeaver.model.DBPDataSourceOrigin)6 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)6 SimplePreferenceStore (org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore)6 UIPropertyConfiguratorDescriptor (org.jkiss.dbeaver.registry.configurator.UIPropertyConfiguratorDescriptor)6 TypeToken (com.google.gson.reflect.TypeToken)4 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4