/* * DBeaver - Universal Database Manager * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jkiss.dbeaver.registry; import org.jkiss.dbeaver.core.DBeaverCore; import org.jkiss.dbeaver.model.DBConstants; import org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore; import org.jkiss.utils.CommonUtils; import java.io.IOException; import java.util.Map; /** * DataSourcePreferenceStore */ public class DataSourcePreferenceStore extends SimplePreferenceStore { private final DataSourceDescriptor dataSourceDescriptor; DataSourcePreferenceStore(DataSourceDescriptor dataSourceDescriptor) { super(DBeaverCore.getGlobalPreferenceStore()); this.dataSourceDescriptor = dataSourceDescriptor; // Init default properties from driver overrides Map<Object,Object> defaultConnectionProperties = dataSourceDescriptor.getDriver().getDefaultConnectionProperties(); for (Map.Entry<Object, Object> prop : defaultConnectionProperties.entrySet()) { String propName = CommonUtils.toString(prop.getKey()); if (propName.startsWith(DBConstants.DEFAULT_DRIVER_PROP_PREFIX)) { getDefaultProperties().put( propName.substring(DBConstants.DEFAULT_DRIVER_PROP_PREFIX.length()), CommonUtils.toString(prop.getValue())); } } } public DataSourceDescriptor getDataSourceDescriptor() { return dataSourceDescriptor; } @Override public void save() throws IOException { dataSourceDescriptor.getRegistry().flushConfig(); } }