Skip to content

Commit c8b161e

Browse files
author
pkolovos
committed
cancel query on tab close
1 parent 3a455e3 commit c8b161e

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

src/main/java/gr/sqlbrowserfx/nodes/sqlpane/DraggingTabPaneSupport.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import gr.sqlbrowserfx.utils.JavaFXUtils;
66
import javafx.collections.ListChangeListener.Change;
77
import javafx.scene.Node;
8+
import javafx.scene.control.ContextMenu;
89
import javafx.scene.control.Label;
10+
import javafx.scene.control.MenuItem;
911
import javafx.scene.control.Tab;
1012
import javafx.scene.control.TabPane;
13+
import javafx.scene.control.TextField;
1114
import javafx.scene.input.ClipboardContent;
1215
import javafx.scene.input.Dragboard;
16+
import javafx.scene.input.KeyCode;
1317
import javafx.scene.input.TransferMode;
1418

1519
public class DraggingTabPaneSupport {
@@ -32,6 +36,7 @@ public DraggingTabPaneSupport(String dragIconUrl) {
3236

3337
public void addSupport(TabPane tabPane) {
3438
tabPane.getTabs().forEach(this::addDragHandlers);
39+
3540
tabPane.getTabs().addListener((Change<? extends Tab> c) -> {
3641
while (c.next()) {
3742
if (c.wasAdded()) {
@@ -107,7 +112,7 @@ private void addDragHandlers(Tab tab) {
107112
tab.setText(null);
108113
tab.setGraphic(label);
109114
}
110-
115+
111116
Node graphic = tab.getGraphic();
112117
graphic.setOnDragDetected(e -> {
113118
Dragboard dragboard = graphic.startDragAndDrop(TransferMode.MOVE);

src/main/java/gr/sqlbrowserfx/nodes/sqlpane/SqlPane.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -601,23 +601,23 @@ protected void getDataFromDB(String table, final SqlTableTab sqlTableTab) {
601601
query += " limit " + linesLimit;
602602
}
603603

604-
String message = "Executing : " + query;
605-
logger.debug(message);
604+
logger.debug("Executing : " + query);
606605
try {
607-
sqlConnector.executeQueryRawSafely(query, resultSet -> {
608-
sqlTableView.setItemsLater(resultSet);
609-
// in case the query contains a view reset name
606+
sqlConnector.executeCancelableQuery(query, rset -> {
607+
sqlTableView.setItemsLater(rset);
610608
sqlTableView.setTableName(table);
611-
});
609+
},
610+
stmt -> sqlTableTab.setOnClosed(action -> {
611+
try {
612+
stmt.cancel();
613+
} catch (SQLException e) {
614+
LoggerFactory.getLogger(LoggerConf.LOGGER_NAME).error(e.getMessage());
615+
}
616+
}));
612617

613618
} catch (SQLException e) {
614619
DialogFactory.createErrorNotification(e);
615620
if (e.getErrorCode() == MemoryGuard.SQL_MEMORY_ERROR_CODE) {
616-
// TODO what must be done here in order to free memory?
617-
// Platform.runLater(() -> {
618-
// sqlTableTab.getOnClosed().handle(new ActionEvent());
619-
// tablesTabPane.getTabs().remove(sqlTableTab);
620-
// });
621621
System.gc();
622622
}
623623
} finally {

src/main/java/gr/sqlbrowserfx/nodes/tableviews/SqlTableView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public synchronized void setItemsLater(ResultSet rs) throws SQLException {
245245
parent.load();
246246
this.clear();
247247
});
248-
throw new SQLException("MemoryGuard action", "", MemoryGuard.SQL_MEMORY_ERROR_CODE);
248+
throw new SQLException("Query cnacelled", "", MemoryGuard.SQL_MEMORY_ERROR_CODE);
249249
}
250250

251251
Platform.runLater(() -> {

0 commit comments

Comments
 (0)