Skip to content

Commit

Permalink
Remove ConnectionPool
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Nov 24, 2023
1 parent 2aeed6f commit ebfc4ee
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 79 deletions.
54 changes: 0 additions & 54 deletions src/studio/kdb/ConnectionPool.java

This file was deleted.

34 changes: 33 additions & 1 deletion src/studio/kdb/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import studio.core.AuthenticationManager;
import studio.core.Credentials;
import studio.core.IAuthenticationMechanism;
import studio.ui.EditorTab;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Session {
private KConnection kConn;
Expand All @@ -20,10 +25,37 @@ public class Session {

private static final long HOUR = 1000*3600;
private static SessionCreator sessionCreator = new SessionCreator();
private final List<EditorTab> editors = new ArrayList<>();

private static final Logger log = LogManager.getLogger();

public Session(Server server) {
private final static Map<Server, Session> sessions = new HashMap<>();

public static Session newSession(EditorTab editor) {
Server server = editor.getServer();
Session session;
if (Config.getInstance().getBoolean(Config.SESSION_REUSE) ) {
session = sessions.get(server);
if (session == null) {
session = new Session(server);
sessions.put(server, session);
}
} else {
session = new Session(server);
}

session.editors.add(editor);
return session;
}

public void removeTab(EditorTab editor) {
editors.remove(editor);
if (editors.size() == 0) {
close();
}
}

private Session(Server server) {
this.server = server;
init();
}
Expand Down
12 changes: 7 additions & 5 deletions src/studio/ui/EditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ public Session getSession() {
return session;
}

public void setSession(Session session) {
this.session = session;
}

public void closing() {
stopFileWatching();
if (session != null) {
session.close();
session.removeTab(this);
}
}

Expand Down Expand Up @@ -249,7 +245,13 @@ public Server getServer() {

public void setServer(Server server) {
if (this.server == server) return;

if (session != null) {
session.removeTab(this);
}
this.server = server;
session = Session.newSession(this);

getTextArea().setBackground(server.getBackgroundColor());

studioWindow.getMainStatusBar().setTemporaryStatus("Changed server: " + server.getDescription(true));
Expand Down
3 changes: 0 additions & 3 deletions src/studio/ui/StudioWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ private void initActions() {
if (stopAction.isEnabled())
stopAction.actionPerformed(e);

ConnectionPool.getInstance().purge(editor.getServer());
CONFIG.removeServer(editor.getServer());

Server newServer = f.getServer();
Expand All @@ -553,7 +552,6 @@ private void initActions() {
if (f.getResult() == ACCEPTED) {
Server s = f.getServer();
CONFIG.addServer(s);
ConnectionPool.getInstance().purge(s); //?
setServer(s);
rerfreshAll();
}
Expand Down Expand Up @@ -906,7 +904,6 @@ private void refreshMenu() {
clone = f.getServer();
CONFIG.addServer(clone);
setServer(clone);
ConnectionPool.getInstance().purge(clone); //?
rerfreshAll();
}
});
Expand Down
19 changes: 3 additions & 16 deletions src/studio/ui/action/QueryExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import kx.ProgressCallback;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import studio.kdb.*;
import studio.kdb.K;
import studio.kdb.Server;
import studio.kdb.Session;
import studio.ui.EditorTab;
import studio.ui.StudioWindow;

Expand Down Expand Up @@ -116,22 +118,7 @@ void closeConnection() {
}

private Session getSession() {
if (Config.getInstance().getBoolean(Config.SESSION_REUSE)) {
return ConnectionPool.getInstance().leaseConnection(server);
}

Session session = editor.getSession();
if (session == null) {
session = new Session(server);
editor.setSession(session);
}

if (! session.getServer().equals(server) ) {
session.close();
session = new Session(server);
editor.setSession(session);
}

session.validate();
return session;
}
Expand Down

0 comments on commit ebfc4ee

Please sign in to comment.