Search in sources :

Example 1 with SimplePreferenceStore

use of org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore in project dbeaver by serge-rider.

the class DataSourceRegistry method saveDataSource.

private void saveDataSource(XMLBuilder xml, DataSourceDescriptor dataSource) throws IOException {
    clearSecuredPasswords(dataSource);
    xml.startElement(RegistryConstants.TAG_DATA_SOURCE);
    xml.addAttribute(RegistryConstants.ATTR_ID, dataSource.getId());
    xml.addAttribute(RegistryConstants.ATTR_PROVIDER, dataSource.getDriver().getProviderDescriptor().getId());
    xml.addAttribute(RegistryConstants.ATTR_DRIVER, dataSource.getDriver().getId());
    xml.addAttribute(RegistryConstants.ATTR_NAME, dataSource.getName());
    xml.addAttribute(RegistryConstants.ATTR_SAVE_PASSWORD, dataSource.isSavePassword());
    if (dataSource.isShowSystemObjects()) {
        xml.addAttribute(RegistryConstants.ATTR_SHOW_SYSTEM_OBJECTS, dataSource.isShowSystemObjects());
    }
    if (dataSource.isShowUtilityObjects()) {
        xml.addAttribute(RegistryConstants.ATTR_SHOW_UTIL_OBJECTS, dataSource.isShowUtilityObjects());
    }
    xml.addAttribute(RegistryConstants.ATTR_READ_ONLY, dataSource.isConnectionReadOnly());
    if (dataSource.getFolder() != null) {
        xml.addAttribute(RegistryConstants.ATTR_FOLDER, dataSource.getFolder().getFolderPath());
    }
    final String lockPasswordHash = dataSource.getLockPasswordHash();
    if (!CommonUtils.isEmpty(lockPasswordHash)) {
        xml.addAttribute(RegistryConstants.ATTR_LOCK_PASSWORD, lockPasswordHash);
    }
    {
        // Connection info
        DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
        xml.startElement(RegistryConstants.TAG_CONNECTION);
        if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
            xml.addAttribute(RegistryConstants.ATTR_HOST, connectionInfo.getHostName());
        }
        if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
            xml.addAttribute(RegistryConstants.ATTR_PORT, connectionInfo.getHostPort());
        }
        xml.addAttribute(RegistryConstants.ATTR_SERVER, CommonUtils.notEmpty(connectionInfo.getServerName()));
        xml.addAttribute(RegistryConstants.ATTR_DATABASE, CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
        xml.addAttribute(RegistryConstants.ATTR_URL, CommonUtils.notEmpty(connectionInfo.getUrl()));
        saveSecuredCredentials(xml, dataSource, null, connectionInfo.getUserName(), dataSource.isSavePassword() ? connectionInfo.getUserPassword() : null);
        if (!CommonUtils.isEmpty(connectionInfo.getClientHomeId())) {
            xml.addAttribute(RegistryConstants.ATTR_HOME, connectionInfo.getClientHomeId());
        }
        if (connectionInfo.getConnectionType() != null) {
            xml.addAttribute(RegistryConstants.ATTR_TYPE, connectionInfo.getConnectionType().getId());
        }
        if (connectionInfo.getConnectionColor() != null) {
            xml.addAttribute(RegistryConstants.ATTR_COLOR, connectionInfo.getConnectionColor());
        }
        // Save other
        if (connectionInfo.getKeepAliveInterval() > 0) {
            xml.addAttribute(RegistryConstants.ATTR_KEEP_ALIVE, connectionInfo.getKeepAliveInterval());
        }
        for (Map.Entry<String, String> entry : connectionInfo.getProperties().entrySet()) {
            xml.startElement(RegistryConstants.TAG_PROPERTY);
            xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(entry.getKey()));
            xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(entry.getValue()));
            xml.endElement();
        }
        for (Map.Entry<String, String> entry : connectionInfo.getProviderProperties().entrySet()) {
            xml.startElement(RegistryConstants.TAG_PROVIDER_PROPERTY);
            xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(entry.getKey()));
            xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(entry.getValue()));
            xml.endElement();
        }
        // Save events
        for (DBPConnectionEventType eventType : connectionInfo.getDeclaredEvents()) {
            DBRShellCommand command = connectionInfo.getEvent(eventType);
            xml.startElement(RegistryConstants.TAG_EVENT);
            xml.addAttribute(RegistryConstants.ATTR_TYPE, eventType.name());
            xml.addAttribute(RegistryConstants.ATTR_ENABLED, command.isEnabled());
            xml.addAttribute(RegistryConstants.ATTR_SHOW_PANEL, command.isShowProcessPanel());
            xml.addAttribute(RegistryConstants.ATTR_WAIT_PROCESS, command.isWaitProcessFinish());
            xml.addAttribute(RegistryConstants.ATTR_TERMINATE_AT_DISCONNECT, command.isTerminateAtDisconnect());
            xml.addText(command.getCommand());
            xml.endElement();
        }
        // Save network handlers' configurations
        for (DBWHandlerConfiguration configuration : connectionInfo.getDeclaredHandlers()) {
            xml.startElement(RegistryConstants.TAG_NETWORK_HANDLER);
            xml.addAttribute(RegistryConstants.ATTR_TYPE, configuration.getType().name());
            xml.addAttribute(RegistryConstants.ATTR_ID, CommonUtils.notEmpty(configuration.getId()));
            xml.addAttribute(RegistryConstants.ATTR_ENABLED, configuration.isEnabled());
            xml.addAttribute(RegistryConstants.ATTR_SAVE_PASSWORD, configuration.isSavePassword());
            if (!CommonUtils.isEmpty(configuration.getUserName())) {
                saveSecuredCredentials(xml, dataSource, "network/" + configuration.getId(), configuration.getUserName(), configuration.isSavePassword() ? configuration.getPassword() : null);
            }
            for (Map.Entry<String, String> entry : configuration.getProperties().entrySet()) {
                if (CommonUtils.isEmpty(entry.getValue())) {
                    continue;
                }
                xml.startElement(RegistryConstants.TAG_PROPERTY);
                xml.addAttribute(RegistryConstants.ATTR_NAME, entry.getKey());
                xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.notEmpty(entry.getValue()));
                xml.endElement();
            }
            xml.endElement();
        }
        // Save bootstrap info
        {
            DBPConnectionBootstrap bootstrap = connectionInfo.getBootstrap();
            if (bootstrap.hasData()) {
                xml.startElement(RegistryConstants.TAG_BOOTSTRAP);
                if (bootstrap.getDefaultAutoCommit() != null) {
                    xml.addAttribute(RegistryConstants.ATTR_AUTOCOMMIT, bootstrap.getDefaultAutoCommit());
                }
                if (bootstrap.getDefaultTransactionIsolation() != null) {
                    xml.addAttribute(RegistryConstants.ATTR_TXN_ISOLATION, bootstrap.getDefaultTransactionIsolation());
                }
                if (!CommonUtils.isEmpty(bootstrap.getDefaultObjectName())) {
                    xml.addAttribute(RegistryConstants.ATTR_DEFAULT_OBJECT, bootstrap.getDefaultObjectName());
                }
                if (bootstrap.isIgnoreErrors()) {
                    xml.addAttribute(RegistryConstants.ATTR_IGNORE_ERRORS, true);
                }
                for (String query : bootstrap.getInitQueries()) {
                    xml.startElement(RegistryConstants.TAG_QUERY);
                    xml.addText(query);
                    xml.endElement();
                }
                xml.endElement();
            }
        }
        xml.endElement();
    }
    {
        // Filters
        Collection<DataSourceDescriptor.FilterMapping> filterMappings = dataSource.getObjectFilters();
        if (!CommonUtils.isEmpty(filterMappings)) {
            xml.startElement(RegistryConstants.TAG_FILTERS);
            for (DataSourceDescriptor.FilterMapping filter : filterMappings) {
                if (filter.defaultFilter != null && !filter.defaultFilter.isEmpty()) {
                    saveObjectFiler(xml, filter.typeName, null, filter.defaultFilter);
                }
                for (Map.Entry<String, DBSObjectFilter> cf : filter.customFilters.entrySet()) {
                    if (!cf.getValue().isEmpty()) {
                        saveObjectFiler(xml, filter.typeName, cf.getKey(), cf.getValue());
                    }
                }
            }
            xml.endElement();
        }
    }
    // Virtual model
    if (dataSource.getVirtualModel().hasValuableData()) {
        xml.startElement(RegistryConstants.TAG_VIRTUAL_META_DATA);
        dataSource.getVirtualModel().serialize(xml);
        xml.endElement();
    }
    // Preferences
    {
        // Save only properties who are differs from default values
        SimplePreferenceStore prefStore = dataSource.getPreferenceStore();
        for (String propName : prefStore.preferenceNames()) {
            String propValue = prefStore.getString(propName);
            String defValue = prefStore.getDefaultString(propName);
            if (propValue == null || CommonUtils.equalObjects(propValue, defValue)) {
                continue;
            }
            xml.startElement(RegistryConstants.TAG_CUSTOM_PROPERTY);
            xml.addAttribute(RegistryConstants.ATTR_NAME, propName);
            xml.addAttribute(RegistryConstants.ATTR_VALUE, propValue);
            xml.endElement();
        }
    }
    if (!CommonUtils.isEmpty(dataSource.getDescription())) {
        xml.startElement(RegistryConstants.TAG_DESCRIPTION);
        xml.addText(dataSource.getDescription());
        xml.endElement();
    }
    xml.endElement();
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPConnectionEventType(org.jkiss.dbeaver.model.connection.DBPConnectionEventType) DBPConnectionBootstrap(org.jkiss.dbeaver.model.connection.DBPConnectionBootstrap) SimplePreferenceStore(org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand)

Example 2 with SimplePreferenceStore

use of org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore in project dbeaver by dbeaver.

the class DataSourceRegistry method saveDataSource.

private void saveDataSource(XMLBuilder xml, DataSourceDescriptor dataSource) throws IOException {
    xml.startElement(RegistryConstants.TAG_DATA_SOURCE);
    xml.addAttribute(RegistryConstants.ATTR_ID, dataSource.getId());
    xml.addAttribute(RegistryConstants.ATTR_PROVIDER, dataSource.getDriver().getProviderDescriptor().getId());
    xml.addAttribute(RegistryConstants.ATTR_DRIVER, dataSource.getDriver().getId());
    xml.addAttribute(RegistryConstants.ATTR_NAME, dataSource.getName());
    xml.addAttribute(RegistryConstants.ATTR_SAVE_PASSWORD, dataSource.isSavePassword());
    if (dataSource.isShowSystemObjects()) {
        xml.addAttribute(RegistryConstants.ATTR_SHOW_SYSTEM_OBJECTS, dataSource.isShowSystemObjects());
    }
    if (dataSource.isShowUtilityObjects()) {
        xml.addAttribute(RegistryConstants.ATTR_SHOW_UTIL_OBJECTS, dataSource.isShowUtilityObjects());
    }
    xml.addAttribute(RegistryConstants.ATTR_READ_ONLY, dataSource.isConnectionReadOnly());
    if (dataSource.getFolder() != null) {
        xml.addAttribute(RegistryConstants.ATTR_FOLDER, dataSource.getFolder().getFolderPath());
    }
    final String lockPasswordHash = dataSource.getLockPasswordHash();
    if (!CommonUtils.isEmpty(lockPasswordHash)) {
        xml.addAttribute(RegistryConstants.ATTR_LOCK_PASSWORD, lockPasswordHash);
    }
    {
        // Connection info
        DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
        xml.startElement(RegistryConstants.TAG_CONNECTION);
        if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
            xml.addAttribute(RegistryConstants.ATTR_HOST, connectionInfo.getHostName());
        }
        if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
            xml.addAttribute(RegistryConstants.ATTR_PORT, connectionInfo.getHostPort());
        }
        xml.addAttribute(RegistryConstants.ATTR_SERVER, CommonUtils.notEmpty(connectionInfo.getServerName()));
        xml.addAttribute(RegistryConstants.ATTR_DATABASE, CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
        xml.addAttribute(RegistryConstants.ATTR_URL, CommonUtils.notEmpty(connectionInfo.getUrl()));
        saveSecuredCredentials(xml, dataSource, null, connectionInfo.getUserName(), dataSource.isSavePassword() ? connectionInfo.getUserPassword() : null);
        if (!CommonUtils.isEmpty(connectionInfo.getClientHomeId())) {
            xml.addAttribute(RegistryConstants.ATTR_HOME, connectionInfo.getClientHomeId());
        }
        if (connectionInfo.getConnectionType() != null) {
            xml.addAttribute(RegistryConstants.ATTR_TYPE, connectionInfo.getConnectionType().getId());
        }
        if (connectionInfo.getConnectionColor() != null) {
            xml.addAttribute(RegistryConstants.ATTR_COLOR, connectionInfo.getConnectionColor());
        }
        // Save other
        if (connectionInfo.getKeepAliveInterval() > 0) {
            xml.addAttribute(RegistryConstants.ATTR_KEEP_ALIVE, connectionInfo.getKeepAliveInterval());
        }
        for (Map.Entry<String, String> entry : connectionInfo.getProperties().entrySet()) {
            xml.startElement(RegistryConstants.TAG_PROPERTY);
            xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(entry.getKey()));
            xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(entry.getValue()));
            xml.endElement();
        }
        for (Map.Entry<String, String> entry : connectionInfo.getProviderProperties().entrySet()) {
            xml.startElement(RegistryConstants.TAG_PROVIDER_PROPERTY);
            xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(entry.getKey()));
            xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(entry.getValue()));
            xml.endElement();
        }
        // Save events
        for (DBPConnectionEventType eventType : connectionInfo.getDeclaredEvents()) {
            DBRShellCommand command = connectionInfo.getEvent(eventType);
            xml.startElement(RegistryConstants.TAG_EVENT);
            xml.addAttribute(RegistryConstants.ATTR_TYPE, eventType.name());
            xml.addAttribute(RegistryConstants.ATTR_ENABLED, command.isEnabled());
            xml.addAttribute(RegistryConstants.ATTR_SHOW_PANEL, command.isShowProcessPanel());
            xml.addAttribute(RegistryConstants.ATTR_WAIT_PROCESS, command.isWaitProcessFinish());
            if (command.isWaitProcessFinish()) {
                xml.addAttribute(RegistryConstants.ATTR_WAIT_PROCESS_TIMEOUT, command.getWaitProcessTimeoutMs());
            }
            xml.addAttribute(RegistryConstants.ATTR_TERMINATE_AT_DISCONNECT, command.isTerminateAtDisconnect());
            xml.addAttribute(RegistryConstants.ATTR_PAUSE_AFTER_EXECUTE, command.getPauseAfterExecute());
            if (!CommonUtils.isEmpty(command.getWorkingDirectory())) {
                xml.addAttribute(RegistryConstants.ATTR_WORKING_DIRECTORY, command.getWorkingDirectory());
            }
            xml.addText(command.getCommand());
            xml.endElement();
        }
        // Save network handlers' configurations
        for (DBWHandlerConfiguration configuration : connectionInfo.getDeclaredHandlers()) {
            xml.startElement(RegistryConstants.TAG_NETWORK_HANDLER);
            xml.addAttribute(RegistryConstants.ATTR_TYPE, configuration.getType().name());
            xml.addAttribute(RegistryConstants.ATTR_ID, CommonUtils.notEmpty(configuration.getId()));
            xml.addAttribute(RegistryConstants.ATTR_ENABLED, configuration.isEnabled());
            xml.addAttribute(RegistryConstants.ATTR_SAVE_PASSWORD, configuration.isSavePassword());
            if (!CommonUtils.isEmpty(configuration.getUserName())) {
                saveSecuredCredentials(xml, dataSource, "network/" + configuration.getId(), configuration.getUserName(), configuration.isSavePassword() ? configuration.getPassword() : null);
            }
            for (Map.Entry<String, String> entry : configuration.getProperties().entrySet()) {
                if (CommonUtils.isEmpty(entry.getValue())) {
                    continue;
                }
                xml.startElement(RegistryConstants.TAG_PROPERTY);
                xml.addAttribute(RegistryConstants.ATTR_NAME, entry.getKey());
                xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.notEmpty(entry.getValue()));
                xml.endElement();
            }
            xml.endElement();
        }
        // Save bootstrap info
        {
            DBPConnectionBootstrap bootstrap = connectionInfo.getBootstrap();
            if (bootstrap.hasData()) {
                xml.startElement(RegistryConstants.TAG_BOOTSTRAP);
                if (bootstrap.getDefaultAutoCommit() != null) {
                    xml.addAttribute(RegistryConstants.ATTR_AUTOCOMMIT, bootstrap.getDefaultAutoCommit());
                }
                if (bootstrap.getDefaultTransactionIsolation() != null) {
                    xml.addAttribute(RegistryConstants.ATTR_TXN_ISOLATION, bootstrap.getDefaultTransactionIsolation());
                }
                if (!CommonUtils.isEmpty(bootstrap.getDefaultObjectName())) {
                    xml.addAttribute(RegistryConstants.ATTR_DEFAULT_OBJECT, bootstrap.getDefaultObjectName());
                }
                if (bootstrap.isIgnoreErrors()) {
                    xml.addAttribute(RegistryConstants.ATTR_IGNORE_ERRORS, true);
                }
                for (String query : bootstrap.getInitQueries()) {
                    xml.startElement(RegistryConstants.TAG_QUERY);
                    xml.addText(query);
                    xml.endElement();
                }
                xml.endElement();
            }
        }
        xml.endElement();
    }
    {
        // Filters
        Collection<FilterMapping> filterMappings = dataSource.getObjectFilters();
        if (!CommonUtils.isEmpty(filterMappings)) {
            xml.startElement(RegistryConstants.TAG_FILTERS);
            for (FilterMapping filter : filterMappings) {
                if (filter.defaultFilter != null && !filter.defaultFilter.isEmpty()) {
                    saveObjectFiler(xml, filter.typeName, null, filter.defaultFilter);
                }
                for (Map.Entry<String, DBSObjectFilter> cf : filter.customFilters.entrySet()) {
                    if (!cf.getValue().isEmpty()) {
                        saveObjectFiler(xml, filter.typeName, cf.getKey(), cf.getValue());
                    }
                }
            }
            xml.endElement();
        }
    }
    // Virtual model
    if (dataSource.getVirtualModel().hasValuableData()) {
        xml.startElement(RegistryConstants.TAG_VIRTUAL_META_DATA);
        dataSource.getVirtualModel().serialize(xml);
        xml.endElement();
    }
    // Preferences
    {
        // Save only properties who are differs from default values
        SimplePreferenceStore prefStore = dataSource.getPreferenceStore();
        for (String propName : prefStore.preferenceNames()) {
            String propValue = prefStore.getString(propName);
            String defValue = prefStore.getDefaultString(propName);
            if (propValue == null || CommonUtils.equalObjects(propValue, defValue)) {
                continue;
            }
            xml.startElement(RegistryConstants.TAG_CUSTOM_PROPERTY);
            xml.addAttribute(RegistryConstants.ATTR_NAME, propName);
            xml.addAttribute(RegistryConstants.ATTR_VALUE, propValue);
            xml.endElement();
        }
    }
    if (!CommonUtils.isEmpty(dataSource.getDescription())) {
        xml.startElement(RegistryConstants.TAG_DESCRIPTION);
        xml.addText(dataSource.getDescription());
        xml.endElement();
    }
    xml.endElement();
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPConnectionEventType(org.jkiss.dbeaver.model.connection.DBPConnectionEventType) DBPConnectionBootstrap(org.jkiss.dbeaver.model.connection.DBPConnectionBootstrap) SimplePreferenceStore(org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand)

Example 3 with SimplePreferenceStore

use of org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore in project dbeaver by serge-rider.

the class DataFormatterRegistry method saveProfiles.

private void saveProfiles() {
    if (customProfiles == null) {
        return;
    }
    File storeFile = DBWorkbench.getPlatform().getConfigurationFile(CONFIG_FILE_NAME);
    try (OutputStream os = new FileOutputStream(storeFile)) {
        XMLBuilder xml = new XMLBuilder(os, GeneralUtils.UTF8_ENCODING);
        xml.setButify(true);
        xml.startElement("profiles");
        for (DBDDataFormatterProfile profile : customProfiles) {
            xml.startElement("profile");
            xml.addAttribute("name", profile.getProfileName());
            SimplePreferenceStore store = (SimplePreferenceStore) profile.getPreferenceStore();
            Map<String, String> props = store.getProperties();
            if (props != null) {
                for (Map.Entry<String, String> entry : props.entrySet()) {
                    xml.startElement("property");
                    xml.addAttribute("name", entry.getKey());
                    xml.addAttribute("value", entry.getValue());
                    xml.endElement();
                }
            }
            xml.endElement();
        }
        xml.endElement();
        xml.flush();
    } catch (IOException ex) {
        log.warn("IO error", ex);
    }
}
Also used : SimplePreferenceStore(org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore) DBDDataFormatterProfile(org.jkiss.dbeaver.model.data.DBDDataFormatterProfile) HashMap(java.util.HashMap) Map(java.util.Map) XMLBuilder(org.jkiss.utils.xml.XMLBuilder)

Example 4 with SimplePreferenceStore

use of org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore in project dbeaver by dbeaver.

the class DataFormatterProfile method reset.

@Override
public void reset() {
    if (store instanceof SimplePreferenceStore) {
        // Set all formatter properties to default
        store.setToDefault(PROP_LANGUAGE);
        store.setToDefault(PROP_COUNTRY);
        store.setToDefault(PROP_VARIANT);
        for (DataFormatterDescriptor formatter : DataFormatterRegistry.getInstance().getDataFormatters()) {
            for (DBPPropertyDescriptor prop : formatter.getProperties()) {
                store.setToDefault(DATAFORMAT_TYPE_PREFIX + formatter.getId() + "." + prop.getId());
            }
        }
    }
    loadProfile();
}
Also used : SimplePreferenceStore(org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Example 5 with SimplePreferenceStore

use of org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore in project dbeaver by dbeaver.

the class DataSourceSerializerModern method saveDataSource.

private void saveDataSource(@NotNull JsonWriter json, @NotNull DataSourceDescriptor dataSource) throws IOException {
    json.name(dataSource.getId());
    json.beginObject();
    JSONUtils.field(json, RegistryConstants.ATTR_PROVIDER, dataSource.getDriver().getProviderDescriptor().getId());
    JSONUtils.field(json, RegistryConstants.ATTR_DRIVER, dataSource.getDriver().getId());
    DBPDataSourceOrigin origin = dataSource.getOrigin();
    if (origin != DataSourceOriginLocal.INSTANCE) {
        Map<String, Object> originProps = new LinkedHashMap<>();
        originProps.put(ATTR_ORIGIN_TYPE, origin.getType());
        originProps.putAll(origin.getConfiguration());
        JSONUtils.serializeProperties(json, TAG_ORIGIN, originProps);
    }
    JSONUtils.field(json, RegistryConstants.ATTR_NAME, dataSource.getName());
    JSONUtils.fieldNE(json, RegistryConstants.TAG_DESCRIPTION, dataSource.getDescription());
    JSONUtils.field(json, RegistryConstants.ATTR_SAVE_PASSWORD, dataSource.isSavePassword());
    if (dataSource.isTemplate()) {
        JSONUtils.field(json, RegistryConstants.ATTR_TEMPLATE, dataSource.isTemplate());
    }
    DataSourceNavigatorSettings navSettings = dataSource.getNavigatorSettings();
    if (navSettings.isShowSystemObjects())
        JSONUtils.field(json, ATTR_NAVIGATOR_SHOW_SYSTEM_OBJECTS, true);
    if (navSettings.isShowUtilityObjects())
        JSONUtils.field(json, ATTR_NAVIGATOR_SHOW_UTIL_OBJECTS, true);
    if (navSettings.isShowOnlyEntities())
        JSONUtils.field(json, ATTR_NAVIGATOR_SHOW_ONLY_ENTITIES, true);
    if (navSettings.isHideFolders())
        JSONUtils.field(json, ATTR_NAVIGATOR_HIDE_FOLDERS, true);
    if (navSettings.isHideSchemas())
        JSONUtils.field(json, ATTR_NAVIGATOR_HIDE_SCHEMAS, true);
    if (navSettings.isHideVirtualModel())
        JSONUtils.field(json, ATTR_NAVIGATOR_HIDE_VIRTUAL, true);
    if (navSettings.isMergeEntities())
        JSONUtils.field(json, ATTR_NAVIGATOR_MERGE_ENTITIES, true);
    JSONUtils.field(json, RegistryConstants.ATTR_READ_ONLY, dataSource.isConnectionReadOnly());
    if (dataSource.getFolder() != null) {
        JSONUtils.field(json, RegistryConstants.ATTR_FOLDER, dataSource.getFolder().getFolderPath());
    }
    final String lockPasswordHash = dataSource.getLockPasswordHash();
    if (!CommonUtils.isEmpty(lockPasswordHash)) {
        JSONUtils.field(json, RegistryConstants.ATTR_LOCK_PASSWORD, lockPasswordHash);
    }
    if (dataSource.hasSharedVirtualModel()) {
        JSONUtils.field(json, "virtual-model-id", dataSource.getVirtualModel().getId());
    }
    {
        // Connection info
        DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
        json.name("configuration");
        json.beginObject();
        JSONUtils.fieldNE(json, RegistryConstants.ATTR_HOST, connectionInfo.getHostName());
        JSONUtils.fieldNE(json, RegistryConstants.ATTR_PORT, connectionInfo.getHostPort());
        JSONUtils.fieldNE(json, RegistryConstants.ATTR_SERVER, connectionInfo.getServerName());
        JSONUtils.fieldNE(json, RegistryConstants.ATTR_DATABASE, connectionInfo.getDatabaseName());
        JSONUtils.fieldNE(json, RegistryConstants.ATTR_URL, connectionInfo.getUrl());
        saveSecuredCredentials(dataSource, null, null, new SecureCredentials(dataSource));
        JSONUtils.fieldNE(json, RegistryConstants.ATTR_HOME, connectionInfo.getClientHomeId());
        if (connectionInfo.getConnectionType() != null) {
            JSONUtils.field(json, RegistryConstants.ATTR_TYPE, connectionInfo.getConnectionType().getId());
        }
        JSONUtils.fieldNE(json, RegistryConstants.ATTR_COLOR, connectionInfo.getConnectionColor());
        // Save other
        if (connectionInfo.getKeepAliveInterval() > 0) {
            JSONUtils.field(json, RegistryConstants.ATTR_KEEP_ALIVE, connectionInfo.getKeepAliveInterval());
        }
        JSONUtils.fieldNE(json, "config-profile", connectionInfo.getConfigProfileName());
        JSONUtils.serializeProperties(json, RegistryConstants.TAG_PROPERTIES, connectionInfo.getProperties());
        JSONUtils.serializeProperties(json, RegistryConstants.TAG_PROVIDER_PROPERTIES, connectionInfo.getProviderProperties());
        JSONUtils.fieldNE(json, RegistryConstants.ATTR_AUTH_MODEL, connectionInfo.getAuthModelId());
        JSONUtils.serializeProperties(json, "auth-properties", connectionInfo.getAuthProperties());
        // Save events
        if (!ArrayUtils.isEmpty(connectionInfo.getDeclaredEvents())) {
            json.name(RegistryConstants.TAG_EVENTS);
            json.beginObject();
            for (DBPConnectionEventType eventType : connectionInfo.getDeclaredEvents()) {
                DBRShellCommand command = connectionInfo.getEvent(eventType);
                if (!command.isEnabled()) {
                    continue;
                }
                json.name(eventType.name());
                json.beginObject();
                JSONUtils.field(json, RegistryConstants.ATTR_ENABLED, command.isEnabled());
                JSONUtils.field(json, RegistryConstants.ATTR_SHOW_PANEL, command.isShowProcessPanel());
                JSONUtils.field(json, RegistryConstants.ATTR_WAIT_PROCESS, command.isWaitProcessFinish());
                if (command.isWaitProcessFinish()) {
                    JSONUtils.field(json, RegistryConstants.ATTR_WAIT_PROCESS_TIMEOUT, command.getWaitProcessTimeoutMs());
                }
                JSONUtils.field(json, RegistryConstants.ATTR_TERMINATE_AT_DISCONNECT, command.isTerminateAtDisconnect());
                JSONUtils.field(json, RegistryConstants.ATTR_PAUSE_AFTER_EXECUTE, command.getPauseAfterExecute());
                JSONUtils.fieldNE(json, RegistryConstants.ATTR_WORKING_DIRECTORY, command.getWorkingDirectory());
                JSONUtils.fieldNE(json, RegistryConstants.ATTR_COMMAND, command.getCommand());
                json.endObject();
            }
            json.endObject();
        }
        // Save network handlers' configurations
        if (!CommonUtils.isEmpty(connectionInfo.getHandlers())) {
            json.name(RegistryConstants.TAG_HANDLERS);
            json.beginObject();
            for (DBWHandlerConfiguration configuration : connectionInfo.getHandlers()) {
                if (configuration.isEnabled()) {
                    saveNetworkHandlerConfiguration(json, dataSource, null, configuration);
                }
            }
            json.endObject();
        }
        // Save bootstrap info
        {
            DBPConnectionBootstrap bootstrap = connectionInfo.getBootstrap();
            if (bootstrap.hasData()) {
                json.name(RegistryConstants.TAG_BOOTSTRAP);
                json.beginObject();
                if (bootstrap.getDefaultAutoCommit() != null) {
                    JSONUtils.field(json, RegistryConstants.ATTR_AUTOCOMMIT, bootstrap.getDefaultAutoCommit());
                }
                if (bootstrap.getDefaultTransactionIsolation() != null) {
                    JSONUtils.field(json, RegistryConstants.ATTR_TXN_ISOLATION, bootstrap.getDefaultTransactionIsolation());
                }
                JSONUtils.fieldNE(json, RegistryConstants.ATTR_DEFAULT_CATALOG, bootstrap.getDefaultCatalogName());
                JSONUtils.fieldNE(json, RegistryConstants.ATTR_DEFAULT_SCHEMA, bootstrap.getDefaultSchemaName());
                if (bootstrap.isIgnoreErrors()) {
                    JSONUtils.field(json, RegistryConstants.ATTR_IGNORE_ERRORS, true);
                }
                JSONUtils.serializeStringList(json, RegistryConstants.TAG_QUERY, bootstrap.getInitQueries());
                json.endObject();
            }
        }
        json.endObject();
    }
    // Permissions
    serializeModifyPermissions(json, dataSource);
    {
        // Filters
        Collection<FilterMapping> filterMappings = dataSource.getObjectFilters();
        if (!CommonUtils.isEmpty(filterMappings)) {
            json.name(RegistryConstants.TAG_FILTERS);
            json.beginArray();
            for (FilterMapping filter : filterMappings) {
                if (filter.defaultFilter != null && !filter.defaultFilter.isEmpty()) {
                    saveObjectFiler(json, filter.typeName, null, filter.defaultFilter);
                }
                for (Map.Entry<String, DBSObjectFilter> cf : filter.customFilters.entrySet()) {
                    if (!cf.getValue().isEmpty()) {
                        saveObjectFiler(json, filter.typeName, cf.getKey(), cf.getValue());
                    }
                }
            }
            json.endArray();
        }
    }
    // Preferences
    {
        // Save only properties who are differs from default values
        SimplePreferenceStore prefStore = dataSource.getPreferenceStore();
        Map<String, String> props = new TreeMap<>();
        for (String propName : prefStore.preferenceNames()) {
            String propValue = prefStore.getString(propName);
            String defValue = prefStore.getDefaultString(propName);
            if (propValue != null && !CommonUtils.equalObjects(propValue, defValue)) {
                props.put(propName, propValue);
            }
        }
        if (!props.isEmpty()) {
            JSONUtils.serializeProperties(json, RegistryConstants.TAG_CUSTOM_PROPERTIES, props);
        }
    }
    json.endObject();
}
Also used : SimplePreferenceStore(org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore) DBPDataSourceOrigin(org.jkiss.dbeaver.model.DBPDataSourceOrigin) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)

Aggregations

SimplePreferenceStore (org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore)8 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)4 DBRShellCommand (org.jkiss.dbeaver.model.runtime.DBRShellCommand)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DBPDataSourceOrigin (org.jkiss.dbeaver.model.DBPDataSourceOrigin)2 DBPConnectionBootstrap (org.jkiss.dbeaver.model.connection.DBPConnectionBootstrap)2 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2 DBPConnectionEventType (org.jkiss.dbeaver.model.connection.DBPConnectionEventType)2 DBDDataFormatterProfile (org.jkiss.dbeaver.model.data.DBDDataFormatterProfile)2 DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)2 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)2