1
mirror of https://github.com/CarmJos/EasySQL.git synced 2026-06-05 09:01:26 +08:00

Compare commits

...

19 Commits

Author SHA1 Message Date
carm 19490d7508 Merge remote-tracking branch 'origin/master' 2022-04-27 02:09:07 +08:00
carm e8a01169d2 [0.3.16] 支持 IS NULL 判断(即设定queryValue为null)。 2022-04-27 02:08:58 +08:00
carm 2e1df7c7f6 Merge pull request #46 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.4.0
Bump maven-javadoc-plugin from 3.3.2 to 3.4.0
2022-04-21 17:04:02 +08:00
dependabot[bot] 1812db3a16 Bump maven-javadoc-plugin from 3.3.2 to 3.4.0
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.2 to 3.4.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.3.2...maven-javadoc-plugin-3.4.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-21 08:31:13 +00:00
carm deb5de35a8 移除api与impl的shaded 2022-04-17 17:23:49 +08:00
carm e9ce0a769c [0.3.15] 版本修复
- `[F]` 修复上一版本中 SQLDebugHandler 的处理出现空指针异常。
2022-04-13 08:04:30 +08:00
carm e98e9586ef [0.3.14] 版本修复
- `[F]` 修复上一版本中 SQLDebugHandler 的处理出现空指针异常。
2022-04-13 07:52:06 +08:00
carm 6cd080210f [0.3.14] 版本修复
- `[F]` 修复上一版本中 SQLDebugHandler 的处理出现空指针异常。
2022-04-13 07:51:56 +08:00
carm 20ac8f3908 [0.3.13] 版本修复
- `[R]` 修复上一版本中 SQLDebugHandler 的处理出现空指针异常。
2022-04-13 07:12:07 +08:00
carm c079c98e3e [0.3.12] 版本更新 (破坏性)
- `[R]` 采用 slf4j-api 替代Java原生的Logger库。
- `[A]` 新增 SQLDebugHandler 用于更好的处理调试消息。
2022-04-13 06:37:19 +08:00
carm 18dd618c21 [0.3.12] 版本更新 (破坏性)
- `[R]` 采用 slf4j-api 替代Java原生的Logger库。
- `[A]` 新增 SQLDebugHandler 用于更好的处理调试消息。
2022-04-13 06:30:20 +08:00
carm 03e157d3d9 [0.3.11] (破坏性更新) 令SQLUpdateAction返回的值为 Long 以适配自增主键大小范围。 2022-04-12 16:46:42 +08:00
carm a2d972621d [0.3.11] (破坏性更新) 令SQLUpdateAction返回的值为 Long 以适配自增主键大小范围。 2022-04-12 16:43:38 +08:00
carm 903f3a5f93 [0.3.11] (破坏性更新) 令SQLUpdateAction返回的值为 Long 以适配自增主键大小范围。 2022-04-12 16:14:35 +08:00
carm 44f9392e81 [0.3.11] (破坏性更新) 令SQLUpdateAction返回的值为 Long 以适配自增主键大小范围。 2022-04-12 16:09:51 +08:00
carm 1ad196f04b Merge remote-tracking branch 'origin/master' 2022-04-12 16:08:43 +08:00
carm fd0a4e48ef [0.3.11] (破坏性更新) 令SQLUpdateAction返回的值为 Long 以适配自增主键大小范围。 2022-04-12 16:08:29 +08:00
carm 14ee6ca1f2 Merge pull request #43 from CarmJos/dependabot/maven/com.h2database-h2-2.1.212
Bump h2 from 2.1.210 to 2.1.212
2022-04-12 03:42:33 +08:00
dependabot[bot] db33e5e830 Bump h2 from 2.1.210 to 2.1.212
Bumps [h2](https://github.com/h2database/h2database) from 2.1.210 to 2.1.212.
- [Release notes](https://github.com/h2database/h2database/releases)
- [Commits](https://github.com/h2database/h2database/compare/version-2.1.210...version-2.1.212)

---
updated-dependencies:
- dependency-name: com.h2database:h2
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-11 09:50:42 +00:00
39 changed files with 334 additions and 136 deletions
+9 -5
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<version>0.3.10</version>
<version>0.3.16</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -52,6 +52,14 @@
<url>https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml</url>
</ciManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@@ -70,10 +78,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>
@@ -6,10 +6,12 @@ import cc.carm.lib.easysql.api.function.SQLHandler;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
/**
* SQLAction 是用于承载SQL语句并进行处理、返回的基本类。
@@ -60,6 +62,15 @@ public interface SQLAction<T> {
*/
@NotNull String getSQLContent();
/**
* 得到该Action所要执行的源SQL语句列表。
*
* @return 源SQL语句列表
*/
default @NotNull List<String> getSQLContents() {
return Collections.singletonList(getSQLContent());
}
/**
* 得到承载该Action的对应{@link SQLManager}
*
@@ -5,9 +5,11 @@ import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
import cc.carm.lib.easysql.api.action.SQLUpdateAction;
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
import cc.carm.lib.easysql.api.builder.*;
import cc.carm.lib.easysql.api.function.SQLDebugHandler;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -16,7 +18,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;
import java.util.logging.Logger;
/**
* SQLManager 是EasySQL的核心类,用于管理数据库连接,提供数据库操作的方法。
@@ -29,12 +30,38 @@ public interface SQLManager {
boolean isDebugMode();
/**
* 设定是否启用调试模式。
* 启用调试模式后,会在每次执行SQL语句时,调用 {@link #getDebugHandler()} 来输出调试信息。
*
* @param debugMode 是否启用调试模式
*/
void setDebugMode(@NotNull Supplier<@NotNull Boolean> debugMode);
/**
* 设定是否启用调试模式。
* 启用调试模式后,会在每次执行SQL语句时,调用 {@link #getDebugHandler()} 来输出调试信息。
*
* @param enable 是否启用调试模式
*/
default void setDebugMode(boolean enable) {
setDebugMode(() -> enable);
}
/**
* 获取调试处理器,用于处理调试信息。
*
* @return {@link SQLDebugHandler}
*/
@NotNull SQLDebugHandler getDebugHandler();
/**
* 设定调试处理器,默认为 {@link SQLDebugHandler#defaultHandler(Logger)} 。
*
* @param debugHandler {@link SQLDebugHandler}
*/
void setDebugHandler(@NotNull SQLDebugHandler debugHandler);
/**
* 得到连接池源
*
@@ -83,7 +110,7 @@ public interface SQLManager {
* @return 更新的行数
* @see SQLUpdateAction
*/
@Nullable Integer executeSQL(String sql);
@Nullable Long executeSQL(String sql);
/**
* 执行一条不需要返回结果的预处理SQL更改(UPDATE、REPLACE、DELETE)
@@ -93,7 +120,7 @@ public interface SQLManager {
* @return 更新的行数
* @see PreparedSQLUpdateAction
*/
@Nullable Integer executeSQL(String sql, Object[] params);
@Nullable Long executeSQL(String sql, Object[] params);
/**
* 执行多条不需要返回结果的SQL更改(UPDATE、REPLACE、DELETE)
@@ -103,7 +130,7 @@ public interface SQLManager {
* @return 对应参数返回的行数
* @see PreparedSQLUpdateBatchAction
*/
@Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
@Nullable List<Long> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
/**
@@ -25,11 +25,11 @@ public abstract class SQLTable {
public static @NotNull SQLTable of(@NotNull String tableName, @Nullable SQLHandler<TableCreateBuilder> table) {
return new SQLTable(tableName) {
@Override
public int create(SQLManager sqlManager) throws SQLException {
public boolean create(SQLManager sqlManager) throws SQLException {
if (this.manager == null) this.manager = sqlManager;
TableCreateBuilder tableBuilder = sqlManager.createTable(getTableName());
if (table != null) table.accept(tableBuilder);
return tableBuilder.build().execute();
return tableBuilder.build().executeFunction(l -> l > 0, false);
}
};
}
@@ -63,7 +63,14 @@ public abstract class SQLTable {
return tableName;
}
public abstract int create(SQLManager sqlManager) throws SQLException;
/**
* 使用指定 SQLManager 进行本示例的初始化。
*
* @param sqlManager {@link SQLManager}
* @return 本表是否为首次创建
* @throws SQLException 出现任何错误时抛出
*/
public abstract boolean create(SQLManager sqlManager) throws SQLException;
public @NotNull TableQueryBuilder createQuery(@NotNull SQLManager sqlManager) {
return sqlManager.createQuery().inTable(getTableName());
@@ -4,7 +4,7 @@ import cc.carm.lib.easysql.api.SQLAction;
import java.util.List;
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Integer>> {
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Long>> {
/**
* 设定多组SQL语句中所有 ? 对应的参数
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.api.action;
import cc.carm.lib.easysql.api.SQLAction;
public interface SQLUpdateAction extends SQLAction<Integer> {
public interface SQLUpdateAction extends SQLAction<Long> {
/**
* 设定自增主键的序列
@@ -21,6 +21,7 @@ public interface SQLUpdateBatchAction extends SQLAction<List<Integer>> {
return getSQLContents().get(0);
}
List<String> getSQLContents();
@Override
@NotNull List<String> getSQLContents();
}
@@ -47,9 +47,7 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
B addCondition(@NotNull String columnName, @NotNull String operator, @Nullable Object queryValue);
default B addCondition(@NotNull String columnName, @Nullable Object queryValue) {
return addCondition(columnName, "=", queryValue);
}
B addCondition(@NotNull String columnName, @Nullable Object queryValue);
B addCondition(@NotNull String[] columnNames, @Nullable Object[] queryValues);
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.api.builder;
import cc.carm.lib.easysql.api.SQLAction;
public interface DeleteBuilder extends ConditionalBuilder<DeleteBuilder, SQLAction<Integer>> {
public interface DeleteBuilder extends ConditionalBuilder<DeleteBuilder, SQLAction<Long>> {
String getTableName();
@@ -10,13 +10,13 @@ import org.jetbrains.annotations.Nullable;
public interface TableAlterBuilder extends SQLBuilder {
SQLAction<Integer> renameTo(@NotNull String newTableName);
SQLAction<Long> renameTo(@NotNull String newTableName);
SQLAction<Integer> changeComment(@NotNull String newTableComment);
SQLAction<Long> changeComment(@NotNull String newTableComment);
SQLAction<Integer> setAutoIncrementIndex(int index);
SQLAction<Long> setAutoIncrementIndex(int index);
SQLAction<Integer> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
SQLAction<Long> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
@NotNull String columnName, @NotNull String... moreColumns);
/**
@@ -25,7 +25,7 @@ public interface TableAlterBuilder extends SQLBuilder {
* @param indexName 索引名
* @return {@link SQLUpdateAction}
*/
SQLAction<Integer> dropIndex(@NotNull String indexName);
SQLAction<Long> dropIndex(@NotNull String indexName);
/**
* 为该表移除一个外键
@@ -33,14 +33,14 @@ public interface TableAlterBuilder extends SQLBuilder {
* @param keySymbol 外键名
* @return {@link SQLUpdateAction}
*/
SQLAction<Integer> dropForeignKey(@NotNull String keySymbol);
SQLAction<Long> dropForeignKey(@NotNull String keySymbol);
/**
* 为该表移除主键(须添加新主键)
*
* @return {@link SQLUpdateAction}
*/
SQLAction<Integer> dropPrimaryKey();
SQLAction<Long> dropPrimaryKey();
/**
* 为表添加一列
@@ -49,7 +49,7 @@ public interface TableAlterBuilder extends SQLBuilder {
* @param settings 列的相关设定
* @return {@link SQLUpdateAction}
*/
default SQLAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings) {
default SQLAction<Long> addColumn(@NotNull String columnName, @NotNull String settings) {
return addColumn(columnName, settings, null);
}
@@ -63,21 +63,21 @@ public interface TableAlterBuilder extends SQLBuilder {
* <p> 若为 "" 则置于首行。
* @return {@link SQLUpdateAction}
*/
SQLAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn);
SQLAction<Long> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn);
SQLAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName);
SQLAction<Long> renameColumn(@NotNull String columnName, @NotNull String newName);
SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings);
SQLAction<Long> modifyColumn(@NotNull String columnName, @NotNull String settings);
default SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String columnSettings, @NotNull String afterColumn) {
default SQLAction<Long> modifyColumn(@NotNull String columnName, @NotNull String columnSettings, @NotNull String afterColumn) {
return modifyColumn(columnName, columnSettings + " AFTER `" + afterColumn + "`");
}
SQLAction<Integer> removeColumn(@NotNull String columnName);
SQLAction<Long> removeColumn(@NotNull String columnName);
SQLAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue);
SQLAction<Long> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue);
SQLAction<Integer> removeColumnDefault(@NotNull String columnName);
SQLAction<Long> removeColumnDefault(@NotNull String columnName);
/**
* 为该表添加一个自增列
@@ -90,7 +90,7 @@ public interface TableAlterBuilder extends SQLBuilder {
* @param unsigned 是否采用 UNSIGNED (即无负数,可以增加自增键的最高数,建议为true)
* @return {@link TableCreateBuilder}
*/
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
default SQLAction<Long> addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
boolean primary, boolean unsigned) {
return addColumn(columnName,
(numberType == null ? NumberType.INT : numberType).name()
@@ -109,7 +109,7 @@ public interface TableAlterBuilder extends SQLBuilder {
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
* @return {@link TableAlterBuilder}
*/
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName, @NotNull NumberType numberType) {
default SQLAction<Long> addAutoIncrementColumn(@NotNull String columnName, @NotNull NumberType numberType) {
return addAutoIncrementColumn(columnName, numberType, false, true);
}
@@ -122,7 +122,7 @@ public interface TableAlterBuilder extends SQLBuilder {
* @param columnName 列名
* @return {@link TableAlterBuilder}
*/
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName) {
default SQLAction<Long> addAutoIncrementColumn(@NotNull String columnName) {
return addAutoIncrementColumn(columnName, NumberType.INT);
}
@@ -6,7 +6,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.LinkedHashMap;
public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLAction<Integer>> {
public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLAction<Long>> {
String getTableName();
@@ -0,0 +1,93 @@
package cc.carm.lib.easysql.api.function;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
/**
* 异常处理器。
* <br> 在使用 {@link SQLAction#execute(SQLExceptionHandler)} 等相关方法时,
* 如果发生异常,则会调用错误处理器进行错误内容的输出提示。
*/
public interface SQLDebugHandler {
/**
* 该方法将在 {@link SQLAction#execute()} 执行前调用。
*
* @param action {@link SQLAction} 对象
* @param params 执行传入的参数列表。
* 实际上,仅有 {@link PreparedSQLUpdateAction} 和 {@link PreparedSQLUpdateBatchAction} 才会有传入参数。
*/
void beforeExecute(@NotNull SQLAction<?> action, @NotNull List<@Nullable Object[]> params);
/**
* 该方法将在 {@link SQLQuery#close()} 执行后调用。
*
* @param query {@link SQLQuery} 对象
* @param executeTime 该次查询开始执行的时间
* @param closeTime 该次查询彻底关闭的时间
*/
void afterQuery(@NotNull SQLQuery query, long executeTime, long closeTime);
default String parseParams(@Nullable Object[] params) {
if (params == null) return "<#NULL>";
else if (params.length == 0) return "<#EMPTY>";
List<String> paramsString = new ArrayList<>();
for (Object param : params) {
if (param == null) paramsString.add("NULL");
else paramsString.add(param.toString());
}
return String.join(", ", paramsString);
}
@SuppressWarnings("DuplicatedCode")
static SQLDebugHandler defaultHandler(Logger logger) {
return new SQLDebugHandler() {
@Override
public void beforeExecute(@NotNull SQLAction<?> action, @NotNull List<@Nullable Object[]> params) {
logger.info("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
logger.info("┣# ActionUUID: {}", action.getActionUUID());
logger.info("┣# ActionType: {}", action.getClass().getName());
if (action.getSQLContents().size() == 1) {
logger.info("┣# SQLContent: {}", action.getSQLContents().get(0));
} else {
logger.info("┣# SQLContents: ");
int i = 0;
for (String sqlContent : action.getSQLContents()) {
logger.info("┃ [{}] {}", ++i, sqlContent);
}
}
if (params.size() == 1) {
Object[] param = params.get(0);
logger.info("┣# SQLParams: {}", parseParams(param));
} else if (params.size() > 1) {
logger.info("┣# SQLParams: ");
int i = 0;
for (Object[] param : params) {
logger.info("┃ [{}] {}", ++i, parseParams(param));
}
}
logger.info("┣# createTime: {}", action.getCreateTime());
logger.info("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
}
@Override
public void afterQuery(@NotNull SQLQuery query, long executeTime, long closeTime) {
logger.info("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
logger.info("┣# ActionUUID: {}", query.getAction().getActionUUID());
logger.info("┣# SQLContent: {}", query.getSQLContent());
logger.info("┣# executeCost: {} ms", (closeTime - executeTime));
logger.info("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
}
};
}
}
@@ -1,11 +1,10 @@
package cc.carm.lib.easysql.api.function;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
import org.slf4j.Logger;
import java.sql.SQLException;
import java.util.function.BiConsumer;
import java.util.logging.Logger;
/**
* 异常处理器。
@@ -23,15 +22,11 @@ public interface SQLExceptionHandler extends BiConsumer<SQLException, SQLAction<
*/
static SQLExceptionHandler detailed(Logger logger) {
return (exception, sqlAction) -> {
if (sqlAction instanceof SQLUpdateBatchAction) {
logger.severe("Error when execute SQLs : ");
int i = 1;
for (String content : ((SQLUpdateBatchAction) sqlAction).getSQLContents()) {
logger.severe(String.format("#%d {%s}", i, content));
i++;
}
} else {
logger.severe("Error when execute { " + sqlAction.getSQLContent() + " }");
logger.error("Error occurred while executing SQL: ");
int i = 1;
for (String content : sqlAction.getSQLContents()) {
logger.error(String.format("#%d {%s}", i, content));
i++;
}
exception.printStackTrace();
};
+29 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.10</version>
<version>0.3.16</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -17,6 +17,8 @@
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.deploy.skip>true</maven.deploy.skip>
<log4j.version>2.17.2</log4j.version>
</properties>
<artifactId>easysql-demo</artifactId>
@@ -76,10 +78,31 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.210</version>
<version>2.1.212</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
@@ -92,6 +115,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
+4 -5
View File
@@ -56,7 +56,7 @@ public class EasySQLDemo {
"users", "id",
ForeignKeyRule.CASCADE, ForeignKeyRule.CASCADE
);
});
try {
@@ -134,7 +134,7 @@ public class EasySQLDemo {
public void sqlInsert(SQLManager sqlManager) {
// 同步SQL插入 (不使用try-catch的情况下,返回的数值可能为空。)
Integer id = sqlManager.createInsert("users")
Long id = sqlManager.createInsert("users")
.setColumnNames("username", "phone", "email", "registerTime")
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
.setReturnGeneratedKey(true)// 设定在后续返回自增主键
@@ -145,11 +145,10 @@ public class EasySQLDemo {
});
try {
Integer userID = sqlManager.createInsert("users")
Long userID = sqlManager.createInsert("users")
.setColumnNames("username", "phone", "email", "registerTime")
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
.setReturnGeneratedKey(true)
.execute();
.returnGeneratedKey().execute();
System.out.println("新用户的ID为 " + userID);
@@ -22,6 +22,7 @@ public class EasySQLTest {
config.setJdbcUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=MYSQL;");
SQLManager sqlManager = new SQLManagerImpl(new HikariDataSource(config), "test");
sqlManager.setDebugMode(true);
print("加载测试类...");
Set<TestHandler> tests = new LinkedHashSet<>();
@@ -1,7 +1,7 @@
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.TestHandler;
import cc.carm.lib.easysql.api.SQLManager;
import java.sql.SQLException;
@@ -11,12 +11,11 @@ public class DeleteTest extends TestHandler {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
Integer changes = sqlManager.createDelete("test_user_table")
System.out.println("change(s): " + sqlManager.createDelete("test_user_table")
.addCondition("id", ">", 5)
.addNotNullCondition("username")
.build().execute();
System.out.println("change(s): " + changes);
.build().execute());
}
}
@@ -25,7 +25,7 @@ public class SQLUpdateBatchTests extends TestHandler {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
List<Integer> updates = sqlManager.createInsertBatch("test_user_table")
List<Long> updates = sqlManager.createInsertBatch("test_user_table")
.setColumnNames("uuid", "username", "age")
.setAllParams(generateParams())
.execute();
@@ -11,7 +11,7 @@ public class SQLUpdateReturnKeysTest extends SQLUpdateBatchTests {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
List<Integer> generatedKeys = sqlManager.createInsertBatch("test_user_table")
List<Long> generatedKeys = sqlManager.createInsertBatch("test_user_table")
.setColumnNames("uuid", "username", "age")
.setAllParams(generateParams())
.returnGeneratedKeys()
+1 -5
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.10</version>
<version>0.3.16</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -81,10 +81,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>
@@ -7,6 +7,7 @@ import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@@ -66,8 +67,14 @@ public abstract class AbstractSQLAction<T> implements SQLAction<T> {
return this.sqlManager;
}
protected void outputDebugMessage() {
getManager().debug("# " + getShortID() + " -> { " + getSQLContent() + " }");
protected void debugMessage(List<Object[]> params) {
if (getManager().isDebugMode()) {
try {
getManager().getDebugHandler().beforeExecute(this, params);
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
@Override
@@ -15,11 +15,11 @@ import java.util.List;
import java.util.stream.Collectors;
public class PreparedSQLBatchUpdateActionImpl
extends AbstractSQLAction<List<Integer>>
extends AbstractSQLAction<List<Long>>
implements PreparedSQLUpdateBatchAction {
boolean returnKeys = false;
List<Object[]> allParams;
@NotNull List<Object[]> allParams;
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
super(manager, sql);
@@ -47,21 +47,23 @@ public class PreparedSQLBatchUpdateActionImpl
}
@Override
public @NotNull List<Integer> execute() throws SQLException {
public @NotNull List<Long> execute() throws SQLException {
debugMessage(allParams);
try (Connection connection = getManager().getConnection()) {
try (PreparedStatement statement = StatementUtil.createPrepareStatementBatch(
connection, getSQLContent(), allParams, returnKeys
)) {
outputDebugMessage();
int[] executed = statement.executeBatch();
if (!returnKeys) return Arrays.stream(executed).boxed().collect(Collectors.toList());
else {
if (!returnKeys) {
return Arrays.stream(executed).mapToLong(Long::valueOf).boxed().collect(Collectors.toList());
} else {
try (ResultSet resultSet = statement.getGeneratedKeys()) {
List<Integer> generatedKeys = new ArrayList<>();
List<Long> generatedKeys = new ArrayList<>();
while (resultSet.next()) {
generatedKeys.add(resultSet.getInt(1));
generatedKeys.add(resultSet.getLong(1));
}
return generatedKeys;
}
@@ -11,6 +11,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class PreparedSQLUpdateActionImpl
@@ -52,20 +53,20 @@ public class PreparedSQLUpdateActionImpl
}
@Override
public @NotNull Integer execute() throws SQLException {
public @NotNull Long execute() throws SQLException {
debugMessage(Collections.singletonList(params));
try (Connection connection = getManager().getConnection()) {
try (PreparedStatement statement = StatementUtil.createPrepareStatement(
connection, getSQLContent(), params, returnGeneratedKeys
)) {
outputDebugMessage();
int changes = statement.executeUpdate();
if (!returnGeneratedKeys) return changes;
if (!returnGeneratedKeys) return (long) changes;
else {
try (ResultSet resultSet = statement.getGeneratedKeys()) {
return resultSet.next() ? resultSet.getInt(1) : -1;
return resultSet.next() ? resultSet.getLong(1) : -1;
}
}
@@ -8,9 +8,10 @@ import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class SQLUpdateActionImpl
extends AbstractSQLAction<Integer>
extends AbstractSQLAction<Long>
implements SQLUpdateAction {
boolean returnGeneratedKeys = false;
@@ -20,18 +21,19 @@ public class SQLUpdateActionImpl
}
@Override
public @NotNull Integer execute() throws SQLException {
public @NotNull Long execute() throws SQLException {
debugMessage(new ArrayList<>());
try (Connection connection = getManager().getConnection()) {
try (Statement statement = connection.createStatement()) {
outputDebugMessage();
if (!returnGeneratedKeys) {
return statement.executeUpdate(getSQLContent());
return (long) statement.executeUpdate(getSQLContent());
} else {
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
try (ResultSet resultSet = statement.getGeneratedKeys()) {
return resultSet.next() ? resultSet.getInt(1) : -1;
return resultSet.next() ? resultSet.getLong(1) : -1;
}
}
}
@@ -38,10 +38,11 @@ public class SQLUpdateBatchActionImpl
@Override
public @NotNull List<Integer> execute() throws SQLException {
debugMessage(new ArrayList<>());
try (Connection connection = getManager().getConnection()) {
try (Statement statement = connection.createStatement()) {
outputDebugMessage();
for (String content : this.sqlContents) {
statement.addBatch(content);
@@ -55,12 +56,4 @@ public class SQLUpdateBatchActionImpl
}
}
@Override
protected void outputDebugMessage() {
getManager().debug("# " + getShortID() + " -> [");
for (String content : getSQLContents()) getManager().debug(String.format(" { %s }", content));
getManager().debug("]");
}
}
@@ -11,6 +11,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
@@ -49,8 +50,8 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
@Override
public @NotNull SQLQueryImpl execute() throws SQLException {
outputDebugMessage();
debugMessage(Collections.singletonList(params));
Connection connection = getManager().getConnection();
PreparedStatement preparedStatement;
try {
@@ -74,7 +75,6 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
executeTime
);
getManager().getActiveQuery().put(getActionUUID(), query);
return query;
} catch (SQLException exception) {
preparedStatement.close();
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements QueryAction {
@@ -21,6 +22,7 @@ public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements Quer
@Override
public @NotNull SQLQueryImpl execute() throws SQLException {
debugMessage(new ArrayList<>());
Connection connection = getManager().getConnection();
Statement statement;
@@ -32,7 +34,6 @@ public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements Quer
throw ex;
}
outputDebugMessage();
try {
long executeTime = System.currentTimeMillis();
SQLQueryImpl query = new SQLQueryImpl(
@@ -48,6 +48,16 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
return getThis();
}
@Override
public B addCondition(@NotNull String columnName, @Nullable Object queryValue) {
Objects.requireNonNull(columnName, "columnName could not be null");
if (queryValue == null) {
return addCondition(withBackQuote(columnName) + " IS NULL");
} else {
return addCondition(columnName, "=", queryValue);
}
}
@Override
public B addCondition(
@NotNull String columnName, @NotNull String operator, @Nullable Object queryValue
@@ -12,7 +12,7 @@ import java.util.Objects;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
public class DeleteBuilderImpl
extends AbstractConditionalBuilder<DeleteBuilder, SQLAction<Integer>>
extends AbstractConditionalBuilder<DeleteBuilder, SQLAction<Long>>
implements DeleteBuilder {
protected final String tableName;
@@ -10,6 +10,8 @@ import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
public class QueryBuilderImpl extends AbstractSQLBuilder implements QueryBuilder {
@@ -28,7 +28,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> renameTo(@NotNull String newTableName) {
public SQLAction<Long> renameTo(@NotNull String newTableName) {
Objects.requireNonNull(newTableName, "table name could not be null");
return new SQLUpdateActionImpl(getManager(),
"ALTER TABLE " + withBackQuote(tableName) + " RENAME TO " + withBackQuote(newTableName)
@@ -36,7 +36,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> changeComment(@NotNull String newTableComment) {
public SQLAction<Long> changeComment(@NotNull String newTableComment) {
Objects.requireNonNull(newTableComment, "table comment could not be null");
return new SQLUpdateActionImpl(getManager(),
"ALTER TABLE " + withBackQuote(getTableName()) + " COMMENT " + withQuote(newTableComment)
@@ -44,15 +44,15 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> setAutoIncrementIndex(int index) {
public SQLAction<Long> setAutoIncrementIndex(int index) {
return new SQLUpdateActionImpl(getManager(),
"ALTER TABLE " + withBackQuote(getTableName()) + " AUTO_INCREMENT=" + index
);
}
@Override
public SQLAction<Integer> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
@NotNull String columnName, @NotNull String... moreColumns) {
public SQLAction<Long> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
@NotNull String columnName, @NotNull String... moreColumns) {
Objects.requireNonNull(indexType, "indexType could not be null");
Objects.requireNonNull(columnName, "column names could not be null");
Objects.requireNonNull(moreColumns, "column names could not be null");
@@ -63,7 +63,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> dropIndex(@NotNull String indexName) {
public SQLAction<Long> dropIndex(@NotNull String indexName) {
Objects.requireNonNull(indexName, "indexName could not be null");
return createAction(
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP INDEX " + withBackQuote(indexName)
@@ -71,7 +71,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> dropForeignKey(@NotNull String keySymbol) {
public SQLAction<Long> dropForeignKey(@NotNull String keySymbol) {
Objects.requireNonNull(keySymbol, "keySymbol could not be null");
return createAction(
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP FOREIGN KEY " + withBackQuote(keySymbol)
@@ -79,14 +79,14 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> dropPrimaryKey() {
public SQLAction<Long> dropPrimaryKey() {
return createAction(
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP PRIMARY KEY"
);
}
@Override
public SQLAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn) {
public SQLAction<Long> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn) {
Objects.requireNonNull(columnName, "columnName could not be null");
Objects.requireNonNull(settings, "settings could not be null");
String orderSettings = null;
@@ -105,7 +105,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName) {
public SQLAction<Long> renameColumn(@NotNull String columnName, @NotNull String newName) {
Objects.requireNonNull(columnName, "columnName could not be null");
Objects.requireNonNull(newName, "please specify new column name");
return createAction(
@@ -114,7 +114,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings) {
public SQLAction<Long> modifyColumn(@NotNull String columnName, @NotNull String settings) {
Objects.requireNonNull(columnName, "columnName could not be null");
Objects.requireNonNull(settings, "please specify new column settings");
return createAction(
@@ -123,7 +123,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> removeColumn(@NotNull String columnName) {
public SQLAction<Long> removeColumn(@NotNull String columnName) {
Objects.requireNonNull(columnName, "columnName could not be null");
return createAction(
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP " + withBackQuote(columnName)
@@ -131,7 +131,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue) {
public SQLAction<Long> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue) {
Objects.requireNonNull(columnName, "columnName could not be null");
Objects.requireNonNull(defaultValue, "defaultValue could not be null, if you need to remove the default value, please use #removeColumnDefault().");
return createAction(
@@ -140,7 +140,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
}
@Override
public SQLAction<Integer> removeColumnDefault(@NotNull String columnName) {
public SQLAction<Long> removeColumnDefault(@NotNull String columnName) {
Objects.requireNonNull(columnName, "columnName could not be null");
return createAction(
"ALTER TABLE " + withBackQuote(getTableName()) + " ALTER " + withBackQuote(columnName) + " DROP DEFAULT"
@@ -13,7 +13,7 @@ import java.util.*;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
public class UpdateBuilderImpl
extends AbstractConditionalBuilder<UpdateBuilder, SQLAction<Integer>>
extends AbstractConditionalBuilder<UpdateBuilder, SQLAction<Long>>
implements UpdateBuilder {
protected final @NotNull String tableName;
@@ -10,10 +10,13 @@ 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.builder.*;
import cc.carm.lib.easysql.api.function.SQLDebugHandler;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import cc.carm.lib.easysql.builder.impl.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -23,7 +26,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Supplier;
import java.util.logging.Logger;
public class SQLManagerImpl implements SQLManager {
@@ -34,14 +36,19 @@ public class SQLManagerImpl implements SQLManager {
@NotNull Supplier<Boolean> debugMode = () -> Boolean.FALSE;
@NotNull SQLExceptionHandler exceptionHandler;
@NotNull SQLDebugHandler debugHandler;
public SQLManagerImpl(@NotNull DataSource dataSource) {
this(dataSource, null);
}
public SQLManagerImpl(@NotNull DataSource dataSource, @Nullable String name) {
this(dataSource, LoggerFactory.getLogger(SQLManagerImpl.class), name);
}
public SQLManagerImpl(@NotNull DataSource dataSource, @NotNull Logger logger, @Nullable String name) {
String managerName = "SQLManager" + (name != null ? "#" + name : "");
this.LOGGER = Logger.getLogger(managerName);
this.LOGGER = logger;
this.dataSource = dataSource;
this.executorPool = Executors.newFixedThreadPool(3, r -> {
Thread thread = new Thread(r, managerName);
@@ -50,6 +57,7 @@ public class SQLManagerImpl implements SQLManager {
});
this.exceptionHandler = SQLExceptionHandler.detailed(getLogger());
this.debugHandler = SQLDebugHandler.defaultHandler(getLogger());
}
@Override
@@ -62,6 +70,16 @@ public class SQLManagerImpl implements SQLManager {
this.debugMode = debugMode;
}
@Override
public @NotNull SQLDebugHandler getDebugHandler() {
return this.debugHandler;
}
@Override
public void setDebugHandler(@NotNull SQLDebugHandler debugHandler) {
this.debugHandler = debugHandler;
}
public void debug(String msg) {
if (isDebugMode()) getLogger().info("[DEBUG] " + msg);
}
@@ -102,17 +120,17 @@ public class SQLManagerImpl implements SQLManager {
}
@Override
public Integer executeSQL(String sql) {
public Long executeSQL(String sql) {
return new SQLUpdateActionImpl(this, sql).execute(null);
}
@Override
public Integer executeSQL(String sql, Object[] params) {
public Long executeSQL(String sql, Object[] params) {
return new PreparedSQLUpdateActionImpl(this, sql, params).execute(null);
}
@Override
public List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
public List<Long> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
return new PreparedSQLBatchUpdateActionImpl(this, sql)
.setAllParams(paramsBatch)
.execute(null);
@@ -71,9 +71,13 @@ public class SQLQueryImpl implements SQLQuery {
if (getStatement() != null && !getStatement().isClosed()) getStatement().close();
if (getConnection() != null && !getConnection().isClosed()) getConnection().close();
getManager().debug("#" + getAction().getShortID() +
" -> finished after " + (System.currentTimeMillis() - getExecuteTime()) + " ms."
);
if (getManager().isDebugMode()) {
try {
getManager().getDebugHandler().afterQuery(this, getExecuteTime(), System.currentTimeMillis());
} catch (Exception ex) {
ex.printStackTrace();
}
}
getManager().getActiveQuery().remove(getAction().getActionUUID());
} catch (SQLException e) {
getAction().handleException(getAction().defaultExceptionHandler(), e);
+2 -2
View File
@@ -17,7 +17,7 @@
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<packaging>pom</packaging>
<version>0.3.10</version>
<version>0.3.16</version>
<modules>
<module>api</module>
@@ -169,7 +169,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
<configuration>
<classifier>javadoc</classifier>
<detectJavaApiLink>false</detectJavaApiLink>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.10</version>
<version>0.3.16</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -24,11 +24,11 @@ public class EasySQL {
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");
manager.getLogger().warn("There are " + manager.getActiveQuery().size() + " connections still running");
for (SQLQuery value : manager.getActiveQuery().values()) {
if (outputActiveQuery) {
manager.getLogger().severe(String.format("#%s -> %s", value.getAction().getShortID(), value.getSQLContent()));
manager.getLogger().severe(String.format("- execute at %s", TimeDateUtils.getTimeString(value.getExecuteTime())));
manager.getLogger().warn(String.format("#%s -> %s", value.getAction().getShortID(), value.getSQLContent()));
manager.getLogger().warn(String.format("- execute at %s", TimeDateUtils.getTimeString(value.getExecuteTime())));
}
if (forceClose) value.close();
}
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.10</version>
<version>0.3.16</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -34,11 +34,11 @@ public class EasySQL {
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");
manager.getLogger().warn("There are " + manager.getActiveQuery().size() + " connections still running");
for (SQLQuery value : manager.getActiveQuery().values()) {
if (outputActiveQuery) {
manager.getLogger().severe(String.format("#%s -> %s", value.getAction().getShortID(), value.getSQLContent()));
manager.getLogger().severe(String.format("- execute at %s", TimeDateUtils.getTimeString(value.getExecuteTime())));
manager.getLogger().warn(String.format("#%s -> %s", value.getAction().getShortID(), value.getSQLContent()));
manager.getLogger().warn(String.format("- execute at %s", TimeDateUtils.getTimeString(value.getExecuteTime())));
}
if (forceClose) value.close();
}