Skip to content

Commit 47bb280

Browse files
authored
CB-2464 de save data sources remotely fix (dbeaver#1081)
* CB-2464 de save data sources remotely fix * CB-2464 add data source persistence registry
1 parent 94c8fa0 commit 47bb280

5 files changed

Lines changed: 259 additions & 27 deletions

File tree

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/VirtualProjectImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.core.resources.IProject;
2121
import org.jkiss.code.NotNull;
2222
import org.jkiss.code.Nullable;
23+
import org.jkiss.dbeaver.model.app.DBPDataSourceRegistry;
2324
import org.jkiss.dbeaver.model.auth.SMSessionContext;
2425
import org.jkiss.dbeaver.model.rm.RMProject;
2526
import org.jkiss.dbeaver.registry.BaseProjectImpl;
@@ -93,7 +94,7 @@ public RMProject getRmProject() {
9394

9495
@NotNull
9596
@Override
96-
protected DataSourceRegistry createDataSourceRegistry() {
97-
return new WebDataSourceRegistryProxy(super.createDataSourceRegistry(), dataSourceFilter);
97+
protected DBPDataSourceRegistry createDataSourceRegistry() {
98+
return new WebDataSourceRegistryProxy(new DataSourceRegistry(this), dataSourceFilter);
9899
}
99100
}

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/WebDataSourceRegistryProxy.java

Lines changed: 246 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,40 @@
77
import org.jkiss.dbeaver.model.*;
88
import org.jkiss.dbeaver.model.access.DBAAuthProfile;
99
import org.jkiss.dbeaver.model.access.DBACredentialsProvider;
10+
import org.jkiss.dbeaver.model.app.DBPDataSourceRegistry;
1011
import org.jkiss.dbeaver.model.app.DBPProject;
1112
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
1213
import org.jkiss.dbeaver.model.connection.DBPDriver;
1314
import org.jkiss.dbeaver.model.net.DBWNetworkProfile;
15+
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
1416
import org.jkiss.dbeaver.model.struct.DBSObjectFilter;
15-
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
16-
import org.jkiss.dbeaver.registry.DataSourceFolder;
17+
import org.jkiss.dbeaver.registry.DataSourceConfigurationManager;
18+
import org.jkiss.dbeaver.registry.DataSourcePersistentRegistry;
1719
import org.jkiss.dbeaver.registry.DataSourceRegistry;
1820

1921
import java.util.List;
22+
import java.util.Set;
23+
import java.util.function.Predicate;
2024
import java.util.stream.Collectors;
2125

22-
public class WebDataSourceRegistryProxy extends DataSourceRegistry {
26+
public class WebDataSourceRegistryProxy implements DBPDataSourceRegistry, DataSourcePersistentRegistry {
2327
private final DataSourceFilter dataSourceFilter;
28+
private final DataSourceRegistry dataSourceRegistry;
2429

2530
public WebDataSourceRegistryProxy(DataSourceRegistry dataSourceRegistry, DataSourceFilter filter) {
26-
super(dataSourceRegistry.getProject());
31+
this.dataSourceRegistry = dataSourceRegistry;
2732
this.dataSourceFilter = filter;
2833
}
2934

35+
@Override
36+
public DBPProject getProject() {
37+
return dataSourceRegistry.getProject();
38+
}
39+
3040
@Nullable
3141
@Override
32-
public DataSourceDescriptor getDataSource(String id) {
33-
DataSourceDescriptor dataSource = super.getDataSource(id);
42+
public DBPDataSourceContainer getDataSource(String id) {
43+
DBPDataSourceContainer dataSource = dataSourceRegistry.getDataSource(id);
3444
if (dataSourceFilter != null && !dataSourceFilter.filter(dataSource)) {
3545
return null;
3646
}
@@ -39,17 +49,17 @@ public DataSourceDescriptor getDataSource(String id) {
3949

4050
@Nullable
4151
@Override
42-
public DataSourceDescriptor getDataSource(DBPDataSource dataSource) {
52+
public DBPDataSourceContainer getDataSource(DBPDataSource dataSource) {
4353
if (dataSourceFilter != null && !dataSourceFilter.filter(dataSource.getContainer())) {
4454
return null;
4555
}
46-
return super.getDataSource(dataSource);
56+
return dataSourceRegistry.getDataSource(dataSource);
4757
}
4858

4959
@Nullable
5060
@Override
51-
public DataSourceDescriptor findDataSourceByName(String name) {
52-
var dataSource = super.findDataSourceByName(name);
61+
public DBPDataSourceContainer findDataSourceByName(String name) {
62+
var dataSource = dataSourceRegistry.findDataSourceByName(name);
5363
if (dataSource != null) {
5464
if (dataSourceFilter == null || dataSourceFilter.filter(dataSource)) {
5565
return dataSource;
@@ -61,18 +71,241 @@ public DataSourceDescriptor findDataSourceByName(String name) {
6171
@NotNull
6272
@Override
6373
public List<? extends DBPDataSourceContainer> getDataSourcesByProfile(@NotNull DBWNetworkProfile profile) {
64-
return super.getDataSourcesByProfile(profile)
74+
return dataSourceRegistry.getDataSourcesByProfile(profile)
6575
.stream()
6676
.filter(dataSourceFilter::filter)
6777
.collect(Collectors.toList());
6878
}
6979

7080
@NotNull
7181
@Override
72-
public List<DataSourceDescriptor> getDataSources() {
73-
return super.getDataSources()
82+
public List<DBPDataSourceContainer> getDataSources() {
83+
return dataSourceRegistry.getDataSources()
7484
.stream()
7585
.filter(dataSourceFilter::filter)
7686
.collect(Collectors.toList());
7787
}
88+
89+
@NotNull
90+
@Override
91+
public DBPDataSourceContainer createDataSource(DBPDriver driver, DBPConnectionConfiguration connConfig) {
92+
return dataSourceRegistry.createDataSource(driver, connConfig);
93+
}
94+
95+
@NotNull
96+
@Override
97+
public DBPDataSourceContainer createDataSource(DBPDataSourceContainer source) {
98+
return dataSourceRegistry.createDataSource(source);
99+
}
100+
101+
@Override
102+
public void addDataSourceListener(@NotNull DBPEventListener listener) {
103+
dataSourceRegistry.addDataSourceListener(listener);
104+
}
105+
106+
@Override
107+
public boolean removeDataSourceListener(@NotNull DBPEventListener listener) {
108+
return dataSourceRegistry.removeDataSourceListener(listener);
109+
}
110+
111+
@Override
112+
public void addDataSource(@NotNull DBPDataSourceContainer dataSource) {
113+
dataSourceRegistry.addDataSource(dataSource);
114+
}
115+
116+
@Override
117+
public void removeDataSource(@NotNull DBPDataSourceContainer dataSource) {
118+
dataSourceRegistry.removeDataSource(dataSource);
119+
}
120+
121+
@Override
122+
public void updateDataSource(@NotNull DBPDataSourceContainer dataSource) {
123+
dataSourceRegistry.updateDataSource(dataSource);
124+
}
125+
126+
@NotNull
127+
@Override
128+
public List<? extends DBPDataSourceFolder> getAllFolders() {
129+
return dataSourceRegistry.getAllFolders();
130+
}
131+
132+
@NotNull
133+
@Override
134+
public List<? extends DBPDataSourceFolder> getRootFolders() {
135+
return dataSourceRegistry.getRootFolders();
136+
}
137+
138+
@Override
139+
public DBPDataSourceFolder getFolder(String path) {
140+
return dataSourceRegistry.getFolder(path);
141+
}
142+
143+
@Override
144+
public DBPDataSourceFolder addFolder(DBPDataSourceFolder parent, String name) {
145+
return dataSourceRegistry.addFolder(parent, name);
146+
}
147+
148+
@Override
149+
public void removeFolder(DBPDataSourceFolder folder, boolean dropContents) {
150+
dataSourceRegistry.removeFolder(folder, dropContents);
151+
}
152+
153+
@Nullable
154+
@Override
155+
public DBSObjectFilter getSavedFilter(String name) {
156+
return dataSourceRegistry.getSavedFilter(name);
157+
}
158+
159+
@NotNull
160+
@Override
161+
public List<DBSObjectFilter> getSavedFilters() {
162+
return dataSourceRegistry.getSavedFilters();
163+
}
164+
165+
@Override
166+
public void updateSavedFilter(DBSObjectFilter filter) {
167+
dataSourceRegistry.updateSavedFilter(filter);
168+
}
169+
170+
@Override
171+
public void removeSavedFilter(String filterName) {
172+
dataSourceRegistry.removeSavedFilter(filterName);
173+
}
174+
175+
@Nullable
176+
@Override
177+
public DBWNetworkProfile getNetworkProfile(String name) {
178+
return dataSourceRegistry.getNetworkProfile(name);
179+
}
180+
181+
@NotNull
182+
@Override
183+
public List<DBWNetworkProfile> getNetworkProfiles() {
184+
return dataSourceRegistry.getNetworkProfiles();
185+
}
186+
187+
@Override
188+
public void updateNetworkProfile(DBWNetworkProfile profile) {
189+
dataSourceRegistry.updateNetworkProfile(profile);
190+
}
191+
192+
@Override
193+
public void removeNetworkProfile(DBWNetworkProfile profile) {
194+
dataSourceRegistry.removeNetworkProfile(profile);
195+
}
196+
197+
@Nullable
198+
@Override
199+
public DBAAuthProfile getAuthProfile(String id) {
200+
return dataSourceRegistry.getAuthProfile(id);
201+
}
202+
203+
@NotNull
204+
@Override
205+
public List<DBAAuthProfile> getAllAuthProfiles() {
206+
return dataSourceRegistry.getAllAuthProfiles();
207+
}
208+
209+
@NotNull
210+
@Override
211+
public List<DBAAuthProfile> getApplicableAuthProfiles(@Nullable DBPDriver driver) {
212+
return dataSourceRegistry.getApplicableAuthProfiles(driver);
213+
}
214+
215+
@Override
216+
public void updateAuthProfile(DBAAuthProfile profile) {
217+
dataSourceRegistry.updateAuthProfile(profile);
218+
}
219+
220+
@Override
221+
public void removeAuthProfile(DBAAuthProfile profile) {
222+
dataSourceRegistry.removeAuthProfile(profile);
223+
}
224+
225+
@Override
226+
public void flushConfig() {
227+
dataSourceRegistry.flushConfig();
228+
}
229+
230+
@Override
231+
public void refreshConfig() {
232+
dataSourceRegistry.refreshConfig();
233+
}
234+
235+
@Override
236+
public Throwable getLastError() {
237+
return dataSourceRegistry.getLastError();
238+
}
239+
240+
@Override
241+
public boolean hasError() {
242+
return dataSourceRegistry.hasError();
243+
}
244+
245+
@Override
246+
public void checkForErrors() throws DBException {
247+
dataSourceRegistry.checkForErrors();
248+
}
249+
250+
@Override
251+
public void notifyDataSourceListeners(DBPEvent event) {
252+
dataSourceRegistry.notifyDataSourceListeners(event);
253+
}
254+
255+
@NotNull
256+
@Override
257+
public ISecurePreferences getSecurePreferences() {
258+
return dataSourceRegistry.getSecurePreferences();
259+
}
260+
261+
@Nullable
262+
@Override
263+
public DBACredentialsProvider getAuthCredentialsProvider() {
264+
return dataSourceRegistry.getAuthCredentialsProvider();
265+
}
266+
267+
@Override
268+
public void dispose() {
269+
dataSourceRegistry.dispose();
270+
}
271+
272+
@Override
273+
public void setAuthCredentialsProvider(DBACredentialsProvider authCredentialsProvider) {
274+
dataSourceRegistry.setAuthCredentialsProvider(authCredentialsProvider);
275+
}
276+
277+
@Override
278+
public Set<DBPDataSourceFolder> getTemporaryFolders() {
279+
return dataSourceRegistry.getTemporaryFolders();
280+
}
281+
282+
@Override
283+
public void loadDataSources(
284+
@NotNull List<DBPDataSourceConfigurationStorage> storages,
285+
@NotNull DataSourceConfigurationManager manager,
286+
boolean refresh,
287+
boolean purgeUntouched
288+
) {
289+
dataSourceRegistry.loadDataSources(storages, manager, refresh, purgeUntouched);
290+
}
291+
292+
@Override
293+
public void saveDataSources() {
294+
dataSourceRegistry.saveDataSources();
295+
}
296+
297+
@Override
298+
public DataSourceConfigurationManager getConfigurationManager() {
299+
return dataSourceRegistry.getConfigurationManager();
300+
}
301+
302+
@Override
303+
public void saveConfigurationToManager(
304+
@NotNull DBRProgressMonitor monitor,
305+
@NotNull DataSourceConfigurationManager configurationManager,
306+
@Nullable Predicate<DBPDataSourceContainer> filter
307+
) {
308+
dataSourceRegistry.saveConfigurationToManager(monitor, configurationManager, filter);
309+
}
310+
78311
}

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.jkiss.dbeaver.DBException;
2828
import org.jkiss.dbeaver.Log;
2929
import org.jkiss.dbeaver.model.DBPDataSourceConfigurationStorage;
30+
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
3031
import org.jkiss.dbeaver.model.app.DBPDataSourceRegistry;
3132
import org.jkiss.dbeaver.model.app.DBPProject;
3233
import org.jkiss.dbeaver.model.auth.SMCredentials;
@@ -259,30 +260,30 @@ public String getProjectsDataSources(@NotNull String projectId) throws DBExcepti
259260
DBPDataSourceRegistry registry = projectMetadata.getDataSourceRegistry();
260261
registry.checkForErrors();
261262
DataSourceConfigurationManagerBuffer buffer = new DataSourceConfigurationManagerBuffer();
262-
((DataSourceRegistry)registry).saveConfigurationToManager(new VoidProgressMonitor(), buffer, null);
263+
((DataSourcePersistentRegistry) registry).saveConfigurationToManager(new VoidProgressMonitor(), buffer, null);
263264
registry.checkForErrors();
264265
return new String(buffer.getData(), StandardCharsets.UTF_8);
265266
}
266267

267268
@Override
268269
public void saveProjectDataSources(@NotNull String projectId, @NotNull String configuration) throws DBException {
269270
final DBPProject project = getProjectMetadata(projectId);
270-
final DataSourceRegistry registry = (DataSourceRegistry) project.getDataSourceRegistry();
271+
final DBPDataSourceRegistry registry = project.getDataSourceRegistry();
271272
final DBPDataSourceConfigurationStorage storage = new DataSourceMemoryStorage(configuration.getBytes(StandardCharsets.UTF_8));
272273
final DataSourceConfigurationManager manager = new DataSourceConfigurationManagerBuffer();
273-
registry.loadDataSources(List.of(storage), manager, true, false);
274+
((DataSourcePersistentRegistry) registry).loadDataSources(List.of(storage), manager, true, false);
274275
registry.checkForErrors();
275-
registry.saveDataSources();
276+
((DataSourcePersistentRegistry) registry).saveDataSources();
276277
registry.checkForErrors();
277278
}
278279

279280
@Override
280281
public void deleteProjectDataSources(@NotNull String projectId, @NotNull String[] dataSourceIds) throws DBException {
281282
final DBPProject project = getProjectMetadata(projectId);
282-
final DataSourceRegistry registry = (DataSourceRegistry) project.getDataSourceRegistry();
283+
final DBPDataSourceRegistry registry = project.getDataSourceRegistry();
283284

284285
for (String dataSourceId : dataSourceIds) {
285-
final DataSourceDescriptor dataSource = registry.getDataSource(dataSourceId);
286+
final DBPDataSourceContainer dataSource = registry.getDataSource(dataSourceId);
286287

287288
if (dataSource != null) {
288289
registry.removeDataSource(dataSource);

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
*/
1717
package io.cloudbeaver.model.session;
1818

19-
import io.cloudbeaver.DBWConstants;
20-
import io.cloudbeaver.DBWebException;
21-
import io.cloudbeaver.DataSourceFilter;
22-
import io.cloudbeaver.VirtualProjectImpl;
19+
import io.cloudbeaver.*;
2320
import io.cloudbeaver.model.WebAsyncTaskInfo;
2421
import io.cloudbeaver.model.WebConnectionInfo;
2522
import io.cloudbeaver.model.WebServerMessage;
@@ -366,7 +363,7 @@ public VirtualProjectImpl createVirtualProject(RMProject project) {
366363
this,
367364
filter);
368365
DBPDataSourceRegistry dataSourceRegistry = sessionProject.getDataSourceRegistry();
369-
((DataSourceRegistry) dataSourceRegistry).setAuthCredentialsProvider(this);
366+
dataSourceRegistry.setAuthCredentialsProvider(this);
370367
addSessionProject(sessionProject);
371368
if (!project.isShared() || application.isConfigurationMode()) {
372369
this.defaultProject = sessionProject;

0 commit comments

Comments
 (0)