diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceDescriptor.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceDescriptor.java index 097dbd8b66a4531a00d69f4e33445282dc08b52d..71971d84daaed77a8de4bb29a4a242dca893d209 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceDescriptor.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceDescriptor.java @@ -112,6 +112,8 @@ public class DataSourceDescriptor @NotNull private final DBPDataSourceRegistry registry; @NotNull + private final DataSourceOrigin origin; + @NotNull private DriverDescriptor driver; @NotNull private DBPConnectionConfiguration connectionInfo; @@ -138,8 +140,6 @@ public class DataSourceDescriptor private final List users = new ArrayList<>(); - private boolean provided; - private volatile boolean connectFailed = false; private volatile Date connectTime = null; private volatile boolean disposed = false; @@ -155,8 +155,19 @@ public class DataSourceDescriptor @NotNull String id, @NotNull DriverDescriptor driver, @NotNull DBPConnectionConfiguration connectionInfo) + { + this(registry, ((DataSourceRegistry)registry).getDefaultOrigin(), id, driver, connectionInfo); + } + + DataSourceDescriptor( + @NotNull DBPDataSourceRegistry registry, + @NotNull DataSourceOrigin origin, + @NotNull String id, + @NotNull DriverDescriptor driver, + @NotNull DBPConnectionConfiguration connectionInfo) { this.registry = registry; + this.origin = origin; this.id = id; this.driver = driver; this.connectionInfo = connectionInfo; @@ -168,6 +179,7 @@ public class DataSourceDescriptor public DataSourceDescriptor(@NotNull DataSourceDescriptor source) { this.registry = source.registry; + this.origin = source.origin; this.id = source.id; this.name = source.name; this.description = source.description; @@ -512,11 +524,7 @@ public class DataSourceDescriptor @Override public boolean isProvided() { - return provided; - } - - public void setProvided(boolean provided) { - this.provided = provided; + return !origin.isDefault(); } @Override diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceOrigin.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceOrigin.java new file mode 100644 index 0000000000000000000000000000000000000000..6ce8885b83393b10e9776ac83967edef13224b0d --- /dev/null +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceOrigin.java @@ -0,0 +1,51 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2016 Serge Rieder (serge@jkiss.org) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License (version 2) + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.jkiss.dbeaver.registry; + +import java.io.File; + +/** + * DataSourceOrigin + */ +class DataSourceOrigin +{ + private final File sourceFile; + private final boolean isDefault; + + public DataSourceOrigin(File sourceFile, boolean isDefault) { + this.sourceFile = sourceFile; + this.isDefault = isDefault; + } + + public String getName() { + return sourceFile.getName(); + } + + public boolean isDefault() { + return isDefault; + } + + public File getSourceFile() { + return sourceFile; + } + + @Override + public String toString() { + return sourceFile.getAbsolutePath(); + } +} diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java index f30d32077feee4e94d4e618eb2170d5b94fd0d62..b44a3392a2ad21b287ff4a4ec1e0e6b67e33f4a6 100644 --- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java +++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java @@ -85,6 +85,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry private final DBPPlatform platform; private final IProject project; + private final Map origins = new HashMap<>(); private final List dataSources = new ArrayList<>(); private final List dataSourceListeners = new ArrayList<>(); private final List dataSourceFolders = new ArrayList<>(); @@ -144,6 +145,20 @@ public class DataSourceRegistry implements DBPDataSourceRegistry } } + DataSourceOrigin getDefaultOrigin() { + synchronized (origins) { + for (DataSourceOrigin origin : origins.values()) { + if (origin.isDefault()) { + return origin; + } + } + IFile defFile = project.getFile(CONFIG_FILE_NAME); + DataSourceOrigin origin = new DataSourceOrigin(defFile.getLocation().toFile(), true); + origins.put(origin.getSourceFile(), origin); + return origin; + } + } + @NotNull public DBPPlatform getPlatform() { return platform; @@ -462,12 +477,20 @@ public class DataSourceRegistry implements DBPDataSourceRegistry private void loadDataSources(File fromFile, boolean refresh, ParseResults parseResults) { + boolean extraConfig = !fromFile.getName().equalsIgnoreCase(CONFIG_FILE_NAME); + DataSourceOrigin origin; + synchronized (origins) { + origin = origins.get(fromFile); + if (origin == null) { + origin = new DataSourceOrigin(fromFile, !extraConfig); + origins.put(fromFile, origin); + } + } if (!fromFile.exists()) { return; } - boolean extraConfig = !fromFile.getName().equalsIgnoreCase(CONFIG_FILE_NAME); try (InputStream is = new FileInputStream(fromFile)) { - loadDataSources(is, extraConfig, refresh, parseResults); + loadDataSources(is, origin, refresh, parseResults); } catch (DBException ex) { log.warn("Error loading datasource config from " + fromFile.getAbsolutePath(), ex); } catch (IOException ex) { @@ -475,12 +498,12 @@ public class DataSourceRegistry implements DBPDataSourceRegistry } } - private void loadDataSources(InputStream is, boolean extraConfig, boolean refresh, ParseResults parseResults) + private void loadDataSources(InputStream is, DataSourceOrigin origin, boolean refresh, ParseResults parseResults) throws DBException, IOException { SAXReader parser = new SAXReader(is); try { - final DataSourcesParser dsp = new DataSourcesParser(extraConfig, refresh, parseResults); + final DataSourcesParser dsp = new DataSourcesParser(origin, refresh, parseResults); parser.parse(dsp); } catch (XMLException ex) { @@ -878,7 +901,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry private class DataSourcesParser implements SAXListener { DataSourceDescriptor curDataSource; - boolean extraConfig; + DataSourceOrigin origin; boolean refresh; boolean isDescription = false; DBRShellCommand curCommand = null; @@ -888,9 +911,9 @@ public class DataSourceRegistry implements DBPDataSourceRegistry private ParseResults parseResults; private boolean passwordReadCanceled = false; - private DataSourcesParser(boolean extraConfig, boolean refresh, ParseResults parseResults) + private DataSourcesParser(DataSourceOrigin origin, boolean refresh, ParseResults parseResults) { - this.extraConfig = extraConfig; + this.origin = origin; this.refresh = refresh; this.parseResults = parseResults; } @@ -943,6 +966,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry if (newDataSource) { curDataSource = new DataSourceDescriptor( DataSourceRegistry.this, + origin, id, driver, new DBPConnectionConfiguration()); @@ -952,9 +976,6 @@ public class DataSourceRegistry implements DBPDataSourceRegistry curDataSource.getConnectionConfiguration().setHandlers(Collections.emptyList()); curDataSource.clearFilters(); } - if (extraConfig) { - curDataSource.setProvided(true); - } curDataSource.setName(name); try { String createDate = atts.getValue(RegistryConstants.ATTR_CREATE_DATE);