From ab986e9526964fbe182a4fb4eeb571b39ff3ac3f Mon Sep 17 00:00:00 2001 From: CarmJos Date: Thu, 23 Dec 2021 15:17:12 +0800 Subject: [PATCH] =?UTF-8?q?[v0.2.3]=20=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E7=9A=84=E7=BB=88=E6=AD=A2manager=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E6=94=AF=E6=8C=81=E5=BC=BA=E5=88=B6=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E9=93=BE=E6=8E=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- easysql-api/pom.xml | 2 +- easysql-beecp/pom.xml | 2 +- .../java/cc/carm/lib/easysql/EasySQL.java | 25 +++++++++++++++++++ easysql-demo/pom.xml | 2 +- easysql-hikaricp/pom.xml | 2 +- .../src/main/java/easysql/EasySQL.java | 24 ++++++++++++++++++ easysql-impl/pom.xml | 2 +- .../lib/easysql/manager/SQLManagerImpl.java | 2 +- pom.xml | 2 +- 9 files changed, 56 insertions(+), 7 deletions(-) diff --git a/easysql-api/pom.xml b/easysql-api/pom.xml index 5068b42..836ecec 100644 --- a/easysql-api/pom.xml +++ b/easysql-api/pom.xml @@ -5,7 +5,7 @@ cc.carm.lib easysql-parent - 0.2.2 + 0.2.3 4.0.0 diff --git a/easysql-beecp/pom.xml b/easysql-beecp/pom.xml index 04eee2c..7e385ee 100644 --- a/easysql-beecp/pom.xml +++ b/easysql-beecp/pom.xml @@ -5,7 +5,7 @@ easysql-parent cc.carm.lib - 0.2.2 + 0.2.3 4.0.0 diff --git a/easysql-beecp/src/main/java/cc/carm/lib/easysql/EasySQL.java b/easysql-beecp/src/main/java/cc/carm/lib/easysql/EasySQL.java index 166c102..8f1c87b 100644 --- a/easysql-beecp/src/main/java/cc/carm/lib/easysql/EasySQL.java +++ b/easysql-beecp/src/main/java/cc/carm/lib/easysql/EasySQL.java @@ -1,5 +1,8 @@ package cc.carm.lib.easysql; +import cc.carm.lib.easysql.api.SQLManager; +import cc.carm.lib.easysql.api.action.query.SQLQuery; +import cc.carm.lib.easysql.api.util.TimeDateUtils; import cc.carm.lib.easysql.manager.SQLManagerImpl; import cn.beecp.BeeDataSource; import cn.beecp.BeeDataSourceConfig; @@ -18,4 +21,26 @@ public class EasySQL { return new SQLManagerImpl(new BeeDataSource(config)); } + + public static void shutdownManager(SQLManager manager, boolean forceClose, boolean outputActiveQuery) { + if (!manager.getActiveQuery().isEmpty()) { + manager.getLogger().severe("There are " + manager.getActiveQuery().size() + " connections still running"); + for (SQLQuery value : manager.getActiveQuery().values()) { + if (outputActiveQuery) { + manager.getLogger().severe("#" + value.getAction().getShortID() + " -> " + value.getSQLContent()); + manager.getLogger().severe("- execute at " + TimeDateUtils.getTimeString(value.getExecuteTime())); + } + if (forceClose) value.close(); + } + } + if (manager.getDataSource() instanceof BeeDataSource) { + //Close bee connection pool + ((BeeDataSource) manager.getDataSource()).close(); + } + } + + public static void shutdownManager(SQLManager manager) { + shutdownManager(manager, true, manager.isDebugMode()); + } + } diff --git a/easysql-demo/pom.xml b/easysql-demo/pom.xml index ccbc99c..54ba132 100644 --- a/easysql-demo/pom.xml +++ b/easysql-demo/pom.xml @@ -5,7 +5,7 @@ easysql-parent cc.carm.lib - 0.2.2 + 0.2.3 4.0.0 diff --git a/easysql-hikaricp/pom.xml b/easysql-hikaricp/pom.xml index 393a50a..1b5e7dc 100644 --- a/easysql-hikaricp/pom.xml +++ b/easysql-hikaricp/pom.xml @@ -5,7 +5,7 @@ easysql-parent cc.carm.lib - 0.2.2 + 0.2.3 4.0.0 diff --git a/easysql-hikaricp/src/main/java/easysql/EasySQL.java b/easysql-hikaricp/src/main/java/easysql/EasySQL.java index 7a592ab..1b57170 100644 --- a/easysql-hikaricp/src/main/java/easysql/EasySQL.java +++ b/easysql-hikaricp/src/main/java/easysql/EasySQL.java @@ -1,5 +1,8 @@ package easysql; +import cc.carm.lib.easysql.api.SQLManager; +import cc.carm.lib.easysql.api.action.query.SQLQuery; +import cc.carm.lib.easysql.api.util.TimeDateUtils; import cc.carm.lib.easysql.manager.SQLManagerImpl; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @@ -29,4 +32,25 @@ public class EasySQL { return new SQLManagerImpl(new HikariDataSource(config)); } + public static void shutdownManager(SQLManager manager, boolean forceClose, boolean outputActiveQuery) { + if (!manager.getActiveQuery().isEmpty()) { + manager.getLogger().severe("There are " + manager.getActiveQuery().size() + " connections still running"); + for (SQLQuery value : manager.getActiveQuery().values()) { + if (outputActiveQuery) { + manager.getLogger().severe("#" + value.getAction().getShortID() + " -> " + value.getSQLContent()); + manager.getLogger().severe("- execute at " + TimeDateUtils.getTimeString(value.getExecuteTime())); + } + if (forceClose) value.close(); + } + } + if (manager.getDataSource() instanceof HikariDataSource) { + //Close hikari pool + ((HikariDataSource) manager.getDataSource()).close(); + } + } + + public static void shutdownManager(SQLManager manager) { + shutdownManager(manager, true, manager.isDebugMode()); + } + } diff --git a/easysql-impl/pom.xml b/easysql-impl/pom.xml index 7d6aa52..2a3e4f6 100644 --- a/easysql-impl/pom.xml +++ b/easysql-impl/pom.xml @@ -5,7 +5,7 @@ easysql-parent cc.carm.lib - 0.2.2 + 0.2.3 4.0.0 diff --git a/easysql-impl/src/main/java/cc/carm/lib/easysql/manager/SQLManagerImpl.java b/easysql-impl/src/main/java/cc/carm/lib/easysql/manager/SQLManagerImpl.java index 64d2dc5..1926cac 100644 --- a/easysql-impl/src/main/java/cc/carm/lib/easysql/manager/SQLManagerImpl.java +++ b/easysql-impl/src/main/java/cc/carm/lib/easysql/manager/SQLManagerImpl.java @@ -5,10 +5,10 @@ import cc.carm.lib.easysql.action.PreparedSQLUpdateActionImpl; import cc.carm.lib.easysql.action.SQLUpdateActionImpl; import cc.carm.lib.easysql.action.SQLUpdateBatchActionImpl; import cc.carm.lib.easysql.api.SQLManager; -import cc.carm.lib.easysql.api.action.query.SQLQuery; import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction; import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction; import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction; +import cc.carm.lib.easysql.api.action.query.SQLQuery; import cc.carm.lib.easysql.api.builder.*; import cc.carm.lib.easysql.builder.impl.*; import org.jetbrains.annotations.NotNull; diff --git a/pom.xml b/pom.xml index a73a1ed..2e4fc95 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ cc.carm.lib easysql-parent pom - 0.2.2 + 0.2.3 easysql-api