Skip to content

Commit a818a6b

Browse files
yagudin10EvgeniaBzzzsergeyteleshev
authored
CB-6200 disconnect data source on changing config (#3240)
* CB-6200 disconnect data source on changing * CB-6200 correctly checks if connection is connected on updated connection resource event * Revert "CB-6200 correctly checks if connection is connected on updated connection resource event" This reverts commit 45485a0. --------- Co-authored-by: Evgenia <139753579+EvgeniaBzzz@users.noreply.github.com> Co-authored-by: sergeyteleshev <iamsergeyteleshev@gmail.com>
1 parent 7919ec8 commit a818a6b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import java.nio.file.Path;
3737
import java.util.*;
38-
import java.util.function.Function;
3938
import java.util.stream.Collectors;
4039

4140
public class WebSessionProjectImpl extends WebProjectImpl {
@@ -206,7 +205,7 @@ public synchronized boolean updateProjectDataSources(@NotNull List<String> dataS
206205
.filter(Objects::nonNull)
207206
.collect(Collectors.toMap(
208207
DBPDataSourceContainer::getId,
209-
Function.identity())
208+
registry::createDataSource)
210209
);
211210
if (WSDataSourceEvent.CREATED.equals(eventId) || WSDataSourceEvent.UPDATED.equals(eventId)) {
212211
registry.refreshConfig(dataSourceIds);
@@ -221,8 +220,14 @@ public synchronized boolean updateProjectDataSources(@NotNull List<String> dataS
221220
addConnection(ds);
222221
sendDataSourceUpdatedEvent = true;
223222
}
224-
case WSDataSourceEvent.UPDATED -> // if settings were changed we need to send event
225-
sendDataSourceUpdatedEvent |= !ds.equalSettings(oldDataSources.get(dsId));
223+
case WSDataSourceEvent.UPDATED -> {
224+
boolean connectionUpdated = !ds.equalSettings(oldDataSources.get(dsId));
225+
if (connectionUpdated) {
226+
sendDataSourceUpdatedEvent = true;
227+
WebDataSourceUtils.disconnectDataSource(webSession, ds);
228+
}
229+
// if settings were changed we need to send event
230+
}
226231
case WSDataSourceEvent.DELETED -> {
227232
WebDataSourceUtils.disconnectDataSource(webSession, ds);
228233
if (registry instanceof DBPDataSourceRegistryCache dsrc) {

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/utils/WebDataSourceUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
3333
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
3434
import org.jkiss.dbeaver.model.net.ssh.SSHConstants;
35+
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceDisconnectEvent;
3536
import org.jkiss.dbeaver.runtime.DBWorkbench;
3637
import org.jkiss.utils.CommonUtils;
3738

@@ -157,6 +158,14 @@ public static boolean disconnectDataSource(@NotNull WebSession webSession, @NotN
157158
if (dataSource.isConnected()) {
158159
try {
159160
dataSource.disconnect(webSession.getProgressMonitor());
161+
webSession.addSessionEvent(
162+
new WSDataSourceDisconnectEvent(
163+
dataSource.getProject().getId(),
164+
dataSource.getId(),
165+
webSession.getSessionId(),
166+
webSession.getUserId()
167+
)
168+
);
160169
return true;
161170
} catch (DBException e) {
162171
log.error("Error closing connection", e);

0 commit comments

Comments
 (0)