diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebDataSourceRegistryProxy.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebDataSourceRegistryProxy.java index 08f20a45ec..4593e06f1c 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebDataSourceRegistryProxy.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebDataSourceRegistryProxy.java @@ -45,9 +45,9 @@ public class WebDataSourceRegistryProxy implements DBPDataSourceRegistry, DataSourcePersistentRegistry, DBPDataSourceRegistryCache { private final DataSourceFilter dataSourceFilter; - private final DataSourceRegistry dataSourceRegistry; + private final DataSourceRegistry dataSourceRegistry; - public WebDataSourceRegistryProxy(DataSourceRegistry dataSourceRegistry, DataSourceFilter filter) { + public WebDataSourceRegistryProxy(DataSourceRegistry dataSourceRegistry, DataSourceFilter filter) { this.dataSourceRegistry = dataSourceRegistry; this.dataSourceFilter = filter; } @@ -113,6 +113,26 @@ public DBPDataSourceContainer createDataSource(@NotNull DBPDriver driver, @NotNu return dataSourceRegistry.createDataSource(driver, connConfig); } + @Override + public DBPDataSourceContainer createDataSource( + @NotNull String id, + @NotNull DBPDriver driver, + @NotNull DBPConnectionConfiguration connConfig + ) { + return dataSourceRegistry.createDataSource(id, driver, connConfig); + } + + @Override + public DBPDataSourceContainer createDataSource( + @NotNull DBPDataSourceConfigurationStorage dataSourceStorage, + @NotNull DBPDataSourceOrigin origin, + @NotNull String id, + @NotNull DBPDriver driver, + @NotNull DBPConnectionConfiguration configuration + ) { + return dataSourceRegistry.createDataSource(dataSourceStorage, origin, id, driver, configuration); + } + @NotNull @Override public DBPDataSourceContainer createDataSource(@NotNull DBPDataSourceContainer source) { diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebProjectImpl.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebProjectImpl.java index c6c7144198..6058052231 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebProjectImpl.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebProjectImpl.java @@ -27,6 +27,7 @@ import org.jkiss.dbeaver.model.rm.RMController; import org.jkiss.dbeaver.model.rm.RMProject; import org.jkiss.dbeaver.model.task.DBTTaskManager; +import org.jkiss.dbeaver.registry.DataSourceRegistry; import org.jkiss.dbeaver.registry.rm.DataSourceRegistryRM; import org.jkiss.dbeaver.runtime.DBWorkbench; @@ -84,11 +85,15 @@ public DBTTaskManager getTaskManager() { @Override protected DBPDataSourceRegistry createDataSourceRegistry() { return new WebDataSourceRegistryProxy( - new DataSourceRegistryRM(this, getResourceController(), preferenceStore), + createRMRegistry(), getDataSourceFilter() ); } + protected DataSourceRegistry createRMRegistry() { + return new DataSourceRegistryRM<>(this, getResourceController(), preferenceStore); + } + @NotNull public DataSourceFilter getDataSourceFilter() { return (ds) -> true; diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebSessionProjectImpl.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebSessionProjectImpl.java index b55860c05b..9cbeeb1aa6 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebSessionProjectImpl.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebSessionProjectImpl.java @@ -34,6 +34,7 @@ import java.nio.file.Path; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; public class WebSessionProjectImpl extends WebProjectImpl { @@ -199,8 +200,8 @@ public synchronized boolean updateProjectDataSources(@NotNull List dataS .filter(Objects::nonNull) .collect(Collectors.toMap( DBPDataSourceContainer::getId, - ds -> new DataSourceDescriptor((DataSourceDescriptor) ds, ds.getRegistry()) - )); + Function.identity()) + ); if (type == WSEventType.DATASOURCE_CREATED || type == WSEventType.DATASOURCE_UPDATED) { registry.refreshConfig(dataSourceIds); } diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java index c5d8318213..9a27954e00 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java @@ -316,7 +316,7 @@ private WebSessionProjectImpl createWebProject(RMProject project) throws DBExcep if (project.isGlobal()) { sessionProject = createGlobalProject(project); } else { - sessionProject = new WebSessionProjectImpl(this, project, getProjectPath(project)); + sessionProject = createSessionProject(project); } // do not load data sources for anonymous project if (project.getType() == RMProjectType.USER && userContext.getUser() == null) { @@ -329,6 +329,10 @@ private WebSessionProjectImpl createWebProject(RMProject project) throws DBExcep return sessionProject; } + protected WebSessionProjectImpl createSessionProject(@NotNull RMProject project) throws DBException { + return new WebSessionProjectImpl(this, project, getProjectPath(project)); + } + @NotNull protected Path getProjectPath(@NotNull RMProject project) throws DBException { return RMUtils.getProjectPath(project); diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebGlobalProject.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebGlobalProject.java index 6cf1faec56..2999947646 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebGlobalProject.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebGlobalProject.java @@ -80,6 +80,6 @@ public boolean isUseSecretStorage() { @NotNull @Override protected DBPDataSourceRegistry createDataSourceRegistry() { - return new DataSourceRegistry(this); + return new DataSourceRegistry<>(this); } } \ No newline at end of file diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java index 408095d615..4461424b01 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java @@ -505,8 +505,9 @@ public WebConnectionInfo updateConnection( WebConnectionInfo connectionInfo = WebDataSourceUtils.getWebConnectionInfo(webSession, projectId, config.getConnectionId()); DBPDataSourceContainer dataSource = connectionInfo.getDataSourceContainer(); webSession.addInfoMessage("Update connection - " + WebServiceUtils.getConnectionContainerInfo(dataSource)); - var oldDataSource = new DataSourceDescriptor((DataSourceDescriptor) dataSource, dataSource.getRegistry()); - + DataSourceDescriptor oldDataSource; + oldDataSource = dataSource.getRegistry().createDataSource(dataSource); + oldDataSource.setId(dataSource.getId()); if (!CommonUtils.isEmpty(config.getName())) { dataSource.setName(config.getName()); }