提交 81baaa26 编写于 作者: S serge-rider

Datasource origins

上级 cb79fc9f
......@@ -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<DBPDataSourceUser> 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
......
/*
* 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();
}
}
......@@ -85,6 +85,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
private final DBPPlatform platform;
private final IProject project;
private final Map<File, DataSourceOrigin> origins = new HashMap<>();
private final List<DataSourceDescriptor> dataSources = new ArrayList<>();
private final List<DBPEventListener> dataSourceListeners = new ArrayList<>();
private final List<DataSourceFolder> 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.<DBWHandlerConfiguration>emptyList());
curDataSource.clearFilters();
}
if (extraConfig) {
curDataSource.setProvided(true);
}
curDataSource.setName(name);
try {
String createDate = atts.getValue(RegistryConstants.ATTR_CREATE_DATE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册