Skip to content

Commit

Permalink
CB-5570 connection cache same ids fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yagudin10 committed Sep 4, 2024
1 parent b6b8388 commit 0aac260
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void dispose() {
@Nullable
public WebConnectionInfo findWebConnectionInfo(@NotNull String connectionId) {
synchronized (connections) {
return connections.get(connectionId);
return connections.get(getConnectionId(connectionId));
}
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public WebConnectionInfo getWebConnectionInfo(@NotNull String connectionId) thro
public synchronized WebConnectionInfo addConnection(@NotNull DBPDataSourceContainer dataSourceContainer) {
WebConnectionInfo connection = new WebConnectionInfo(webSession, dataSourceContainer);
synchronized (connections) {
connections.put(dataSourceContainer.getId(), connection);
connections.put(getConnectionId(dataSourceContainer), connection);
}
return connection;
}
Expand All @@ -141,15 +141,24 @@ public synchronized WebConnectionInfo addConnection(@NotNull DBPDataSourceContai
* Removes connection from project cache.
*/
public void removeConnection(@NotNull DBPDataSourceContainer dataSourceContainer) {
WebConnectionInfo webConnectionInfo = connections.get(dataSourceContainer.getId());
if (webConnectionInfo != null) {
webConnectionInfo.clearCache();
synchronized (connections) {
connections.remove(dataSourceContainer.getId());
synchronized (connections) {
WebConnectionInfo webConnectionInfo = connections.remove(getConnectionId(dataSourceContainer));
if (webConnectionInfo != null) {
webConnectionInfo.clearCache();
}
}
}

@NotNull
private String getConnectionId(@NotNull DBPDataSourceContainer dataSourceContainer) {
return getConnectionId(dataSourceContainer.getId());
}

@NotNull
private String getConnectionId(@NotNull String dataSourceId) {
return getId() + ":" + dataSourceId;
}

/**
* Loads connection from registry if they are not loaded.
*
Expand Down

0 comments on commit 0aac260

Please sign in to comment.