mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-14 03:15:55 +08:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 03e157d3d9 | |||
| a2d972621d | |||
| 903f3a5f93 | |||
| 44f9392e81 | |||
| 1ad196f04b | |||
| fd0a4e48ef | |||
| 14ee6ca1f2 | |||
| 6ba58b540f | |||
| db33e5e830 | |||
| 3fbc58acf7 | |||
| 0a6c8ae1a9 | |||
| f00e741035 | |||
| 50c2016820 | |||
| 71b0bb98d8 | |||
| ce3deb8f12 | |||
| b5a40b0f52 | |||
| ae5ca6cb23 | |||
| 866115db99 | |||
| 332540710d | |||
| ebe51dd9a3 | |||
| 0bdfe3d556 | |||
| e60c44aaae | |||
| 28f76ae50a | |||
| ffa0b74ccc | |||
| 4b766d7794 | |||
| f12fdc9c66 | |||
| 6115e6bf21 | |||
| 6356c0f723 | |||
| 5e15c3b308 | |||
| 46b21ead05 | |||
| 8a9e4b8d1c |
@@ -40,7 +40,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
rm -rf docs
|
rm -rf docs
|
||||||
mkdir -vp docs
|
mkdir -vp docs
|
||||||
cp -vrf easysql-api/target/apidocs/* docs/
|
cp -vrf api/target/apidocs/* docs/
|
||||||
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
||||||
|
|
||||||
- name: "Generate the Javadoc sitemap"
|
- name: "Generate the Javadoc sitemap"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ name: Project Build & Tests
|
|||||||
on:
|
on:
|
||||||
# 支持手动触发构建
|
# 支持手动触发构建
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
push:
|
push:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
+1
-2
@@ -1,4 +1,3 @@
|
|||||||
/.idea/
|
/.idea/
|
||||||
/target/
|
**/target/
|
||||||
/*/target/
|
|
||||||
**.iml
|
**.iml
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<version>0.3.8</version>
|
<version>0.3.11</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
+6
-6
@@ -3,7 +3,6 @@ package cc.carm.lib.easysql.api;
|
|||||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||||
import cc.carm.lib.easysql.api.function.SQLFunction;
|
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||||
import cc.carm.lib.easysql.api.function.SQLHandler;
|
import cc.carm.lib.easysql.api.function.SQLHandler;
|
||||||
import cc.carm.lib.easysql.api.function.defaults.DefaultSQLExceptionHandler;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -189,13 +188,14 @@ public interface SQLAction<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认的异常处理器
|
* 获取管理器提供的默认异常处理器。
|
||||||
|
* 若未使用过 {@link #setExceptionHandler(SQLExceptionHandler)} 方法,
|
||||||
|
* 则默认返回 {@link SQLExceptionHandler#detailed(Logger)} 。
|
||||||
*
|
*
|
||||||
* @return {@link DefaultSQLExceptionHandler#get(Logger)}
|
* @return {@link SQLExceptionHandler}
|
||||||
* @see DefaultSQLExceptionHandler
|
|
||||||
*/
|
*/
|
||||||
default SQLExceptionHandler defaultExceptionHandler() {
|
default SQLExceptionHandler defaultExceptionHandler() {
|
||||||
return DefaultSQLExceptionHandler.get(getManager().getLogger());
|
return getManager().getExceptionHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,7 +206,7 @@ public interface SQLAction<T> {
|
|||||||
* @param handler 异常处理器
|
* @param handler 异常处理器
|
||||||
*/
|
*/
|
||||||
default void setExceptionHandler(@Nullable SQLExceptionHandler handler) {
|
default void setExceptionHandler(@Nullable SQLExceptionHandler handler) {
|
||||||
DefaultSQLExceptionHandler.setCustomHandler(handler);
|
getManager().setExceptionHandler(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+22
-3
@@ -5,6 +5,7 @@ import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
|
|||||||
import cc.carm.lib.easysql.api.action.SQLUpdateAction;
|
import cc.carm.lib.easysql.api.action.SQLUpdateAction;
|
||||||
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
||||||
import cc.carm.lib.easysql.api.builder.*;
|
import cc.carm.lib.easysql.api.builder.*;
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -56,6 +57,24 @@ public interface SQLManager {
|
|||||||
*/
|
*/
|
||||||
@NotNull Map<UUID, SQLQuery> getActiveQuery();
|
@NotNull Map<UUID, SQLQuery> getActiveQuery();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取改管理器提供的默认异常处理器。
|
||||||
|
* 若未使用过 {@link #setExceptionHandler(SQLExceptionHandler)} 方法,
|
||||||
|
* 则默认返回 {@link SQLExceptionHandler#detailed(Logger)} 。
|
||||||
|
*
|
||||||
|
* @return {@link SQLExceptionHandler}
|
||||||
|
*/
|
||||||
|
@NotNull SQLExceptionHandler getExceptionHandler();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设定通用的异常处理器。
|
||||||
|
* <br> 在使用 {@link SQLAction#execute(SQLExceptionHandler)} 等相关方法时,若传入的处理器为null,则会采用此处理器。
|
||||||
|
* <br> 若该方法传入参数为 null,则会使用 {@link SQLExceptionHandler#detailed(Logger)} 。
|
||||||
|
*
|
||||||
|
* @param handler 异常处理器
|
||||||
|
*/
|
||||||
|
void setExceptionHandler(@Nullable SQLExceptionHandler handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行一条不需要返回结果的SQL语句(多用于UPDATE、REPLACE、DELETE方法)
|
* 执行一条不需要返回结果的SQL语句(多用于UPDATE、REPLACE、DELETE方法)
|
||||||
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||||
@@ -64,7 +83,7 @@ public interface SQLManager {
|
|||||||
* @return 更新的行数
|
* @return 更新的行数
|
||||||
* @see SQLUpdateAction
|
* @see SQLUpdateAction
|
||||||
*/
|
*/
|
||||||
@Nullable Integer executeSQL(String sql);
|
@Nullable Long executeSQL(String sql);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行一条不需要返回结果的预处理SQL更改(UPDATE、REPLACE、DELETE)
|
* 执行一条不需要返回结果的预处理SQL更改(UPDATE、REPLACE、DELETE)
|
||||||
@@ -74,7 +93,7 @@ public interface SQLManager {
|
|||||||
* @return 更新的行数
|
* @return 更新的行数
|
||||||
* @see PreparedSQLUpdateAction
|
* @see PreparedSQLUpdateAction
|
||||||
*/
|
*/
|
||||||
@Nullable Integer executeSQL(String sql, Object[] params);
|
@Nullable Long executeSQL(String sql, Object[] params);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行多条不需要返回结果的SQL更改(UPDATE、REPLACE、DELETE)
|
* 执行多条不需要返回结果的SQL更改(UPDATE、REPLACE、DELETE)
|
||||||
@@ -84,7 +103,7 @@ public interface SQLManager {
|
|||||||
* @return 对应参数返回的行数
|
* @return 对应参数返回的行数
|
||||||
* @see PreparedSQLUpdateBatchAction
|
* @see PreparedSQLUpdateBatchAction
|
||||||
*/
|
*/
|
||||||
@Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
|
@Nullable List<Long> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package cc.carm.lib.easysql.api;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
|
||||||
|
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
|
||||||
|
import cc.carm.lib.easysql.api.builder.*;
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLHandler;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQLTable 基于 {@link TableCreateBuilder} 构建表,用于快速创建与该表相关的操作。
|
||||||
|
* <ul>
|
||||||
|
* <li>1. 调用 {@link SQLTable#of(String, String[])} 方法创建一个 SQLTable 对象;</li>
|
||||||
|
* <li>2. 在应用初始化阶段调用 {@link SQLTable#create(SQLManager)} 方法初始化 SQLTable 对象;</li>
|
||||||
|
* <li>3. 获取已创建的{@link SQLTable} 实例,直接调用对应方法进行关于表的相关操作。</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @author CarmJos
|
||||||
|
* @since 0.3.10
|
||||||
|
*/
|
||||||
|
public abstract class SQLTable {
|
||||||
|
|
||||||
|
public static @NotNull SQLTable of(@NotNull String tableName, @Nullable SQLHandler<TableCreateBuilder> table) {
|
||||||
|
return new SQLTable(tableName) {
|
||||||
|
@Override
|
||||||
|
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().executeFunction(l -> l > 0, false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull SQLTable of(@NotNull String tableName, @NotNull String[] columns) {
|
||||||
|
return of(tableName, columns, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull SQLTable of(@NotNull String tableName,
|
||||||
|
@NotNull String[] columns, @Nullable String tableSettings) {
|
||||||
|
return of(tableName, builder -> {
|
||||||
|
builder.setColumns(columns);
|
||||||
|
if (tableSettings != null) builder.setTableSettings(tableSettings);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private final @NotNull String tableName;
|
||||||
|
|
||||||
|
protected SQLManager manager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请调用 {@link SQLTable} 下的静态方法进行对象的初始化。
|
||||||
|
*
|
||||||
|
* @param tableName 该表的名称
|
||||||
|
*/
|
||||||
|
private SQLTable(@NotNull String tableName) {
|
||||||
|
this.tableName = tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getTableName() {
|
||||||
|
return tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用指定 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull TableQueryBuilder createQuery() {
|
||||||
|
return createQuery(this.manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull DeleteBuilder createDelete() {
|
||||||
|
return createDelete(this.manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull DeleteBuilder createDelete(@NotNull SQLManager sqlManager) {
|
||||||
|
return sqlManager.createDelete(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull UpdateBuilder createUpdate() {
|
||||||
|
return createUpdate(this.manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull UpdateBuilder createUpdate(@NotNull SQLManager sqlManager) {
|
||||||
|
return sqlManager.createUpdate(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @NotNull InsertBuilder<PreparedSQLUpdateAction> createInsert() {
|
||||||
|
return createInsert(this.manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull InsertBuilder<PreparedSQLUpdateAction> createInsert(@NotNull SQLManager sqlManager) {
|
||||||
|
return sqlManager.createInsert(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @NotNull InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch() {
|
||||||
|
return createInsertBatch(this.manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch(@NotNull SQLManager sqlManager) {
|
||||||
|
return sqlManager.createInsertBatch(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @NotNull ReplaceBuilder<PreparedSQLUpdateAction> createReplace() {
|
||||||
|
return createReplace(this.manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ReplaceBuilder<PreparedSQLUpdateAction> createReplace(@NotNull SQLManager sqlManager) {
|
||||||
|
return sqlManager.createReplace(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @NotNull ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch() {
|
||||||
|
return createReplaceBatch(this.manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch(@NotNull SQLManager sqlManager) {
|
||||||
|
return sqlManager.createReplaceBatch(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -4,7 +4,7 @@ import cc.carm.lib.easysql.api.SQLAction;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Integer>> {
|
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Long>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定多组SQL语句中所有 ? 对应的参数
|
* 设定多组SQL语句中所有 ? 对应的参数
|
||||||
+1
-1
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.api.action;
|
|||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
|
|
||||||
public interface SQLUpdateAction extends SQLAction<Integer> {
|
public interface SQLUpdateAction extends SQLAction<Long> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定自增主键的序列
|
* 设定自增主键的序列
|
||||||
-2
@@ -39,8 +39,6 @@ public interface QueryAction extends SQLAction<SQLQuery> {
|
|||||||
try (SQLQuery value = execute()) {
|
try (SQLQuery value = execute()) {
|
||||||
R result = function.apply(value);
|
R result = function.apply(value);
|
||||||
return result == null ? defaultResult : result;
|
return result == null ? defaultResult : result;
|
||||||
} catch (SQLException exception) {
|
|
||||||
throw new SQLException(exception);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+1
-1
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.api.builder;
|
|||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
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();
|
String getTableName();
|
||||||
|
|
||||||
+18
-18
@@ -10,13 +10,13 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public interface TableAlterBuilder extends SQLBuilder {
|
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);
|
@NotNull String columnName, @NotNull String... moreColumns);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +25,7 @@ public interface TableAlterBuilder extends SQLBuilder {
|
|||||||
* @param indexName 索引名
|
* @param indexName 索引名
|
||||||
* @return {@link SQLUpdateAction}
|
* @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 外键名
|
* @param keySymbol 外键名
|
||||||
* @return {@link SQLUpdateAction}
|
* @return {@link SQLUpdateAction}
|
||||||
*/
|
*/
|
||||||
SQLAction<Integer> dropForeignKey(@NotNull String keySymbol);
|
SQLAction<Long> dropForeignKey(@NotNull String keySymbol);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为该表移除主键(须添加新主键)
|
* 为该表移除主键(须添加新主键)
|
||||||
*
|
*
|
||||||
* @return {@link SQLUpdateAction}
|
* @return {@link SQLUpdateAction}
|
||||||
*/
|
*/
|
||||||
SQLAction<Integer> dropPrimaryKey();
|
SQLAction<Long> dropPrimaryKey();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为表添加一列
|
* 为表添加一列
|
||||||
@@ -49,7 +49,7 @@ public interface TableAlterBuilder extends SQLBuilder {
|
|||||||
* @param settings 列的相关设定
|
* @param settings 列的相关设定
|
||||||
* @return {@link SQLUpdateAction}
|
* @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);
|
return addColumn(columnName, settings, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,21 +63,21 @@ public interface TableAlterBuilder extends SQLBuilder {
|
|||||||
* <p> 若为 "" 则置于首行。
|
* <p> 若为 "" 则置于首行。
|
||||||
* @return {@link SQLUpdateAction}
|
* @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 + "`");
|
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)
|
* @param unsigned 是否采用 UNSIGNED (即无负数,可以增加自增键的最高数,建议为true)
|
||||||
* @return {@link TableCreateBuilder}
|
* @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) {
|
boolean primary, boolean unsigned) {
|
||||||
return addColumn(columnName,
|
return addColumn(columnName,
|
||||||
(numberType == null ? NumberType.INT : numberType).name()
|
(numberType == null ? NumberType.INT : numberType).name()
|
||||||
@@ -109,7 +109,7 @@ public interface TableAlterBuilder extends SQLBuilder {
|
|||||||
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
|
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
|
||||||
* @return {@link TableAlterBuilder}
|
* @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);
|
return addAutoIncrementColumn(columnName, numberType, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ public interface TableAlterBuilder extends SQLBuilder {
|
|||||||
* @param columnName 列名
|
* @param columnName 列名
|
||||||
* @return {@link TableAlterBuilder}
|
* @return {@link TableAlterBuilder}
|
||||||
*/
|
*/
|
||||||
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName) {
|
default SQLAction<Long> addAutoIncrementColumn(@NotNull String columnName) {
|
||||||
return addAutoIncrementColumn(columnName, NumberType.INT);
|
return addAutoIncrementColumn(columnName, NumberType.INT);
|
||||||
}
|
}
|
||||||
|
|
||||||
+1
-1
@@ -6,7 +6,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLAction<Integer>> {
|
public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLAction<Long>> {
|
||||||
|
|
||||||
String getTableName();
|
String getTableName();
|
||||||
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cc.carm.lib.easysql.api.function;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
|
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常处理器。
|
||||||
|
* <br> 在使用 {@link SQLAction#execute(SQLExceptionHandler)} 等相关方法时,
|
||||||
|
* 如果发生异常,则会调用错误处理器进行错误内容的输出提示。
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SQLExceptionHandler extends BiConsumer<SQLException, SQLAction<?>> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认的异常处理器,将详细的输出相关错误与错误来源。
|
||||||
|
*
|
||||||
|
* @param logger 用于输出错误信息的Logger。
|
||||||
|
* @return 输出详细信息的错误处理器。
|
||||||
|
*/
|
||||||
|
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() + " }");
|
||||||
|
}
|
||||||
|
exception.printStackTrace();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* “安静“ 的错误处理器,发生错误什么都不做。
|
||||||
|
* 强烈不建议把此处理器作为默认处理器使用!
|
||||||
|
*
|
||||||
|
* @return 无输出的处理器。
|
||||||
|
*/
|
||||||
|
static SQLExceptionHandler silent() {
|
||||||
|
return (exception, sqlAction) -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package cc.carm.lib.easysql.api.util;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class UUIDUtil {
|
||||||
|
|
||||||
|
private static final Pattern COMPILE = Pattern.compile("-", Pattern.LITERAL);
|
||||||
|
|
||||||
|
public static UUID random() {
|
||||||
|
return UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(UUID uuid, boolean withDash) {
|
||||||
|
if (withDash) return uuid.toString();
|
||||||
|
else return COMPILE.matcher(uuid.toString()).replaceAll(Matcher.quoteReplacement(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID toUUID(String s) {
|
||||||
|
if (s.length() == 36) {
|
||||||
|
return UUID.fromString(s);
|
||||||
|
} else {
|
||||||
|
return UUID.fromString(s.substring(0, 8) + '-' + s.substring(8, 12) + '-' + s.substring(12, 16) + '-' + s.substring(16, 20) + '-' + s.substring(20));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package cc.carm.lib.easysql.api.function;
|
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface SQLExceptionHandler extends BiConsumer<SQLException, SQLAction<?>> {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-56
@@ -1,56 +0,0 @@
|
|||||||
package cc.carm.lib.easysql.api.function.defaults;
|
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
|
||||||
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
|
||||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
public class DefaultSQLExceptionHandler implements SQLExceptionHandler {
|
|
||||||
|
|
||||||
private static @Nullable SQLExceptionHandler customDefaultHandler = null;
|
|
||||||
private final Logger logger;
|
|
||||||
|
|
||||||
public DefaultSQLExceptionHandler(Logger logger) {
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @Nullable SQLExceptionHandler getCustomHandler() {
|
|
||||||
return customDefaultHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setCustomHandler(@Nullable SQLExceptionHandler handler) {
|
|
||||||
DefaultSQLExceptionHandler.customDefaultHandler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull SQLExceptionHandler get(Logger logger) {
|
|
||||||
if (getCustomHandler() != null) return getCustomHandler();
|
|
||||||
else return new DefaultSQLExceptionHandler(logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Logger getLogger() {
|
|
||||||
return logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accept(SQLException exception, SQLAction<?> sqlAction) {
|
|
||||||
if (sqlAction instanceof SQLUpdateBatchAction) {
|
|
||||||
|
|
||||||
getLogger().severe("Error when execute SQLs : ");
|
|
||||||
int i = 1;
|
|
||||||
for (String content : ((SQLUpdateBatchAction) sqlAction).getSQLContents()) {
|
|
||||||
getLogger().severe(String.format("#%d {%s}", i, content));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
getLogger().severe("Error when execute { " + sqlAction.getSQLContent() + " }");
|
|
||||||
}
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package cc.carm.lib.easysql.api.util;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class UUIDUtil {
|
|
||||||
|
|
||||||
public static UUID toUUID(String s) {
|
|
||||||
if (s.length() == 36) {
|
|
||||||
return UUID.fromString(s);
|
|
||||||
} else {
|
|
||||||
return UUID.fromString(s.substring(0, 8) + '-' + s.substring(8, 12) + '-' + s.substring(12, 16) + '-' + s.substring(16, 20) + '-' + s.substring(20));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,14 +5,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.3.8</version>
|
<version>0.3.11</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||||
@@ -64,6 +64,22 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<!--项目地址 https://github.com/brettwooldridge/HikariCP/ -->
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>4.0.3</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<version>2.1.212</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
+31
-4
@@ -1,5 +1,6 @@
|
|||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.api.SQLQuery;
|
import cc.carm.lib.easysql.api.SQLQuery;
|
||||||
|
import cc.carm.lib.easysql.api.SQLTable;
|
||||||
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
||||||
import cc.carm.lib.easysql.api.enums.IndexType;
|
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||||
import cc.carm.lib.easysql.api.enums.NumberType;
|
import cc.carm.lib.easysql.api.enums.NumberType;
|
||||||
@@ -43,6 +44,33 @@ public class EasySQLDemo {
|
|||||||
.build().execute(null /* 不处理错误 */);
|
.build().execute(null /* 不处理错误 */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void useSQLTable(SQLManager sqlManager) {
|
||||||
|
SQLTable tags = SQLTable.of("servers", table -> {
|
||||||
|
table.addAutoIncrementColumn("id", true);
|
||||||
|
table.addColumn("user", "INT UNSIGNED NOT NULL");
|
||||||
|
table.addColumn("content", "TEXT NOT NULL");
|
||||||
|
table.addColumn("time", "DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP");
|
||||||
|
|
||||||
|
table.addForeignKey(
|
||||||
|
"user", "fk_user_tags",
|
||||||
|
"users", "id",
|
||||||
|
ForeignKeyRule.CASCADE, ForeignKeyRule.CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
tags.create(sqlManager);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
tags.createQuery().addCondition("id", 5).build()
|
||||||
|
.executeAsync(success -> {
|
||||||
|
System.out.println("success!");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void alertTable(SQLManager sqlManager) {
|
public void alertTable(SQLManager sqlManager) {
|
||||||
// 同步更新表
|
// 同步更新表
|
||||||
sqlManager.alterTable("users")
|
sqlManager.alterTable("users")
|
||||||
@@ -106,7 +134,7 @@ public class EasySQLDemo {
|
|||||||
|
|
||||||
public void sqlInsert(SQLManager sqlManager) {
|
public void sqlInsert(SQLManager sqlManager) {
|
||||||
// 同步SQL插入 (不使用try-catch的情况下,返回的数值可能为空。)
|
// 同步SQL插入 (不使用try-catch的情况下,返回的数值可能为空。)
|
||||||
Integer id = sqlManager.createInsert("users")
|
Long id = sqlManager.createInsert("users")
|
||||||
.setColumnNames("username", "phone", "email", "registerTime")
|
.setColumnNames("username", "phone", "email", "registerTime")
|
||||||
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
||||||
.setReturnGeneratedKey(true)// 设定在后续返回自增主键
|
.setReturnGeneratedKey(true)// 设定在后续返回自增主键
|
||||||
@@ -117,11 +145,10 @@ public class EasySQLDemo {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Integer userID = sqlManager.createInsert("users")
|
Long userID = sqlManager.createInsert("users")
|
||||||
.setColumnNames("username", "phone", "email", "registerTime")
|
.setColumnNames("username", "phone", "email", "registerTime")
|
||||||
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
||||||
.setReturnGeneratedKey(true)
|
.returnGeneratedKey().execute();
|
||||||
.execute();
|
|
||||||
|
|
||||||
System.out.println("新用户的ID为 " + userID);
|
System.out.println("新用户的ID为 " + userID);
|
||||||
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package cc.carm.lib.easysql;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||||
|
import cc.carm.lib.easysql.tests.*;
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class EasySQLTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onTest() {
|
||||||
|
|
||||||
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setDriverClassName("org.h2.Driver");
|
||||||
|
config.setJdbcUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=MYSQL;");
|
||||||
|
|
||||||
|
SQLManager sqlManager = new SQLManagerImpl(new HikariDataSource(config), "test");
|
||||||
|
|
||||||
|
print("加载测试类...");
|
||||||
|
Set<TestHandler> tests = new LinkedHashSet<>();
|
||||||
|
tests.add(new TableCreateTest());
|
||||||
|
// tests.add(new TableAlterTest());
|
||||||
|
// tests.add(new TableRenameTest());
|
||||||
|
// tests.add(new QueryNotCloseTest());
|
||||||
|
tests.add(new QueryCloseTest());
|
||||||
|
tests.add(new SQLUpdateBatchTests());
|
||||||
|
tests.add(new SQLUpdateReturnKeysTest());
|
||||||
|
tests.add(new QueryFunctionTest());
|
||||||
|
tests.add(new DeleteTest());
|
||||||
|
|
||||||
|
print("准备进行测试...");
|
||||||
|
|
||||||
|
int index = 1;
|
||||||
|
int success = 0;
|
||||||
|
|
||||||
|
for (TestHandler currentTest : tests) {
|
||||||
|
print("-------------------------------------------------");
|
||||||
|
if (currentTest.executeTest(index, sqlManager)) {
|
||||||
|
success++;
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000L);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
print(" ");
|
||||||
|
print("全部测试执行完毕,成功 %s 个,失败 %s 个。",
|
||||||
|
success, (tests.size() - success)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (sqlManager.getDataSource() instanceof HikariDataSource) {
|
||||||
|
//Close bee connection pool
|
||||||
|
((HikariDataSource) sqlManager.getDataSource()).close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void print(@NotNull String format, Object... params) {
|
||||||
|
System.out.printf((format) + "%n", params);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.easysql.tester;
|
package cc.carm.lib.easysql;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
@@ -6,10 +6,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public abstract class EasySQLTest {
|
public abstract class TestHandler {
|
||||||
|
|
||||||
protected static void print(@NotNull String format, Object... params) {
|
protected static void print(@NotNull String format, Object... params) {
|
||||||
Main.print(format, params);
|
EasySQLTest.print(format, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.OverrideOnly
|
@ApiStatus.OverrideOnly
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class DeleteTest extends TestHandler {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("change(s): " + sqlManager.createDelete("test_user_table")
|
||||||
|
.addCondition("id", ">", 5)
|
||||||
|
.addNotNullCondition("username")
|
||||||
|
.build().execute());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -1,13 +1,13 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.api.SQLQuery;
|
import cc.carm.lib.easysql.api.SQLQuery;
|
||||||
import cc.carm.lib.easysql.tester.EasySQLTest;
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class QueryCloseTest extends EasySQLTest {
|
public class QueryCloseTest extends TestHandler {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.tester.EasySQLTest;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class QueryFunctionTest extends EasySQLTest {
|
public class QueryFunctionTest extends TestHandler {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
+3
-3
@@ -1,13 +1,13 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.api.SQLQuery;
|
import cc.carm.lib.easysql.api.SQLQuery;
|
||||||
import cc.carm.lib.easysql.tester.EasySQLTest;
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class QueryNotCloseTest extends EasySQLTest {
|
public class QueryNotCloseTest extends TestHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.tester.EasySQLTest;
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -10,7 +10,7 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class SQLUpdateBatchTests extends EasySQLTest {
|
public class SQLUpdateBatchTests extends TestHandler {
|
||||||
|
|
||||||
|
|
||||||
protected static List<Object[]> generateParams() {
|
protected static List<Object[]> generateParams() {
|
||||||
@@ -25,7 +25,7 @@ public class SQLUpdateBatchTests extends EasySQLTest {
|
|||||||
@Override
|
@Override
|
||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
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")
|
.setColumnNames("uuid", "username", "age")
|
||||||
.setAllParams(generateParams())
|
.setAllParams(generateParams())
|
||||||
.execute();
|
.execute();
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ public class SQLUpdateReturnKeysTest extends SQLUpdateBatchTests {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
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")
|
.setColumnNames("uuid", "username", "age")
|
||||||
.setAllParams(generateParams())
|
.setAllParams(generateParams())
|
||||||
.returnGeneratedKeys()
|
.returnGeneratedKeys()
|
||||||
+3
-3
@@ -1,12 +1,12 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.api.enums.NumberType;
|
import cc.carm.lib.easysql.api.enums.NumberType;
|
||||||
import cc.carm.lib.easysql.tester.EasySQLTest;
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class TableAlterTest extends EasySQLTest {
|
public class TableAlterTest extends TestHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
+3
-4
@@ -1,13 +1,13 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
||||||
import cc.carm.lib.easysql.api.enums.IndexType;
|
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||||
import cc.carm.lib.easysql.tester.EasySQLTest;
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class TableCreateTest extends EasySQLTest {
|
public class TableCreateTest extends TestHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
@@ -30,7 +30,6 @@ public class TableCreateTest extends EasySQLTest {
|
|||||||
"test_user_table", "id",
|
"test_user_table", "id",
|
||||||
ForeignKeyRule.CASCADE, ForeignKeyRule.CASCADE
|
ForeignKeyRule.CASCADE, ForeignKeyRule.CASCADE
|
||||||
)
|
)
|
||||||
.setIndex(IndexType.FULLTEXT_INDEX, "sign", "info")
|
|
||||||
.build().execute();
|
.build().execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,11 +1,11 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
package cc.carm.lib.easysql.tests;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.tester.EasySQLTest;
|
import cc.carm.lib.easysql.TestHandler;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class TableRenameTest extends EasySQLTest {
|
public class TableRenameTest extends TestHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
print(" 重命名 test_user_table");
|
print(" 重命名 test_user_table");
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>easysql-parent</artifactId>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<version>0.3.8</version>
|
|
||||||
<relativePath>../../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
|
||||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
|
||||||
<maven.deploy.skip>true</maven.deploy.skip>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<artifactId>easysql-tester</artifactId>
|
|
||||||
|
|
||||||
<name>EasySQL-Test</name>
|
|
||||||
<description>EasySQL的测试代码</description>
|
|
||||||
<url>https://github.com/CarmJos/EasySQL</url>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easysql-beecp</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>8.0.28</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>1.7.36</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-api</artifactId>
|
|
||||||
<version>2.17.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-core</artifactId>
|
|
||||||
<version>2.17.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-slf4j-impl</artifactId>
|
|
||||||
<version>2.17.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.2.4</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
<!-- when downloading via Maven we can pull depends individually -->
|
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptRef>jar-with-dependencies</descriptRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>cc.carm.lib.easysql.tester.Main</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>make-assembly</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>assembly</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
package cc.carm.lib.easysql.tester;
|
|
||||||
|
|
||||||
import cc.carm.lib.easysql.EasySQL;
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
|
||||||
import cc.carm.lib.easysql.tester.tests.DeleteTest;
|
|
||||||
import cc.carm.lib.easysql.tester.tests.QueryCloseTest;
|
|
||||||
import cc.carm.lib.easysql.tester.tests.QueryFunctionTest;
|
|
||||||
import cc.carm.lib.easysql.tester.tests.TableCreateTest;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.TestOnly;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@TestOnly
|
|
||||||
@SuppressWarnings("all")
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
if (args.length < 4) {
|
|
||||||
print("请提供以下参数:<数据库驱动> <数据库地址(JDBC)> <数据库用户> <数据库密码> [是否采用DEBUG(y/n)]");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SQLManager sqlManager;
|
|
||||||
try {
|
|
||||||
print("初始化 SQLManager...");
|
|
||||||
print("数据库驱动 %s", args[0]);
|
|
||||||
print("数据库地址 %s", args[1]);
|
|
||||||
print("数据库用户 %s", args[2]);
|
|
||||||
print("数据库密码 %s", args[3]);
|
|
||||||
sqlManager = EasySQL.createManager(args[0], args[1], args[2], args[3]);
|
|
||||||
sqlManager.setDebugMode(args.length > 4);
|
|
||||||
print("SQLManager 初始化完成!");
|
|
||||||
} catch (Exception exception) {
|
|
||||||
print("SQLManager 初始化失败,请检查数据库配置。");
|
|
||||||
exception.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
print("加载测试类...");
|
|
||||||
Set<EasySQLTest> tests = new LinkedHashSet<>();
|
|
||||||
tests.add(new TableCreateTest());
|
|
||||||
// tests.add(new TableAlterTest());
|
|
||||||
// tests.add(new TableRenameTest());
|
|
||||||
// tests.add(new QueryNotCloseTest());
|
|
||||||
tests.add(new QueryCloseTest());
|
|
||||||
// tests.add(new SQLUpdateBatchTests());
|
|
||||||
// tests.add(new SQLUpdateReturnKeysTest());
|
|
||||||
tests.add(new QueryFunctionTest());
|
|
||||||
tests.add(new DeleteTest());
|
|
||||||
|
|
||||||
print("准备进行测试...");
|
|
||||||
|
|
||||||
int index = 1;
|
|
||||||
int success = 0;
|
|
||||||
|
|
||||||
Iterator<EasySQLTest> testIterator = tests.iterator();
|
|
||||||
|
|
||||||
print("准备完成,请按回车键开始执行测试。");
|
|
||||||
|
|
||||||
while (testIterator.hasNext()) {
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
|
|
||||||
if (scanner.nextLine() != null) {
|
|
||||||
|
|
||||||
EasySQLTest currentTest = testIterator.next();
|
|
||||||
|
|
||||||
if (currentTest.executeTest(index, sqlManager)) {
|
|
||||||
success++;
|
|
||||||
}
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
print(" ");
|
|
||||||
print("全部测试执行完毕,成功 %s 个,失败 %s 个。",
|
|
||||||
success, (tests.size() - success)
|
|
||||||
);
|
|
||||||
|
|
||||||
EasySQL.shutdownManager(sqlManager);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void print(@NotNull String format, Object... params) {
|
|
||||||
System.out.printf((format) + "%n", params);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package cc.carm.lib.easysql.tester.tests;
|
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
|
||||||
import cc.carm.lib.easysql.tester.EasySQLTest;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class DeleteTest extends EasySQLTest {
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
|
||||||
|
|
||||||
Integer changes = sqlManager.createDelete("test_user_table")
|
|
||||||
.addCondition("id", ">", 5)
|
|
||||||
.addNotNullCondition("username")
|
|
||||||
.build().execute();
|
|
||||||
|
|
||||||
System.out.println("change(s): " + changes);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Configuration status="WARN" packages="cc.carm.lib.easysql">
|
|
||||||
<Appenders>
|
|
||||||
<console name="Console" target="SYSTEM_OUT">
|
|
||||||
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n"/>
|
|
||||||
</console>
|
|
||||||
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
|
|
||||||
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n"/>
|
|
||||||
<Policies>
|
|
||||||
<TimeBasedTriggeringPolicy/>
|
|
||||||
<OnStartupTriggeringPolicy/>
|
|
||||||
</Policies>
|
|
||||||
</RollingRandomAccessFile>
|
|
||||||
</Appenders>
|
|
||||||
<Loggers>
|
|
||||||
<root level="info">
|
|
||||||
<filters>
|
|
||||||
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
|
|
||||||
</filters>
|
|
||||||
<!-- <AppenderRef ref="WINDOWS_COMPAT" level="info"/>-->
|
|
||||||
<AppenderRef ref="File"/>
|
|
||||||
<appender-ref ref="Console"/>
|
|
||||||
</root>
|
|
||||||
</Loggers>
|
|
||||||
</Configuration>
|
|
||||||
|
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.3.8</version>
|
<version>0.3.11</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
+7
-6
@@ -15,7 +15,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PreparedSQLBatchUpdateActionImpl
|
public class PreparedSQLBatchUpdateActionImpl
|
||||||
extends AbstractSQLAction<List<Integer>>
|
extends AbstractSQLAction<List<Long>>
|
||||||
implements PreparedSQLUpdateBatchAction {
|
implements PreparedSQLUpdateBatchAction {
|
||||||
|
|
||||||
boolean returnKeys = false;
|
boolean returnKeys = false;
|
||||||
@@ -47,7 +47,7 @@ public class PreparedSQLBatchUpdateActionImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<Integer> execute() throws SQLException {
|
public @NotNull List<Long> execute() throws SQLException {
|
||||||
try (Connection connection = getManager().getConnection()) {
|
try (Connection connection = getManager().getConnection()) {
|
||||||
try (PreparedStatement statement = StatementUtil.createPrepareStatementBatch(
|
try (PreparedStatement statement = StatementUtil.createPrepareStatementBatch(
|
||||||
connection, getSQLContent(), allParams, returnKeys
|
connection, getSQLContent(), allParams, returnKeys
|
||||||
@@ -56,12 +56,13 @@ public class PreparedSQLBatchUpdateActionImpl
|
|||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
int[] executed = statement.executeBatch();
|
int[] executed = statement.executeBatch();
|
||||||
|
|
||||||
if (!returnKeys) return Arrays.stream(executed).boxed().collect(Collectors.toList());
|
if (!returnKeys) {
|
||||||
else {
|
return Arrays.stream(executed).mapToLong(Long::valueOf).boxed().collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||||
List<Integer> generatedKeys = new ArrayList<>();
|
List<Long> generatedKeys = new ArrayList<>();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
generatedKeys.add(resultSet.getInt(1));
|
generatedKeys.add(resultSet.getLong(1));
|
||||||
}
|
}
|
||||||
return generatedKeys;
|
return generatedKeys;
|
||||||
}
|
}
|
||||||
+3
-3
@@ -52,7 +52,7 @@ public class PreparedSQLUpdateActionImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Integer execute() throws SQLException {
|
public @NotNull Long execute() throws SQLException {
|
||||||
try (Connection connection = getManager().getConnection()) {
|
try (Connection connection = getManager().getConnection()) {
|
||||||
|
|
||||||
try (PreparedStatement statement = StatementUtil.createPrepareStatement(
|
try (PreparedStatement statement = StatementUtil.createPrepareStatement(
|
||||||
@@ -62,10 +62,10 @@ public class PreparedSQLUpdateActionImpl
|
|||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
|
|
||||||
int changes = statement.executeUpdate();
|
int changes = statement.executeUpdate();
|
||||||
if (!returnGeneratedKeys) return changes;
|
if (!returnGeneratedKeys) return (long) changes;
|
||||||
else {
|
else {
|
||||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||||
return resultSet.next() ? resultSet.getInt(1) : -1;
|
return resultSet.next() ? resultSet.getLong(1) : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+4
-4
@@ -10,7 +10,7 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
public class SQLUpdateActionImpl
|
public class SQLUpdateActionImpl
|
||||||
extends AbstractSQLAction<Integer>
|
extends AbstractSQLAction<Long>
|
||||||
implements SQLUpdateAction {
|
implements SQLUpdateAction {
|
||||||
|
|
||||||
boolean returnGeneratedKeys = false;
|
boolean returnGeneratedKeys = false;
|
||||||
@@ -20,18 +20,18 @@ public class SQLUpdateActionImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Integer execute() throws SQLException {
|
public @NotNull Long execute() throws SQLException {
|
||||||
try (Connection connection = getManager().getConnection()) {
|
try (Connection connection = getManager().getConnection()) {
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Statement statement = connection.createStatement()) {
|
||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
|
|
||||||
if (!returnGeneratedKeys) {
|
if (!returnGeneratedKeys) {
|
||||||
return statement.executeUpdate(getSQLContent());
|
return (long) statement.executeUpdate(getSQLContent());
|
||||||
} else {
|
} else {
|
||||||
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
|
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||||
return resultSet.next() ? resultSet.getInt(1) : -1;
|
return resultSet.next() ? resultSet.getLong(1) : -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -12,7 +12,7 @@ import java.util.Objects;
|
|||||||
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
|
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
|
||||||
|
|
||||||
public class DeleteBuilderImpl
|
public class DeleteBuilderImpl
|
||||||
extends AbstractConditionalBuilder<DeleteBuilder, SQLAction<Integer>>
|
extends AbstractConditionalBuilder<DeleteBuilder, SQLAction<Long>>
|
||||||
implements DeleteBuilder {
|
implements DeleteBuilder {
|
||||||
|
|
||||||
protected final String tableName;
|
protected final String tableName;
|
||||||
+13
-13
@@ -28,7 +28,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> renameTo(@NotNull String newTableName) {
|
public SQLAction<Long> renameTo(@NotNull String newTableName) {
|
||||||
Objects.requireNonNull(newTableName, "table name could not be null");
|
Objects.requireNonNull(newTableName, "table name could not be null");
|
||||||
return new SQLUpdateActionImpl(getManager(),
|
return new SQLUpdateActionImpl(getManager(),
|
||||||
"ALTER TABLE " + withBackQuote(tableName) + " RENAME TO " + withBackQuote(newTableName)
|
"ALTER TABLE " + withBackQuote(tableName) + " RENAME TO " + withBackQuote(newTableName)
|
||||||
@@ -36,7 +36,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> changeComment(@NotNull String newTableComment) {
|
public SQLAction<Long> changeComment(@NotNull String newTableComment) {
|
||||||
Objects.requireNonNull(newTableComment, "table comment could not be null");
|
Objects.requireNonNull(newTableComment, "table comment could not be null");
|
||||||
return new SQLUpdateActionImpl(getManager(),
|
return new SQLUpdateActionImpl(getManager(),
|
||||||
"ALTER TABLE " + withBackQuote(getTableName()) + " COMMENT " + withQuote(newTableComment)
|
"ALTER TABLE " + withBackQuote(getTableName()) + " COMMENT " + withQuote(newTableComment)
|
||||||
@@ -44,14 +44,14 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> setAutoIncrementIndex(int index) {
|
public SQLAction<Long> setAutoIncrementIndex(int index) {
|
||||||
return new SQLUpdateActionImpl(getManager(),
|
return new SQLUpdateActionImpl(getManager(),
|
||||||
"ALTER TABLE " + withBackQuote(getTableName()) + " AUTO_INCREMENT=" + index
|
"ALTER TABLE " + withBackQuote(getTableName()) + " AUTO_INCREMENT=" + index
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
|
public SQLAction<Long> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
|
||||||
@NotNull String columnName, @NotNull String... moreColumns) {
|
@NotNull String columnName, @NotNull String... moreColumns) {
|
||||||
Objects.requireNonNull(indexType, "indexType could not be null");
|
Objects.requireNonNull(indexType, "indexType could not be null");
|
||||||
Objects.requireNonNull(columnName, "column names could not be null");
|
Objects.requireNonNull(columnName, "column names could not be null");
|
||||||
@@ -63,7 +63,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> dropIndex(@NotNull String indexName) {
|
public SQLAction<Long> dropIndex(@NotNull String indexName) {
|
||||||
Objects.requireNonNull(indexName, "indexName could not be null");
|
Objects.requireNonNull(indexName, "indexName could not be null");
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP INDEX " + withBackQuote(indexName)
|
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP INDEX " + withBackQuote(indexName)
|
||||||
@@ -71,7 +71,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> dropForeignKey(@NotNull String keySymbol) {
|
public SQLAction<Long> dropForeignKey(@NotNull String keySymbol) {
|
||||||
Objects.requireNonNull(keySymbol, "keySymbol could not be null");
|
Objects.requireNonNull(keySymbol, "keySymbol could not be null");
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP FOREIGN KEY " + withBackQuote(keySymbol)
|
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP FOREIGN KEY " + withBackQuote(keySymbol)
|
||||||
@@ -79,14 +79,14 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> dropPrimaryKey() {
|
public SQLAction<Long> dropPrimaryKey() {
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP PRIMARY KEY"
|
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP PRIMARY KEY"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(columnName, "columnName could not be null");
|
||||||
Objects.requireNonNull(settings, "settings could not be null");
|
Objects.requireNonNull(settings, "settings could not be null");
|
||||||
String orderSettings = null;
|
String orderSettings = null;
|
||||||
@@ -105,7 +105,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(columnName, "columnName could not be null");
|
||||||
Objects.requireNonNull(newName, "please specify new column name");
|
Objects.requireNonNull(newName, "please specify new column name");
|
||||||
return createAction(
|
return createAction(
|
||||||
@@ -114,7 +114,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(columnName, "columnName could not be null");
|
||||||
Objects.requireNonNull(settings, "please specify new column settings");
|
Objects.requireNonNull(settings, "please specify new column settings");
|
||||||
return createAction(
|
return createAction(
|
||||||
@@ -123,7 +123,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> removeColumn(@NotNull String columnName) {
|
public SQLAction<Long> removeColumn(@NotNull String columnName) {
|
||||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP " + withBackQuote(columnName)
|
"ALTER TABLE " + withBackQuote(getTableName()) + " DROP " + withBackQuote(columnName)
|
||||||
@@ -131,7 +131,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(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().");
|
Objects.requireNonNull(defaultValue, "defaultValue could not be null, if you need to remove the default value, please use #removeColumnDefault().");
|
||||||
return createAction(
|
return createAction(
|
||||||
@@ -140,7 +140,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLAction<Integer> removeColumnDefault(@NotNull String columnName) {
|
public SQLAction<Long> removeColumnDefault(@NotNull String columnName) {
|
||||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||||
return createAction(
|
return createAction(
|
||||||
"ALTER TABLE " + withBackQuote(getTableName()) + " ALTER " + withBackQuote(columnName) + " DROP DEFAULT"
|
"ALTER TABLE " + withBackQuote(getTableName()) + " ALTER " + withBackQuote(columnName) + " DROP DEFAULT"
|
||||||
+1
-1
@@ -13,7 +13,7 @@ import java.util.*;
|
|||||||
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
|
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
|
||||||
|
|
||||||
public class UpdateBuilderImpl
|
public class UpdateBuilderImpl
|
||||||
extends AbstractConditionalBuilder<UpdateBuilder, SQLAction<Integer>>
|
extends AbstractConditionalBuilder<UpdateBuilder, SQLAction<Long>>
|
||||||
implements UpdateBuilder {
|
implements UpdateBuilder {
|
||||||
|
|
||||||
protected final @NotNull String tableName;
|
protected final @NotNull String tableName;
|
||||||
+19
-3
@@ -10,6 +10,7 @@ import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
|
|||||||
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
|
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
|
||||||
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
||||||
import cc.carm.lib.easysql.api.builder.*;
|
import cc.carm.lib.easysql.api.builder.*;
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||||
import cc.carm.lib.easysql.builder.impl.*;
|
import cc.carm.lib.easysql.builder.impl.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -32,6 +33,8 @@ public class SQLManagerImpl implements SQLManager {
|
|||||||
protected ExecutorService executorPool;
|
protected ExecutorService executorPool;
|
||||||
@NotNull Supplier<Boolean> debugMode = () -> Boolean.FALSE;
|
@NotNull Supplier<Boolean> debugMode = () -> Boolean.FALSE;
|
||||||
|
|
||||||
|
@NotNull SQLExceptionHandler exceptionHandler;
|
||||||
|
|
||||||
public SQLManagerImpl(@NotNull DataSource dataSource) {
|
public SQLManagerImpl(@NotNull DataSource dataSource) {
|
||||||
this(dataSource, null);
|
this(dataSource, null);
|
||||||
}
|
}
|
||||||
@@ -45,6 +48,8 @@ public class SQLManagerImpl implements SQLManager {
|
|||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
return thread;
|
return thread;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.exceptionHandler = SQLExceptionHandler.detailed(getLogger());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,17 +91,28 @@ public class SQLManagerImpl implements SQLManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer executeSQL(String sql) {
|
public @NotNull SQLExceptionHandler getExceptionHandler() {
|
||||||
|
return this.exceptionHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setExceptionHandler(@Nullable SQLExceptionHandler handler) {
|
||||||
|
if (handler == null) this.exceptionHandler = SQLExceptionHandler.detailed(getLogger());
|
||||||
|
else this.exceptionHandler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long executeSQL(String sql) {
|
||||||
return new SQLUpdateActionImpl(this, sql).execute(null);
|
return new SQLUpdateActionImpl(this, sql).execute(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer executeSQL(String sql, Object[] params) {
|
public Long executeSQL(String sql, Object[] params) {
|
||||||
return new PreparedSQLUpdateActionImpl(this, sql, params).execute(null);
|
return new PreparedSQLUpdateActionImpl(this, sql, params).execute(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
|
public List<Long> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
|
||||||
return new PreparedSQLBatchUpdateActionImpl(this, sql)
|
return new PreparedSQLBatchUpdateActionImpl(this, sql)
|
||||||
.setAllParams(paramsBatch)
|
.setAllParams(paramsBatch)
|
||||||
.execute(null);
|
.execute(null);
|
||||||
@@ -17,17 +17,16 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>0.3.8</version>
|
<version>0.3.11</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>easysql-api</module>
|
<module>api</module>
|
||||||
<module>easysql-impl</module>
|
<module>impl</module>
|
||||||
|
|
||||||
<module>with-pool/easysql-beecp</module>
|
<module>with-pool/beecp</module>
|
||||||
<module>with-pool/easysql-hikaricp</module>
|
<module>with-pool/hikaricp</module>
|
||||||
|
|
||||||
<module>example/easysql-demo</module>
|
<module>example/demo</module>
|
||||||
<module>example/easysql-tester</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<name>EasySQL</name>
|
<name>EasySQL</name>
|
||||||
@@ -197,7 +196,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.10.0</version>
|
<version>3.10.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java.version}</source>
|
<source>${java.version}</source>
|
||||||
<target>${java.version}</target>
|
<target>${java.version}</target>
|
||||||
@@ -229,7 +228,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.4</version>
|
<version>3.3.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.3.8</version>
|
<version>0.3.11</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
<!--项目地址 https://github.com/Chris2018998/BeeCP -->
|
<!--项目地址 https://github.com/Chris2018998/BeeCP -->
|
||||||
<groupId>com.github.chris2018998</groupId>
|
<groupId>com.github.chris2018998</groupId>
|
||||||
<artifactId>beecp</artifactId>
|
<artifactId>beecp</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.3.5</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.4</version>
|
<version>3.3.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
+2
-2
@@ -27,8 +27,8 @@ public class EasySQL {
|
|||||||
manager.getLogger().severe("There are " + manager.getActiveQuery().size() + " connections still running");
|
manager.getLogger().severe("There are " + manager.getActiveQuery().size() + " connections still running");
|
||||||
for (SQLQuery value : manager.getActiveQuery().values()) {
|
for (SQLQuery value : manager.getActiveQuery().values()) {
|
||||||
if (outputActiveQuery) {
|
if (outputActiveQuery) {
|
||||||
manager.getLogger().severe("#" + value.getAction().getShortID() + " -> " + value.getSQLContent());
|
manager.getLogger().severe(String.format("#%s -> %s", value.getAction().getShortID(), value.getSQLContent()));
|
||||||
manager.getLogger().severe("- execute at " + TimeDateUtils.getTimeString(value.getExecuteTime()));
|
manager.getLogger().severe(String.format("- execute at %s", TimeDateUtils.getTimeString(value.getExecuteTime())));
|
||||||
}
|
}
|
||||||
if (forceClose) value.close();
|
if (forceClose) value.close();
|
||||||
}
|
}
|
||||||
@@ -5,14 +5,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easysql-parent</artifactId>
|
<artifactId>easysql-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>0.3.8</version>
|
<version>0.3.11</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.4</version>
|
<version>3.3.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
+2
-2
@@ -37,8 +37,8 @@ public class EasySQL {
|
|||||||
manager.getLogger().severe("There are " + manager.getActiveQuery().size() + " connections still running");
|
manager.getLogger().severe("There are " + manager.getActiveQuery().size() + " connections still running");
|
||||||
for (SQLQuery value : manager.getActiveQuery().values()) {
|
for (SQLQuery value : manager.getActiveQuery().values()) {
|
||||||
if (outputActiveQuery) {
|
if (outputActiveQuery) {
|
||||||
manager.getLogger().severe("#" + value.getAction().getShortID() + " -> " + value.getSQLContent());
|
manager.getLogger().severe(String.format("#%s -> %s", value.getAction().getShortID(), value.getSQLContent()));
|
||||||
manager.getLogger().severe("- execute at " + TimeDateUtils.getTimeString(value.getExecuteTime()));
|
manager.getLogger().severe(String.format("- execute at %s", TimeDateUtils.getTimeString(value.getExecuteTime())));
|
||||||
}
|
}
|
||||||
if (forceClose) value.close();
|
if (forceClose) value.close();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user