mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-07-16 06:02:47 +08:00
feat: 提交进度 [ci skip]
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package cc.carm.lib.easysql.api;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* SQLBuilder 是用于构建SQL语句以生成SQLAction执行操作的中间类。
|
||||
* <br>其连接了{@link SQLManager} 与 {@link SQLAction} ,避免大量的代码堆积
|
||||
* <br>其连接了{@link SQLManager} 与 {@link SQLBaseAction} ,避免大量的代码堆积
|
||||
* <br>也是本接口的核心功能所在
|
||||
*
|
||||
* @author CarmJos
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package cc.carm.lib.easysql.api;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.asyncable.AsyncablePreparedBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.asyncable.AsyncablePreparedUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.query.PreparedSQLQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.query.SQLQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.update.PreparedSQLBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.PreparedSQLUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.SQLBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.SQLUpdateAction;
|
||||
import cc.carm.lib.easysql.api.builder.*;
|
||||
import cc.carm.lib.easysql.api.enums.IsolationLevel;
|
||||
import cc.carm.lib.easysql.api.function.SQLBiFunction;
|
||||
@@ -13,10 +17,60 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface SQLManager extends SQLSource {
|
||||
|
||||
/**
|
||||
* 执行一条不需要返回结果的SQL语句(多用于UPDATE、REPLACE、DELETE方法)
|
||||
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @return 更新的行数
|
||||
* @see SQLUpdateAction
|
||||
*/
|
||||
@Nullable Integer executeSQL(String sql);
|
||||
|
||||
/**
|
||||
* 执行一条不需要返回结果的预处理SQL更改(UPDATE、REPLACE、DELETE)
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @param params SQL语句中 ? 的对应参数
|
||||
* @return 更新的行数
|
||||
* @see PreparedSQLUpdateAction
|
||||
*/
|
||||
@Nullable Integer executeSQL(String sql, Object[] params);
|
||||
|
||||
/**
|
||||
* 执行多条不需要返回结果的SQL更改(UPDATE、REPLACE、DELETE)
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @param paramsBatch SQL语句中对应?的参数组
|
||||
* @return 对应参数返回的行数
|
||||
* @see PreparedSQLBatchUpdateAction
|
||||
*/
|
||||
@Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
|
||||
|
||||
/**
|
||||
* 执行多条不需要返回结果的SQL。
|
||||
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @param moreSQL 更多SQL语句内容
|
||||
* @return 对应参数返回的行数
|
||||
* @see SQLBatchUpdateAction
|
||||
*/
|
||||
@Nullable List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL);
|
||||
|
||||
/**
|
||||
* 执行多条不需要返回结果的SQL。
|
||||
*
|
||||
* @param sqlBatch SQL语句内容
|
||||
* @return 对应参数返回的行数
|
||||
*/
|
||||
@Nullable List<Integer> executeSQLBatch(@NotNull Iterable<String> sqlBatch);
|
||||
|
||||
default @NotNull SQLTransaction createTransaction() {
|
||||
return createTransaction(null);
|
||||
}
|
||||
@@ -28,7 +82,7 @@ public interface SQLManager extends SQLSource {
|
||||
*
|
||||
* @return {@link QueryBuilder}
|
||||
*/
|
||||
@NotNull QueryBuilder createQuery();
|
||||
@NotNull QueryBuilder<SQLQueryAction.Advanced, PreparedSQLQueryAction.Advanced> createQuery();
|
||||
|
||||
/**
|
||||
* 创建一条插入操作。
|
||||
@@ -36,7 +90,7 @@ public interface SQLManager extends SQLSource {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link InsertBuilder}
|
||||
*/
|
||||
@NotNull InsertBuilder<AsyncablePreparedUpdateAction<Integer>> insertInto(@NotNull String tableName);
|
||||
@NotNull InsertBuilder<PreparedSQLUpdateAction.Advanced<Integer>> insertInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建支持多组数据的插入操作。
|
||||
@@ -44,7 +98,7 @@ public interface SQLManager extends SQLSource {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link InsertBuilder}
|
||||
*/
|
||||
@NotNull InsertBuilder<AsyncablePreparedBatchUpdateAction<Integer>> insertBatchInto(@NotNull String tableName);
|
||||
@NotNull InsertBuilder<PreparedSQLBatchUpdateAction.Advanced<Integer>> insertBatchInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建一条替换操作。
|
||||
@@ -52,7 +106,7 @@ public interface SQLManager extends SQLSource {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link ReplaceBuilder}
|
||||
*/
|
||||
@NotNull ReplaceBuilder<AsyncablePreparedUpdateAction<Integer>> replaceInto(@NotNull String tableName);
|
||||
@NotNull ReplaceBuilder<PreparedSQLUpdateAction.Advanced<Integer>> replaceInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建支持多组数据的替换操作。
|
||||
@@ -60,7 +114,7 @@ public interface SQLManager extends SQLSource {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link ReplaceBuilder}
|
||||
*/
|
||||
@NotNull ReplaceBuilder<AsyncablePreparedBatchUpdateAction<Integer>> replaceBatchInto(@NotNull String tableName);
|
||||
@NotNull ReplaceBuilder<PreparedSQLBatchUpdateAction.Advanced<Integer>> replaceBatchInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建更新操作。
|
||||
@@ -68,7 +122,7 @@ public interface SQLManager extends SQLSource {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link UpdateBuilder}
|
||||
*/
|
||||
@NotNull UpdateBuilder updateInto(@NotNull String tableName);
|
||||
@NotNull UpdateBuilder<PreparedSQLUpdateAction.Advanced<Integer>> updateInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建删除操作。
|
||||
@@ -76,7 +130,7 @@ public interface SQLManager extends SQLSource {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link DeleteBuilder}
|
||||
*/
|
||||
@NotNull DeleteBuilder deleteFrom(@NotNull String tableName);
|
||||
@NotNull DeleteBuilder<PreparedSQLUpdateAction.Advanced<Integer>> deleteFrom(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 在库中创建一个表。
|
||||
@@ -124,7 +178,8 @@ public interface SQLManager extends SQLSource {
|
||||
* @return 最终结果,通过 {@link CompletableFuture#get()} 可阻塞并等待结果返回。
|
||||
* @throws NullPointerException 当 supplier 提供的 {@link ResultSet} 为NULL时抛出
|
||||
*/
|
||||
default <R> CompletableFuture<R> fetchMetadata(@NotNull SQLFunction<DatabaseMetaData, ResultSet> supplier, @NotNull SQLFunction<@NotNull ResultSet, R> reader) {
|
||||
default <R> CompletableFuture<R> fetchMetadata(@NotNull SQLFunction<DatabaseMetaData, ResultSet> supplier,
|
||||
@NotNull SQLFunction<@NotNull ResultSet, R> reader) {
|
||||
return fetchMetadata((meta, conn) -> supplier.apply(meta), reader);
|
||||
}
|
||||
|
||||
@@ -147,6 +202,7 @@ public interface SQLManager extends SQLSource {
|
||||
* @return 最终结果,通过 {@link CompletableFuture#get()} 可阻塞并等待结果返回。
|
||||
* @throws NullPointerException 当 supplier 提供的 {@link ResultSet} 为NULL时抛出
|
||||
*/
|
||||
<R> CompletableFuture<R> fetchMetadata(@NotNull SQLBiFunction<DatabaseMetaData, Connection, ResultSet> supplier, @NotNull SQLFunction<@NotNull ResultSet, R> reader);
|
||||
<R> CompletableFuture<R> fetchMetadata(@NotNull SQLBiFunction<DatabaseMetaData, Connection, ResultSet> supplier,
|
||||
@NotNull SQLFunction<@NotNull ResultSet, R> reader);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package cc.carm.lib.easysql.api;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.base.QueryAction;
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.query.PreparedSQLQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.query.SQLQueryAction;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -42,11 +43,11 @@ public interface SQLQuery extends AutoCloseable {
|
||||
SQLManager getManager();
|
||||
|
||||
/**
|
||||
* 得到承载该SQLQuery的对应{@link QueryAction}
|
||||
* 得到承载该SQLQuery的对应{@link SQLQueryAction}
|
||||
*
|
||||
* @return {@link QueryAction} 或 {@link PreparedQueryAction}
|
||||
* @return {@link SQLQueryAction} 或 {@link PreparedSQLQueryAction}
|
||||
*/
|
||||
QueryAction getAction();
|
||||
SQLQueryAction<?> getAction();
|
||||
|
||||
ResultSet getResultSet();
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package cc.carm.lib.easysql.api;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.*;
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.base.BatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.base.UpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
import cc.carm.lib.easysql.api.function.SQLDebugHandler;
|
||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -14,7 +10,6 @@ import org.slf4j.Logger;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -23,10 +18,10 @@ import java.util.function.Supplier;
|
||||
|
||||
public interface SQLSource {
|
||||
|
||||
Logger getLogger();
|
||||
@NotNull Logger getLogger();
|
||||
|
||||
/**
|
||||
* 获取用于执行 {@link SQLAction#executeAsync()} 的线程池。
|
||||
* 获取用于执行 {@link SQLAdvancedAction#executeAsync()} 的线程池。
|
||||
* <br> 默认线程池为 {@link #defaultExecutorPool(String)} 。
|
||||
*
|
||||
* @return {@link ExecutorService}
|
||||
@@ -34,7 +29,7 @@ public interface SQLSource {
|
||||
@NotNull ExecutorService getExecutorPool();
|
||||
|
||||
/**
|
||||
* 设定用于执行 {@link SQLAction#executeAsync()} 的线程池.
|
||||
* 设定用于执行 {@link SQLAdvancedAction#executeAsync()} 的线程池.
|
||||
* <br> 默认线程池为 {@link #defaultExecutorPool(String)} 。
|
||||
*
|
||||
* @param executorPool {@link ExecutorService}
|
||||
@@ -103,7 +98,7 @@ public interface SQLSource {
|
||||
*
|
||||
* @return 查询列表
|
||||
*/
|
||||
@NotNull Map<UUID, SQLQuery> getActiveQuery();
|
||||
@NotNull Map<UUID, SQLQuery> getActiveQueries();
|
||||
|
||||
/**
|
||||
* 获取改管理器提供的默认异常处理器。
|
||||
@@ -116,61 +111,11 @@ public interface SQLSource {
|
||||
|
||||
/**
|
||||
* 设定通用的异常处理器。
|
||||
* <br> 在使用 {@link SQLAction#execute(SQLExceptionHandler)} 等相关方法时,若传入的处理器为null,则会采用此处理器。
|
||||
* <br> 在使用 {@link SQLAdvancedAction#execute(SQLExceptionHandler)} 等相关方法时,若传入的处理器为null,则会采用此处理器。
|
||||
* <br> 若该方法传入参数为 null,则会使用 {@link SQLExceptionHandler#detailed(Logger)} 。
|
||||
*
|
||||
* @param handler 异常处理器
|
||||
*/
|
||||
void setExceptionHandler(@Nullable SQLExceptionHandler handler);
|
||||
|
||||
/**
|
||||
* 执行一条不需要返回结果的SQL语句(多用于UPDATE、REPLACE、DELETE方法)
|
||||
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @return 更新的行数
|
||||
* @see UpdateAction
|
||||
*/
|
||||
@Nullable Integer executeSQL(String sql);
|
||||
|
||||
/**
|
||||
* 执行一条不需要返回结果的预处理SQL更改(UPDATE、REPLACE、DELETE)
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @param params SQL语句中 ? 的对应参数
|
||||
* @return 更新的行数
|
||||
* @see PreparedUpdateAction
|
||||
*/
|
||||
@Nullable Integer executeSQL(String sql, Object[] params);
|
||||
|
||||
/**
|
||||
* 执行多条不需要返回结果的SQL更改(UPDATE、REPLACE、DELETE)
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @param paramsBatch SQL语句中对应?的参数组
|
||||
* @return 对应参数返回的行数
|
||||
* @see PreparedBatchUpdateAction
|
||||
*/
|
||||
@Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
|
||||
|
||||
|
||||
/**
|
||||
* 执行多条不需要返回结果的SQL。
|
||||
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @param moreSQL 更多SQL语句内容
|
||||
* @return 对应参数返回的行数
|
||||
* @see BatchUpdateAction
|
||||
*/
|
||||
@Nullable List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL);
|
||||
|
||||
/**
|
||||
* 执行多条不需要返回结果的SQL。
|
||||
*
|
||||
* @param sqlBatch SQL语句内容
|
||||
* @return 对应参数返回的行数
|
||||
*/
|
||||
@Nullable List<Integer> executeSQLBatch(@NotNull Iterable<String> sqlBatch);
|
||||
|
||||
}
|
||||
|
||||
+57
-95
@@ -1,84 +1,37 @@
|
||||
package cc.carm.lib.easysql.api.action;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLSource;
|
||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||
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.concurrent.TimeUnit;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public interface SQLAction<T> {
|
||||
|
||||
/**
|
||||
* 得到该Action的UUID
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
@NotNull UUID getActionUUID();
|
||||
|
||||
/**
|
||||
* 得到短八位格式的UUID
|
||||
*
|
||||
* @return UUID(8)
|
||||
*/
|
||||
@NotNull String getShortID();
|
||||
|
||||
/**
|
||||
* 得到该Action的创建时间。
|
||||
* <br>注意,此处获得的时间非时间戳毫秒数,仅用于计算耗时。
|
||||
*
|
||||
* @return 创建时间 (毫秒)
|
||||
*/
|
||||
default long getCreateTime() {
|
||||
return getCreateTime(TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到该Action的创建时间
|
||||
* <br>注意,此处获得的时间非时间戳毫秒数,仅用于计算耗时。
|
||||
*
|
||||
* @param unit 时间单位
|
||||
* @return 创建时间
|
||||
*/
|
||||
long getCreateTime(TimeUnit unit);
|
||||
|
||||
/**
|
||||
* 得到该Action所要执行的源SQL语句
|
||||
*
|
||||
* @return 源SQL语句
|
||||
*/
|
||||
@NotNull String getSQLContent();
|
||||
|
||||
/**
|
||||
* 得到该Action所要执行的源SQL语句列表。
|
||||
*
|
||||
* @return 源SQL语句列表
|
||||
*/
|
||||
default @NotNull List<String> getSQLContents() {
|
||||
return Collections.singletonList(getSQLContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到承载该Action的对应{@link SQLSource}
|
||||
*
|
||||
* @return {@link SQLSource}
|
||||
*/
|
||||
@NotNull SQLSource getSource();
|
||||
|
||||
/**
|
||||
* 执行该Action对应的SQL语句
|
||||
*
|
||||
* @return 指定数据类型
|
||||
* @throws SQLException 当SQL操作出现问题时抛出
|
||||
*/
|
||||
@NotNull T execute() throws SQLException;
|
||||
/**
|
||||
* SQLAdvancedAction 是用于承载SQL语句并进行处理、返回的高级类。
|
||||
*
|
||||
* <ul>
|
||||
* <li>同步执行 {@link #execute()}, {@link #execute(SQLFunction, SQLExceptionHandler)}
|
||||
* <br>同步执行方法中有会抛出异常的方法与不抛出异常的方法,
|
||||
* <br>若选择不抛出异常,则返回值可能为空,需要特殊处理。</li>
|
||||
*
|
||||
* <li>异步执行 {@link #executeAsync(SQLHandler, SQLExceptionHandler)}
|
||||
* <br>异步执行时将提供成功与异常两种处理方式
|
||||
* <br>可自行选择是否对数据或异常进行处理
|
||||
* <br>默认的异常处理器为 {@link #defaultExceptionHandler()}
|
||||
* <br>若有特殊需要,可通过{@link #setExceptionHandler(SQLExceptionHandler)} 方法修改默认的处理器</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param <T> 需要返回的类型
|
||||
* @author CarmJos
|
||||
* @since 0.5.0
|
||||
*/
|
||||
public interface SQLAdvancedAction<T> extends SQLBaseAction<T> {
|
||||
|
||||
/**
|
||||
* 执行语句并返回值
|
||||
@@ -128,39 +81,47 @@ public interface SQLAction<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行语句并处理返回值
|
||||
*
|
||||
* @param function 处理方法
|
||||
* @param <R> 需要返回的内容
|
||||
* @return 指定类型数据
|
||||
* @throws SQLException 当SQL操作出现问题时抛出
|
||||
* 异步执行SQL语句,采用默认异常处理,无需返回值。
|
||||
*/
|
||||
@Nullable
|
||||
default <R> R executeFunction(@NotNull SQLFunction<@NotNull T, R> function) throws SQLException {
|
||||
return executeFunction(function, null);
|
||||
default void executeAsync() {
|
||||
executeAsync(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行语句并处理返回值
|
||||
* 异步执行SQL语句
|
||||
*
|
||||
* @param function 处理方法
|
||||
* @param defaultResult 默认结果,若处理后的结果为null,则返回该值
|
||||
* @param <R> 需要返回的内容
|
||||
* @return 指定类型数据
|
||||
* @throws SQLException 当SQL操作出现问题时抛出
|
||||
* @param success 成功时的操作
|
||||
*/
|
||||
@Nullable
|
||||
@Contract("_,!null -> !null")
|
||||
default <R> R executeFunction(@NotNull SQLFunction<@NotNull T, R> function,
|
||||
@Nullable R defaultResult) throws SQLException {
|
||||
try {
|
||||
R result = function.apply(execute());
|
||||
return result == null ? defaultResult : result;
|
||||
} catch (SQLException exception) {
|
||||
throw new SQLException(exception);
|
||||
}
|
||||
default void executeAsync(@Nullable SQLHandler<T> success) {
|
||||
executeAsync(success, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步执行SQL语句
|
||||
*
|
||||
* @param success 成功时的操作
|
||||
* @param failure 异常处理器 默认为 {@link SQLAdvancedAction#defaultExceptionHandler()}
|
||||
*/
|
||||
void executeAsync(@Nullable SQLHandler<T> success,
|
||||
@Nullable SQLExceptionHandler failure);
|
||||
|
||||
/**
|
||||
* 以异步Future方式执行SQL语句。
|
||||
*
|
||||
* @return 异步执行的Future实例,可通过 {@link Future#get()} 阻塞并等待结果。
|
||||
*/
|
||||
default @NotNull CompletableFuture<Void> executeFuture() {
|
||||
return executeFuture((t -> null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 以异步Future方式执行SQL语句。
|
||||
*
|
||||
* @return 异步执行的Future实例,可通过 {@link Future#get()} 阻塞并等待结果。
|
||||
*/
|
||||
<R> @NotNull CompletableFuture<R> executeFuture(@NotNull SQLFunction<T, R> handler);
|
||||
|
||||
|
||||
default void handleException(@Nullable SQLExceptionHandler handler, SQLException exception) {
|
||||
if (handler == null) handler = defaultExceptionHandler();
|
||||
handler.accept(exception, this);
|
||||
@@ -188,4 +149,5 @@ public interface SQLAction<T> {
|
||||
getSource().setExceptionHandler(handler);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action;
|
||||
|
||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||
import cc.carm.lib.easysql.api.function.SQLHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public interface SQLAsyncableAction<T> extends SQLAction<T> {
|
||||
|
||||
/**
|
||||
* 异步执行SQL语句,采用默认异常处理,无需返回值。
|
||||
*/
|
||||
default void executeAsync() {
|
||||
executeAsync(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步执行SQL语句
|
||||
*
|
||||
* @param success 成功时的操作
|
||||
*/
|
||||
default void executeAsync(@Nullable SQLHandler<T> success) {
|
||||
executeAsync(success, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步执行SQL语句
|
||||
*
|
||||
* @param success 成功时的操作
|
||||
* @param failure 异常处理器 默认为 {@link SQLAction#defaultExceptionHandler()}
|
||||
*/
|
||||
void executeAsync(@Nullable SQLHandler<T> success,
|
||||
@Nullable SQLExceptionHandler failure);
|
||||
|
||||
/**
|
||||
* 以异步Future方式执行SQL语句。
|
||||
*
|
||||
* @return 异步执行的Future实例,可通过 {@link Future#get()} 阻塞并等待结果。
|
||||
*/
|
||||
default @NotNull CompletableFuture<Void> executeFuture() {
|
||||
return executeFuture((t -> null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 以异步Future方式执行SQL语句。
|
||||
*
|
||||
* @return 异步执行的Future实例,可通过 {@link Future#get()} 阻塞并等待结果。
|
||||
*/
|
||||
<R> @NotNull CompletableFuture<R> executeFuture(@NotNull SQLFunction<T, R> handler);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package cc.carm.lib.easysql.api.action;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLSource;
|
||||
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* SQLBaseAction 是用于承载SQL语句并进行处理、返回的基本类。
|
||||
*
|
||||
* @param <T> 需要返回的类型
|
||||
* @author CarmJos
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public interface SQLBaseAction<T> {
|
||||
|
||||
/**
|
||||
* 得到该Action的UUID
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
@NotNull UUID getActionUUID();
|
||||
|
||||
/**
|
||||
* 得到短八位格式的UUID
|
||||
*
|
||||
* @return UUID(8)
|
||||
*/
|
||||
@NotNull String getShortID();
|
||||
|
||||
/**
|
||||
* 得到该Action的创建时间。
|
||||
* <br>注意,此处获得的时间非时间戳毫秒数,仅用于计算耗时。
|
||||
*
|
||||
* @return 创建时间 (毫秒)
|
||||
*/
|
||||
default long getCreateTime() {
|
||||
return getCreateTime(TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到该Action的创建时间
|
||||
* <br>注意,此处获得的时间非时间戳毫秒数,仅用于计算耗时。
|
||||
*
|
||||
* @param unit 时间单位
|
||||
* @return 创建时间
|
||||
*/
|
||||
long getCreateTime(TimeUnit unit);
|
||||
|
||||
/**
|
||||
* 得到该Action所要执行的源SQL语句
|
||||
*
|
||||
* @return 源SQL语句
|
||||
*/
|
||||
@NotNull String getSQLContent();
|
||||
|
||||
/**
|
||||
* 得到该Action所要执行的源SQL语句列表。
|
||||
*
|
||||
* @return 源SQL语句列表
|
||||
*/
|
||||
default @NotNull List<String> getSQLContents() {
|
||||
return Collections.singletonList(getSQLContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到承载该Action的对应{@link SQLSource}
|
||||
*
|
||||
* @return {@link SQLSource}
|
||||
*/
|
||||
@NotNull SQLSource getSource();
|
||||
|
||||
/**
|
||||
* 执行该Action对应的SQL语句
|
||||
*
|
||||
* @return 指定数据类型
|
||||
* @throws SQLException 当SQL操作出现问题时抛出
|
||||
*/
|
||||
@NotNull T execute() throws SQLException;
|
||||
|
||||
/**
|
||||
* 执行语句并处理返回值
|
||||
*
|
||||
* @param function 处理方法
|
||||
* @param <R> 需要返回的内容
|
||||
* @return 指定类型数据
|
||||
* @throws SQLException 当SQL操作出现问题时抛出
|
||||
*/
|
||||
@Nullable
|
||||
default <R> R executeFunction(@NotNull SQLFunction<@NotNull T, R> function) throws SQLException {
|
||||
return executeFunction(function, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行语句并处理返回值
|
||||
*
|
||||
* @param function 处理方法
|
||||
* @param defaultResult 默认结果,若处理后的结果为null,则返回该值
|
||||
* @param <R> 需要返回的内容
|
||||
* @return 指定类型数据
|
||||
* @throws SQLException 当SQL操作出现问题时抛出
|
||||
*/
|
||||
@Nullable
|
||||
@Contract("_,!null -> !null")
|
||||
default <R> R executeFunction(@NotNull SQLFunction<@NotNull T, R> function,
|
||||
@Nullable R defaultResult) throws SQLException {
|
||||
try {
|
||||
R result = function.apply(execute());
|
||||
return result == null ? defaultResult : result;
|
||||
} catch (SQLException exception) {
|
||||
throw new SQLException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.asyncable;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAsyncableAction;
|
||||
import cc.carm.lib.easysql.api.action.base.BatchUpdateAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public interface AsyncableBatchUpdateAction
|
||||
extends SQLAsyncableAction<List<Integer>> {
|
||||
|
||||
/**
|
||||
* 添加一条批量执行的SQL语句
|
||||
*
|
||||
* @param sql SQL语句
|
||||
* @return {@link BatchUpdateAction}
|
||||
*/
|
||||
BatchUpdateAction addBatch(@NotNull String sql);
|
||||
|
||||
@Override
|
||||
default @NotNull String getSQLContent() {
|
||||
return getSQLContents().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull List<String> getSQLContents();
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.asyncable;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAsyncableAction;
|
||||
import cc.carm.lib.easysql.api.action.base.UpdateAction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AsyncablePreparedBatchUpdateAction<T extends Number> extends SQLAsyncableAction<List<T>> {
|
||||
|
||||
/**
|
||||
* 设定多组SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param allValues 所有参数内容
|
||||
* @return {@link AsyncablePreparedBatchUpdateAction}
|
||||
*/
|
||||
AsyncablePreparedBatchUpdateAction<T> allValues(Iterable<Object[]> allValues);
|
||||
|
||||
/**
|
||||
* 添加一组SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param values 参数内容
|
||||
* @return {@link AsyncablePreparedBatchUpdateAction}
|
||||
*/
|
||||
AsyncablePreparedBatchUpdateAction<T> values(Object... values);
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @return {@link UpdateAction}
|
||||
*/
|
||||
AsyncablePreparedBatchUpdateAction<T> returnGeneratedKeys();
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @param keyTypeClass 自增序列的数字类型
|
||||
* @param <N> 自增键序列类型 {@link Number}
|
||||
* @return {@link UpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
<N extends Number> AsyncablePreparedBatchUpdateAction<N> returnGeneratedKeys(Class<N> keyTypeClass);
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.asyncable;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface AsyncablePreparedQueryAction extends AsyncableQueryAction {
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link AsyncablePreparedQueryAction}
|
||||
*/
|
||||
AsyncablePreparedQueryAction setParams(@Nullable Object... params);
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link AsyncablePreparedQueryAction}
|
||||
*/
|
||||
AsyncablePreparedQueryAction setParams(@Nullable Iterable<Object> params);
|
||||
|
||||
/**
|
||||
* 直接对 {@link PreparedStatement} 进行处理
|
||||
*
|
||||
* @param statement {@link Consumer} 处理操作
|
||||
* 若为空则不进行处理
|
||||
* @return {@link AsyncablePreparedQueryAction}
|
||||
*/
|
||||
AsyncablePreparedQueryAction handleStatement(@Nullable Consumer<PreparedStatement> statement);
|
||||
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.asyncable;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedUpdateAction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface AsyncablePreparedUpdateAction<T extends Number>
|
||||
extends AsyncableUpdateAction<T> {
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedUpdateAction}
|
||||
*/
|
||||
AsyncablePreparedUpdateAction<T> values(Object... params);
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedUpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
AsyncablePreparedUpdateAction<T> values(@Nullable Iterable<Object> params);
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.asyncable;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAsyncableAction;
|
||||
import cc.carm.lib.easysql.api.action.base.UpdateAction;
|
||||
|
||||
public interface AsyncableUpdateAction<T extends Number>
|
||||
extends SQLAsyncableAction<T> {
|
||||
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @return {@link UpdateAction}
|
||||
*/
|
||||
AsyncableUpdateAction<T> returnGeneratedKey();
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @param keyTypeClass 自增序列的数字类型
|
||||
* @param <N> 自增键序列类型 {@link Number}
|
||||
* @return {@link UpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
<N extends Number> AsyncableUpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass);
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.base;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public interface BatchUpdateAction extends SQLAction<List<Integer>> {
|
||||
|
||||
/**
|
||||
* 添加一条批量执行的SQL语句
|
||||
*
|
||||
* @param sql SQL语句
|
||||
* @return {@link BatchUpdateAction}
|
||||
*/
|
||||
BatchUpdateAction addBatch(@NotNull String sql);
|
||||
|
||||
@Override
|
||||
default @NotNull String getSQLContent() {
|
||||
return getSQLContents().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull List<String> getSQLContents();
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.base;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PreparedBatchUpdateAction<T extends Number> extends SQLAction<List<T>> {
|
||||
|
||||
/**
|
||||
* 设定多组SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param allValues 所有参数内容
|
||||
* @return {@link PreparedBatchUpdateAction}
|
||||
*/
|
||||
PreparedBatchUpdateAction<T> allValues(Iterable<Object[]> allValues);
|
||||
|
||||
/**
|
||||
* 添加一组SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param values 参数内容
|
||||
* @return {@link PreparedBatchUpdateAction}
|
||||
*/
|
||||
PreparedBatchUpdateAction<T> values(Object... values);
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @return {@link UpdateAction}
|
||||
*/
|
||||
PreparedBatchUpdateAction<T> returnGeneratedKeys();
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @param keyTypeClass 自增序列的数字类型
|
||||
* @param <N> 自增键序列类型 {@link Number}
|
||||
* @return {@link UpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
<N extends Number> PreparedBatchUpdateAction<N> returnGeneratedKeys(Class<N> keyTypeClass);
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.base;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface PreparedQueryAction extends QueryAction {
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedQueryAction}
|
||||
*/
|
||||
PreparedQueryAction setParams(@Nullable Object... params);
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedQueryAction}
|
||||
*/
|
||||
PreparedQueryAction setParams(@Nullable Iterable<Object> params);
|
||||
|
||||
/**
|
||||
* 直接对 {@link PreparedStatement} 进行处理
|
||||
*
|
||||
* @param statement {@link Consumer} 处理操作
|
||||
* 若为空则不进行处理
|
||||
* @return {@link PreparedQueryAction}
|
||||
*/
|
||||
PreparedQueryAction handleStatement(@Nullable Consumer<PreparedStatement> statement);
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.base;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface PreparedUpdateAction<T extends Number> extends UpdateAction<T> {
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedUpdateAction}
|
||||
*/
|
||||
PreparedUpdateAction<T> values(Object... params);
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedUpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
PreparedUpdateAction<T> values(@Nullable Iterable<Object> params);
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.base;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||
import cc.carm.lib.easysql.api.function.SQLHandler;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* SQLQueryAction 是用于承载SQL查询语句并进行处理、返回并自动关闭连接的基本类。
|
||||
*
|
||||
* <ul>
|
||||
* <li>同步执行 {@link #execute()}, {@link #execute(SQLFunction, SQLExceptionHandler)}
|
||||
* <br>同步执行方法中有会抛出异常的方法与不抛出异常的方法,
|
||||
* <br>若选择不抛出异常,则返回值可能为空,需要特殊处理。</li>
|
||||
*
|
||||
* <li>异步执行 {@link #executeAsync(SQLHandler, SQLExceptionHandler)}
|
||||
* <br>异步执行时将提供成功与异常两种处理方式
|
||||
* <br>可自行选择是否对数据或异常进行处理
|
||||
* <br>默认的异常处理器为 {@link #defaultExceptionHandler()}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <b>注意: 无论是否异步,都不需要自行关闭ResultSet,本API已自动关闭</b>
|
||||
*
|
||||
* @author CarmJos
|
||||
* @since 0.2.6
|
||||
*/
|
||||
public interface QueryAction extends SQLAction<SQLQuery> {
|
||||
|
||||
@Override
|
||||
@Contract("_,!null -> !null")
|
||||
default <R> @Nullable R executeFunction(@NotNull SQLFunction<@NotNull SQLQuery, R> function,
|
||||
@Nullable R defaultResult) throws SQLException {
|
||||
try (SQLQuery value = execute()) {
|
||||
R result = function.apply(value);
|
||||
return result == null ? defaultResult : result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.action.base;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
|
||||
public interface UpdateAction<T extends Number> extends SQLAction<T> {
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @return {@link UpdateAction}
|
||||
*/
|
||||
UpdateAction<T> returnGeneratedKey();
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @param keyTypeClass 自增序列的数字类型
|
||||
* @param <N> 自增键序列类型 {@link Number}
|
||||
* @return {@link UpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
<N extends Number> UpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cc.carm.lib.easysql.api.action.query;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
import cc.carm.lib.easysql.api.function.SQLHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public interface PreparedSQLQueryAction<B extends PreparedSQLQueryAction<B>> extends SQLQueryAction<B> {
|
||||
|
||||
interface Base extends PreparedSQLQueryAction<Base> {
|
||||
}
|
||||
|
||||
interface Advanced extends PreparedSQLQueryAction<Advanced>, SQLAdvancedAction<SQLQuery> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedSQLQueryAction}
|
||||
*/
|
||||
@NotNull B setParams(@Nullable Object... params);
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedSQLQueryAction}
|
||||
*/
|
||||
@NotNull B setParams(@Nullable Iterable<Object> params);
|
||||
|
||||
/**
|
||||
* 直接对 {@link PreparedStatement} 进行处理
|
||||
*
|
||||
* @param statement 通过 {@link SQLHandler} 处理操作
|
||||
* 若为空则不进行处理
|
||||
* @return {@link PreparedSQLQueryAction}
|
||||
*/
|
||||
@NotNull B handleStatement(@Nullable SQLHandler<PreparedStatement> statement);
|
||||
|
||||
}
|
||||
+11
-4
@@ -1,7 +1,8 @@
|
||||
package cc.carm.lib.easysql.api.action.asyncable;
|
||||
package cc.carm.lib.easysql.api.action.query;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.action.SQLAsyncableAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||
import cc.carm.lib.easysql.api.function.SQLHandler;
|
||||
@@ -19,7 +20,7 @@ import java.sql.SQLException;
|
||||
* <br>同步执行方法中有会抛出异常的方法与不抛出异常的方法,
|
||||
* <br>若选择不抛出异常,则返回值可能为空,需要特殊处理。</li>
|
||||
*
|
||||
* <li>异步执行 {@link #executeAsync(SQLHandler, SQLExceptionHandler)}
|
||||
* <li>异步执行 {@link Advanced#executeAsync(SQLHandler, SQLExceptionHandler)}
|
||||
* <br>异步执行时将提供成功与异常两种处理方式
|
||||
* <br>可自行选择是否对数据或异常进行处理
|
||||
* <br>默认的异常处理器为 {@link #defaultExceptionHandler()}</li>
|
||||
@@ -30,7 +31,13 @@ import java.sql.SQLException;
|
||||
* @author CarmJos
|
||||
* @since 0.2.6
|
||||
*/
|
||||
public interface AsyncableQueryAction extends SQLAsyncableAction<SQLQuery> {
|
||||
public interface SQLQueryAction<B extends SQLQueryAction<B>> extends SQLBaseAction<SQLQuery> {
|
||||
|
||||
interface Base extends SQLQueryAction<Base> {
|
||||
}
|
||||
|
||||
interface Advanced extends SQLQueryAction<Advanced>, SQLAdvancedAction<SQLQuery> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Contract("_,!null -> !null")
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package cc.carm.lib.easysql.api.action.update;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PreparedSQLBatchUpdateAction<T extends Number, B extends PreparedSQLBatchUpdateAction<T, B>>
|
||||
extends SQLBaseAction<List<T>> {
|
||||
|
||||
interface Base<T extends Number> extends PreparedSQLBatchUpdateAction<T, Base<T>> {
|
||||
}
|
||||
|
||||
interface Advanced<T extends Number> extends PreparedSQLBatchUpdateAction<T, Advanced<T>>, SQLAdvancedAction<List<T>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设定多组SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param allValues 所有参数内容
|
||||
* @return {@link PreparedSQLBatchUpdateAction}
|
||||
*/
|
||||
B allValues(Iterable<Object[]> allValues);
|
||||
|
||||
/**
|
||||
* 添加一组SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param values 参数内容
|
||||
* @return {@link PreparedSQLBatchUpdateAction}
|
||||
*/
|
||||
B addValues(Object... values);
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @return {@link PreparedSQLBatchUpdateAction}
|
||||
*/
|
||||
B returnGeneratedKeys();
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @param keyTypeClass 自增序列的数字类型
|
||||
* @param <N> 自增键序列类型 {@link Number}
|
||||
* @return {@link PreparedSQLBatchUpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
<N extends Number, D extends PreparedSQLBatchUpdateAction<N, D>> D returnGeneratedKeys(Class<N> keyTypeClass);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cc.carm.lib.easysql.api.action.update;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface PreparedSQLUpdateAction<T extends Number, B extends PreparedSQLUpdateAction<T, B>>
|
||||
extends SQLUpdateAction<T, B> {
|
||||
|
||||
interface Base<T extends Number> extends PreparedSQLUpdateAction<T, Base<T>> {
|
||||
}
|
||||
|
||||
interface Advanced<T extends Number> extends PreparedSQLUpdateAction<T, Advanced<T>>, SQLAdvancedAction<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedSQLUpdateAction}
|
||||
*/
|
||||
B values(Object... params);
|
||||
|
||||
/**
|
||||
* 设定SQL语句中所有 ? 对应的参数
|
||||
*
|
||||
* @param params 参数内容
|
||||
* @return {@link PreparedSQLUpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
B values(@Nullable Iterable<Object> params);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cc.carm.lib.easysql.api.action.update;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SQLBatchUpdateAction<T extends Number, B extends SQLBatchUpdateAction<T, B>> extends SQLBaseAction<T> {
|
||||
|
||||
interface Base<T extends Number> extends SQLBatchUpdateAction<T, Base<T>>, SQLBaseAction<T> {
|
||||
}
|
||||
|
||||
interface Advanced<T extends Number> extends SQLBatchUpdateAction<T, Advanced<T>>, SQLAdvancedAction<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一条批量执行的SQL语句
|
||||
*
|
||||
* @param sql SQL语句
|
||||
* @return {@link SQLBatchUpdateAction}
|
||||
*/
|
||||
B addBatch(@NotNull String sql);
|
||||
|
||||
@Override
|
||||
default @NotNull String getSQLContent() {
|
||||
return getSQLContents().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull List<String> getSQLContents();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cc.carm.lib.easysql.api.action.update;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
|
||||
public interface SQLUpdateAction<T extends Number, B extends SQLUpdateAction<T, B>> extends SQLBaseAction<T> {
|
||||
|
||||
interface Base<T extends Number> extends SQLUpdateAction<T, Base<T>> {
|
||||
|
||||
}
|
||||
|
||||
interface Advanced<T extends Number> extends SQLUpdateAction<T, Advanced<T>>, SQLAdvancedAction<T> {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @return {@link SQLUpdateAction}
|
||||
*/
|
||||
B returnGeneratedKey();
|
||||
|
||||
/**
|
||||
* 设定该操作返回自增键序列。
|
||||
*
|
||||
* @param keyTypeClass 自增序列的数字类型
|
||||
* @param <N> 自增键序列类型 {@link Number}
|
||||
* @return {@link SQLUpdateAction}
|
||||
* @since 0.4.0
|
||||
*/
|
||||
<N extends Number, D extends SQLUpdateAction<N, D>> D returnGeneratedKey(Class<N> keyTypeClass);
|
||||
|
||||
}
|
||||
@@ -1,20 +1,21 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLBuilder;
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extends SQLAction<?>> extends SQLBuilder {
|
||||
public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extends SQLBaseAction<?>> extends SQLBuilder {
|
||||
|
||||
/**
|
||||
* 将现有条件构建完整的SQL语句用于执行。
|
||||
*
|
||||
* @return {@link SQLAction}
|
||||
* @return {@link SQLBaseAction}
|
||||
*/
|
||||
T build();
|
||||
@NotNull T build();
|
||||
|
||||
/**
|
||||
* 设定限定的条目数
|
||||
@@ -22,7 +23,7 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
|
||||
* @param limit 条数限制
|
||||
* @return {@link B}
|
||||
*/
|
||||
B limit(int limit);
|
||||
@NotNull B limit(int limit);
|
||||
|
||||
/**
|
||||
* 直接设定条件的源文本,不需要以WHERE开头。
|
||||
@@ -31,7 +32,7 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
|
||||
* @param condition 条件文本,不需要以WHERE开头。
|
||||
* @return {@link B}
|
||||
*/
|
||||
B where(@Nullable String condition);
|
||||
@NotNull B where(@Nullable String condition);
|
||||
|
||||
/**
|
||||
* 直接设定每个条件的文本与其对应数值,将以AND链接,且不需要以WHERE开头。
|
||||
@@ -40,17 +41,17 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
|
||||
* @param conditionSQLs 条件内容,将以AND链接,且不需要以WHERE开头。
|
||||
* @return {@link B}
|
||||
*/
|
||||
B where(LinkedHashMap<@NotNull String, @Nullable Object> conditionSQLs);
|
||||
@NotNull B where(LinkedHashMap<@NotNull String, @Nullable Object> conditionSQLs);
|
||||
|
||||
B addCondition(@Nullable String condition);
|
||||
@NotNull B addCondition(@Nullable String condition);
|
||||
|
||||
B addCondition(@NotNull String columnName, @NotNull String operator, @Nullable Object queryValue);
|
||||
@NotNull B addCondition(@NotNull String columnName, @NotNull String operator, @Nullable Object queryValue);
|
||||
|
||||
B addCondition(@NotNull String columnName, @Nullable Object queryValue);
|
||||
@NotNull B addCondition(@NotNull String columnName, @Nullable Object queryValue);
|
||||
|
||||
B addCondition(@NotNull String[] columnNames, @Nullable Object[] queryValues);
|
||||
@NotNull B addCondition(@NotNull String[] columnNames, @Nullable Object[] queryValues);
|
||||
|
||||
B addNotNullCondition(@NotNull String columnName);
|
||||
@NotNull B addNotNullCondition(@NotNull String columnName);
|
||||
|
||||
/**
|
||||
* 添加时间的限定条件。 若设定了开始时间,则限定条件为 {@code endMillis >= startMillis};
|
||||
@@ -60,7 +61,7 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
|
||||
* @param endMillis 结束时间戳,若{@code <0}则不作限定
|
||||
* @return {@link B}
|
||||
*/
|
||||
default B addTimeCondition(@NotNull String columnName, long startMillis, long endMillis) {
|
||||
default @NotNull B addTimeCondition(@NotNull String columnName, long startMillis, long endMillis) {
|
||||
return addTimeCondition(columnName,
|
||||
startMillis > 0 ? new Date(startMillis) : null,
|
||||
endMillis > 0 ? new Date(endMillis) : null
|
||||
@@ -75,7 +76,7 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
|
||||
* @param endDate 结束时间,若为null则不作限定
|
||||
* @return {@link B}
|
||||
*/
|
||||
B addTimeCondition(@NotNull String columnName, @Nullable java.util.Date startDate, @Nullable java.util.Date endDate);
|
||||
@NotNull B addTimeCondition(@NotNull String columnName, @Nullable java.util.Date startDate, @Nullable java.util.Date endDate);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
public interface DeleteBuilder extends ConditionalBuilder<DeleteBuilder, SQLAction<Integer>> {
|
||||
import cc.carm.lib.easysql.api.action.update.PreparedSQLUpdateAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
String getTableName();
|
||||
public interface DeleteBuilder<B extends PreparedSQLUpdateAction<Integer, B>>
|
||||
extends ConditionalBuilder<DeleteBuilder<B>, B> {
|
||||
|
||||
@NotNull String getTableName();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public interface InsertBuilder<T> {
|
||||
|
||||
String getTableName();
|
||||
@NotNull String getTableName();
|
||||
|
||||
T columns(List<String> columnNames);
|
||||
@NotNull T columns(List<String> columnNames);
|
||||
|
||||
default T columns(String... columnNames) {
|
||||
default @NotNull T columns(String... columnNames) {
|
||||
return columns(columnNames == null ? null : Arrays.asList(columnNames));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLBuilder;
|
||||
import cc.carm.lib.easysql.api.action.base.QueryAction;
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.query.PreparedSQLQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.query.SQLQueryAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface QueryBuilder extends SQLBuilder {
|
||||
public interface QueryBuilder<Q extends SQLQueryAction<Q>, P extends PreparedSQLQueryAction<P>> extends SQLBuilder {
|
||||
|
||||
/**
|
||||
* 通过一条 SQL语句创建查询。
|
||||
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||
*
|
||||
* @param sql SQL语句
|
||||
* @return {@link QueryAction}
|
||||
* @return {@link SQLQueryAction}
|
||||
* @deprecated 存在SQL注入风险,建议使用 {@link QueryBuilder#withPreparedSQL(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
QueryAction withSQL(@NotNull String sql);
|
||||
@NotNull Q withSQL(@NotNull String sql);
|
||||
|
||||
/**
|
||||
* 通过一条 SQL语句创建预查询
|
||||
*
|
||||
* @param sql SQL语句
|
||||
* @return {@link PreparedQueryAction}
|
||||
* @return {@link PreparedSQLQueryAction}
|
||||
*/
|
||||
PreparedQueryAction withPreparedSQL(@NotNull String sql);
|
||||
@NotNull P withPreparedSQL(@NotNull String sql);
|
||||
|
||||
/**
|
||||
* 创建表查询
|
||||
@@ -32,6 +32,6 @@ public interface QueryBuilder extends SQLBuilder {
|
||||
* @param tableName 表名
|
||||
* @return {@link TableQueryBuilder}
|
||||
*/
|
||||
TableQueryBuilder fromTable(@NotNull String tableName);
|
||||
@NotNull TableQueryBuilder<P> fromTable(@NotNull String tableName);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -10,15 +11,15 @@ import java.util.List;
|
||||
* <br> 执行后,将通过表中键判断该数据是否存在,若存在则用新数据替换原来的值,若不存在则会插入该数据。
|
||||
* <br> 在使用REPLACE时,表与所给行列数据中必须包含唯一索引(或主键),且索引不得为空值,否则将等同于插入语句。
|
||||
*
|
||||
* @param <T> 最终构建出的 {@link SQLAction} 类型
|
||||
* @param <T> 最终构建出的 {@link SQLBaseAction} 类型
|
||||
*/
|
||||
public interface ReplaceBuilder<T extends SQLAction<?>> {
|
||||
public interface ReplaceBuilder<T extends SQLBaseAction<?>> {
|
||||
|
||||
String getTableName();
|
||||
@NotNull String getTableName();
|
||||
|
||||
T columns(List<String> columnNames);
|
||||
@NotNull T columns(List<String> columnNames);
|
||||
|
||||
default T columns(String... columnNames) {
|
||||
default @NotNull T columns(String... columnNames) {
|
||||
return columns(columnNames == null ? null : Arrays.asList(columnNames));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLBuilder;
|
||||
import cc.carm.lib.easysql.api.action.base.UpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||
import cc.carm.lib.easysql.api.enums.NumberType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -9,46 +9,46 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface TableAlterBuilder extends SQLBuilder {
|
||||
|
||||
SQLAction<Integer> renameTo(@NotNull String newTableName);
|
||||
@NotNull SQLAdvancedAction<Integer> renameTo(@NotNull String newTableName);
|
||||
|
||||
SQLAction<Integer> changeComment(@NotNull String newTableComment);
|
||||
@NotNull SQLAdvancedAction<Integer> changeComment(@NotNull String newTableComment);
|
||||
|
||||
SQLAction<Integer> setAutoIncrementIndex(int index);
|
||||
@NotNull SQLAdvancedAction<Integer> setAutoIncrementIndex(int index);
|
||||
|
||||
SQLAction<Integer> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
|
||||
@NotNull String columnName, @NotNull String... moreColumns);
|
||||
@NotNull SQLAdvancedAction<Integer> addIndex(@NotNull IndexType indexType, @Nullable String indexName,
|
||||
@NotNull String columnName, @NotNull String... moreColumns);
|
||||
|
||||
/**
|
||||
* 为该表移除一个索引
|
||||
*
|
||||
* @param indexName 索引名
|
||||
* @return {@link UpdateAction}
|
||||
* @return {@link SQLAdvancedAction}
|
||||
*/
|
||||
SQLAction<Integer> dropIndex(@NotNull String indexName);
|
||||
@NotNull SQLAdvancedAction<Integer> dropIndex(@NotNull String indexName);
|
||||
|
||||
/**
|
||||
* 为该表移除一个外键
|
||||
*
|
||||
* @param keySymbol 外键名
|
||||
* @return {@link UpdateAction}
|
||||
* @return {@link SQLAdvancedAction}
|
||||
*/
|
||||
SQLAction<Integer> dropForeignKey(@NotNull String keySymbol);
|
||||
@NotNull SQLAdvancedAction<Integer> dropForeignKey(@NotNull String keySymbol);
|
||||
|
||||
/**
|
||||
* 为该表移除主键(须添加新主键)
|
||||
*
|
||||
* @return {@link UpdateAction}
|
||||
* @return {@link SQLAdvancedAction}
|
||||
*/
|
||||
SQLAction<Integer> dropPrimaryKey();
|
||||
@NotNull SQLAdvancedAction<Integer> dropPrimaryKey();
|
||||
|
||||
/**
|
||||
* 为表添加一列
|
||||
*
|
||||
* @param columnName 列名
|
||||
* @param settings 列的相关设定
|
||||
* @return {@link UpdateAction}
|
||||
* @return {@link SQLAdvancedAction}
|
||||
*/
|
||||
default SQLAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings) {
|
||||
default @NotNull SQLAdvancedAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings) {
|
||||
return addColumn(columnName, settings, null);
|
||||
}
|
||||
|
||||
@@ -60,23 +60,27 @@ public interface TableAlterBuilder extends SQLBuilder {
|
||||
* @param afterColumn 该列增添到哪个列的后面,
|
||||
* <p> 该参数若省缺则放于最后一行
|
||||
* <p> 若为 "" 则置于首行。
|
||||
* @return {@link UpdateAction}
|
||||
* @return {@link SQLAdvancedAction}
|
||||
*/
|
||||
SQLAction<Integer> addColumn(@NotNull String columnName, @NotNull String settings, @Nullable String afterColumn);
|
||||
@NotNull SQLAdvancedAction<Integer> addColumn(@NotNull String columnName,
|
||||
@NotNull String settings,
|
||||
@Nullable String afterColumn);
|
||||
|
||||
SQLAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName);
|
||||
@NotNull SQLAdvancedAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName);
|
||||
|
||||
SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings);
|
||||
@NotNull SQLAdvancedAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings);
|
||||
|
||||
default SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String columnSettings, @NotNull String afterColumn) {
|
||||
default @NotNull SQLAdvancedAction<Integer> modifyColumn(@NotNull String columnName,
|
||||
@NotNull String columnSettings,
|
||||
@NotNull String afterColumn) {
|
||||
return modifyColumn(columnName, columnSettings + " AFTER `" + afterColumn + "`");
|
||||
}
|
||||
|
||||
SQLAction<Integer> removeColumn(@NotNull String columnName);
|
||||
@NotNull SQLAdvancedAction<Integer> removeColumn(@NotNull String columnName);
|
||||
|
||||
SQLAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue);
|
||||
@NotNull SQLAdvancedAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue);
|
||||
|
||||
SQLAction<Integer> removeColumnDefault(@NotNull String columnName);
|
||||
@NotNull SQLAdvancedAction<Integer> removeColumnDefault(@NotNull String columnName);
|
||||
|
||||
/**
|
||||
* 为该表添加一个自增列
|
||||
@@ -89,8 +93,9 @@ public interface TableAlterBuilder extends SQLBuilder {
|
||||
* @param unsigned 是否采用 UNSIGNED (即无负数,可以增加自增键的最高数,建议为true)
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
|
||||
boolean primary, boolean unsigned) {
|
||||
default @NotNull SQLAdvancedAction<Integer> addAutoIncrementColumn(@NotNull String columnName,
|
||||
@Nullable NumberType numberType,
|
||||
boolean primary, boolean unsigned) {
|
||||
return addColumn(columnName,
|
||||
(numberType == null ? NumberType.INT : numberType).name()
|
||||
+ (unsigned ? " UNSIGNED " : " ")
|
||||
@@ -108,7 +113,8 @@ public interface TableAlterBuilder extends SQLBuilder {
|
||||
* @param numberType 数字类型,若省缺则为 {@link NumberType#INT}
|
||||
* @return {@link TableAlterBuilder}
|
||||
*/
|
||||
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName, @NotNull NumberType numberType) {
|
||||
default @NotNull SQLAdvancedAction<Integer> addAutoIncrementColumn(@NotNull String columnName,
|
||||
@NotNull NumberType numberType) {
|
||||
return addAutoIncrementColumn(columnName, numberType, false, true);
|
||||
}
|
||||
|
||||
@@ -121,7 +127,7 @@ public interface TableAlterBuilder extends SQLBuilder {
|
||||
* @param columnName 列名
|
||||
* @return {@link TableAlterBuilder}
|
||||
*/
|
||||
default SQLAction<Integer> addAutoIncrementColumn(@NotNull String columnName) {
|
||||
default @NotNull SQLAdvancedAction<Integer> addAutoIncrementColumn(@NotNull String columnName) {
|
||||
return addAutoIncrementColumn(columnName, NumberType.INT);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLBuilder;
|
||||
import cc.carm.lib.easysql.api.action.base.UpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.SQLUpdateAction;
|
||||
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
|
||||
import cc.carm.lib.easysql.api.enums.IndexType;
|
||||
import cc.carm.lib.easysql.api.enums.NumberType;
|
||||
@@ -19,9 +19,9 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
/**
|
||||
* 将现有条件构建完整的SQL语句用于执行。
|
||||
*
|
||||
* @return {@link UpdateAction}
|
||||
* @return {@link SQLUpdateAction.Advanced}
|
||||
*/
|
||||
UpdateAction<Integer> build();
|
||||
@NotNull SQLUpdateAction.Advanced<Integer> build();
|
||||
|
||||
@NotNull String getTableName();
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
*/
|
||||
@NotNull String getTableSettings();
|
||||
|
||||
TableCreateBuilder setTableSettings(@NotNull String settings);
|
||||
@NotNull TableCreateBuilder setTableSettings(@NotNull String settings);
|
||||
|
||||
/**
|
||||
* 设定表的标注,一般用于解释该表的作用。
|
||||
@@ -41,7 +41,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param comment 表标注
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
TableCreateBuilder setTableComment(@Nullable String comment);
|
||||
@NotNull TableCreateBuilder setTableComment(@Nullable String comment);
|
||||
|
||||
/**
|
||||
* 直接设定表的所有列信息
|
||||
@@ -49,7 +49,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param columns 列的相关信息 (包括列设定)
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
TableCreateBuilder setColumns(@NotNull String... columns);
|
||||
@NotNull TableCreateBuilder setColumns(@NotNull String... columns);
|
||||
|
||||
/**
|
||||
* 为该表添加一个列
|
||||
@@ -58,7 +58,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* <br>如 `uuid` VARCHAR(36) NOT NULL UNIQUE KEY
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
TableCreateBuilder addColumn(@NotNull String column);
|
||||
@NotNull TableCreateBuilder addColumn(@NotNull String column);
|
||||
|
||||
/**
|
||||
* 为该表添加一个列
|
||||
@@ -68,7 +68,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* <br>如 VARCHAR(36) NOT NULL UNIQUE KEY
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder addColumn(@NotNull String columnName, @NotNull String settings) {
|
||||
default @NotNull TableCreateBuilder addColumn(@NotNull String columnName, @NotNull String settings) {
|
||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||
return addColumn(withBackQuote(columnName) + " " + settings);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param comments 列的注解,用于解释该列数据的作用
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder addColumn(@NotNull String columnName, @NotNull String settings, @NotNull String comments) {
|
||||
default @NotNull TableCreateBuilder addColumn(@NotNull String columnName, @NotNull String settings, @NotNull String comments) {
|
||||
return addColumn(columnName, settings + " COMMENT " + withQuote(comments));
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param unsigned 是否采用 UNSIGNED (即无负数,可以增加自增键的最高数,建议为true)
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
|
||||
boolean asPrimaryKey, boolean unsigned);
|
||||
@NotNull TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
|
||||
boolean asPrimaryKey, boolean unsigned);
|
||||
|
||||
/**
|
||||
* 为该表添加一个INT类型的自增主键列
|
||||
@@ -110,8 +110,8 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param unsigned 是否采用 UNSIGNED (即无负数,可以增加自增键的最高数,建议为true)
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName,
|
||||
boolean asPrimaryKey, boolean unsigned) {
|
||||
default @NotNull TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName,
|
||||
boolean asPrimaryKey, boolean unsigned) {
|
||||
return addAutoIncrementColumn(columnName, NumberType.INT, asPrimaryKey, unsigned);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param asPrimaryKey 是否为主键,若为false则设定为唯一键
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, boolean asPrimaryKey) {
|
||||
default @NotNull TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, boolean asPrimaryKey) {
|
||||
return addAutoIncrementColumn(columnName, asPrimaryKey, true);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param columnName 列名
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName) {
|
||||
default @NotNull TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName) {
|
||||
return addAutoIncrementColumn(columnName, true);
|
||||
}
|
||||
|
||||
@@ -152,8 +152,8 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param columnName 索引包含的列
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder setIndex(@NotNull String columnName,
|
||||
@NotNull IndexType type) {
|
||||
default @NotNull TableCreateBuilder setIndex(@NotNull String columnName,
|
||||
@NotNull IndexType type) {
|
||||
return setIndex(type, null, columnName);
|
||||
}
|
||||
|
||||
@@ -170,8 +170,8 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param moreColumns 联合索引需要包含的列
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
TableCreateBuilder setIndex(@NotNull IndexType type, @Nullable String indexName,
|
||||
@NotNull String columnName, @NotNull String... moreColumns);
|
||||
@NotNull TableCreateBuilder setIndex(@NotNull IndexType type, @Nullable String indexName,
|
||||
@NotNull String columnName, @NotNull String... moreColumns);
|
||||
|
||||
|
||||
/**
|
||||
@@ -185,7 +185,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param foreignColumn 外键关联表中对应的关联列,必须为目标表的主键,即 {@link IndexType#PRIMARY_KEY}
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder addForeignKey(@NotNull String tableColumn, @NotNull String foreignColumn) {
|
||||
default @NotNull TableCreateBuilder addForeignKey(@NotNull String tableColumn, @NotNull String foreignColumn) {
|
||||
return addForeignKey(tableColumn, getTableName(), foreignColumn);
|
||||
}
|
||||
|
||||
@@ -203,8 +203,8 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* <p> 2. 数据类型必须和所要建立主键的列的数据类型相同。
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder addForeignKey(@NotNull String tableColumn,
|
||||
@NotNull String foreignTable, @NotNull String foreignColumn) {
|
||||
default @NotNull TableCreateBuilder addForeignKey(@NotNull String tableColumn,
|
||||
@NotNull String foreignTable, @NotNull String foreignColumn) {
|
||||
return addForeignKey(tableColumn, null, foreignTable, foreignColumn);
|
||||
}
|
||||
|
||||
@@ -223,8 +223,8 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* <p> 2. 数据类型必须和所要建立主键的列的数据类型相同。
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
default TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName,
|
||||
@NotNull String foreignTable, @NotNull String foreignColumn) {
|
||||
default @NotNull TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName,
|
||||
@NotNull String foreignTable, @NotNull String foreignColumn) {
|
||||
return addForeignKey(tableColumn, constraintName, foreignTable, foreignColumn, null, null);
|
||||
}
|
||||
|
||||
@@ -245,9 +245,9 @@ public interface TableCreateBuilder extends SQLBuilder {
|
||||
* @param deleteRule 在外键被删除时采用的规则,缺省时默认为{@link ForeignKeyRule#RESTRICT}
|
||||
* @return {@link TableCreateBuilder}
|
||||
*/
|
||||
TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName,
|
||||
@NotNull String foreignTable, @NotNull String foreignColumn,
|
||||
@Nullable ForeignKeyRule updateRule, @Nullable ForeignKeyRule deleteRule);
|
||||
@NotNull TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName,
|
||||
@NotNull String foreignTable, @NotNull String foreignColumn,
|
||||
@Nullable ForeignKeyRule updateRule, @Nullable ForeignKeyRule deleteRule);
|
||||
|
||||
default String defaultTablesSettings() {
|
||||
return "ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.query.PreparedSQLQueryAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface TableQueryBuilder extends ConditionalBuilder<TableQueryBuilder, PreparedQueryAction> {
|
||||
public interface TableQueryBuilder<B extends PreparedSQLQueryAction<B>>
|
||||
extends ConditionalBuilder<TableQueryBuilder<B>, B> {
|
||||
|
||||
@NotNull String getTableName();
|
||||
|
||||
@@ -13,7 +14,7 @@ public interface TableQueryBuilder extends ConditionalBuilder<TableQueryBuilder,
|
||||
* @param columnNames 列名
|
||||
* @return {@link TableQueryBuilder}
|
||||
*/
|
||||
TableQueryBuilder select(@NotNull String... columnNames);
|
||||
TableQueryBuilder<B> select(@NotNull String... columnNames);
|
||||
|
||||
/**
|
||||
* 对结果进行排序
|
||||
@@ -22,7 +23,7 @@ public interface TableQueryBuilder extends ConditionalBuilder<TableQueryBuilder,
|
||||
* @param asc 是否为正序排序 (为false则倒序排序)
|
||||
* @return {@link TableQueryBuilder}
|
||||
*/
|
||||
TableQueryBuilder orderBy(@NotNull String columnName, boolean asc);
|
||||
TableQueryBuilder<B> orderBy(@NotNull String columnName, boolean asc);
|
||||
|
||||
/**
|
||||
* 限制查询条数,用于分页查询。
|
||||
@@ -32,6 +33,6 @@ public interface TableQueryBuilder extends ConditionalBuilder<TableQueryBuilder,
|
||||
* @return {@link TableQueryBuilder}
|
||||
* @since 0.2.6
|
||||
*/
|
||||
TableQueryBuilder limit(int start, int end);
|
||||
TableQueryBuilder<B> limit(int start, int end);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.update.PreparedSQLUpdateAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLAction<Integer>> {
|
||||
public interface UpdateBuilder<B extends PreparedSQLUpdateAction<Integer, B>>
|
||||
extends ConditionalBuilder<UpdateBuilder<B>, B> {
|
||||
|
||||
String getTableName();
|
||||
|
||||
@@ -17,7 +19,7 @@ public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLActi
|
||||
* @return {@link UpdateBuilder}
|
||||
* @since 0.3.7
|
||||
*/
|
||||
UpdateBuilder set(@NotNull String columnName, @Nullable Object columnValue);
|
||||
UpdateBuilder<B> set(@NotNull String columnName, @Nullable Object columnValue);
|
||||
|
||||
/**
|
||||
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
||||
@@ -26,7 +28,7 @@ public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLActi
|
||||
* @param columnData 字段名和值的键值对
|
||||
* @return {@link UpdateBuilder}
|
||||
*/
|
||||
UpdateBuilder setAll(LinkedHashMap<@NotNull String, @Nullable Object> columnData);
|
||||
UpdateBuilder<B> setAll(LinkedHashMap<@NotNull String, @Nullable Object> columnData);
|
||||
|
||||
/**
|
||||
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
||||
@@ -36,7 +38,7 @@ public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLActi
|
||||
* @param columnValues 字段名对应的值
|
||||
* @return {@link UpdateBuilder}
|
||||
*/
|
||||
UpdateBuilder setAll(@NotNull String[] columnNames, @Nullable Object[] columnValues);
|
||||
UpdateBuilder<B> setAll(@NotNull String[] columnNames, @Nullable Object[] columnValues);
|
||||
|
||||
/**
|
||||
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
||||
@@ -47,9 +49,8 @@ public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLActi
|
||||
* @param columnValue 字段名对应的值
|
||||
* @return {@link UpdateBuilder}
|
||||
*/
|
||||
default UpdateBuilder setAll(@NotNull String columnName, @Nullable Object columnValue) {
|
||||
default UpdateBuilder<B> setAll(@NotNull String columnName, @Nullable Object columnValue) {
|
||||
return setAll(new String[]{columnName}, new Object[]{columnValue});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
/**
|
||||
* 存在则更新,不存在则插入。
|
||||
*
|
||||
* @see ReplaceBuilder
|
||||
*/
|
||||
@Deprecated
|
||||
public interface UpsertBuilder {
|
||||
|
||||
String getTableName();
|
||||
|
||||
default UpsertBuilder setColumnNames(String[] columnNames, String updateColumn) {
|
||||
throw new UnsupportedOperationException("Please use REPLACE .");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cc.carm.lib.easysql.api.function;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedUpdateAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -14,19 +14,19 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 异常处理器。
|
||||
* <br> 在使用 {@link SQLAction#execute(SQLExceptionHandler)} 等相关方法时,
|
||||
* <br> 在使用 {@link SQLBaseAction#execute(SQLExceptionHandler)} 等相关方法时,
|
||||
* 如果发生异常,则会调用错误处理器进行错误内容的输出提示。
|
||||
*/
|
||||
|
||||
public interface SQLDebugHandler {
|
||||
/**
|
||||
* 该方法将在 {@link SQLAction#execute()} 执行前调用。
|
||||
* 该方法将在 {@link SQLBaseAction#execute()} 执行前调用。
|
||||
*
|
||||
* @param action {@link SQLAction} 对象
|
||||
* @param action {@link SQLBaseAction} 对象
|
||||
* @param params 执行传入的参数列表。
|
||||
* 实际上,仅有 {@link PreparedUpdateAction} 和 {@link PreparedBatchUpdateAction} 才会有传入参数。
|
||||
*/
|
||||
void beforeExecute(@NotNull SQLAction<?> action, @NotNull List<@Nullable Object[]> params);
|
||||
void beforeExecute(@NotNull SQLBaseAction<?> action, @NotNull List<@Nullable Object[]> params);
|
||||
|
||||
/**
|
||||
* 该方法将在 {@link SQLQuery#close()} 执行后调用。
|
||||
@@ -54,7 +54,7 @@ public interface SQLDebugHandler {
|
||||
return new SQLDebugHandler() {
|
||||
|
||||
@Override
|
||||
public void beforeExecute(@NotNull SQLAction<?> action, @NotNull List<@Nullable Object[]> params) {
|
||||
public void beforeExecute(@NotNull SQLBaseAction<?> action, @NotNull List<@Nullable Object[]> params) {
|
||||
logger.info("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
||||
logger.info("┣# 操作编号: {}", action.getActionUUID());
|
||||
logger.info("┣# 操作类型: {}", action.getClass().getSimpleName());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.carm.lib.easysql.api.function;
|
||||
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLAdvancedAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.sql.SQLException;
|
||||
@@ -8,11 +9,11 @@ import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* 异常处理器。
|
||||
* <br> 在使用 {@link SQLAction#execute(SQLExceptionHandler)} 等相关方法时,
|
||||
* <br> 在使用 {@link SQLAdvancedAction#execute(SQLExceptionHandler)} 等相关方法时,
|
||||
* 如果发生异常,则会调用错误处理器进行错误内容的输出提示。
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface SQLExceptionHandler extends BiConsumer<SQLException, SQLAction<?>> {
|
||||
public interface SQLExceptionHandler extends BiConsumer<SQLException, SQLBaseAction<?>> {
|
||||
|
||||
/**
|
||||
* 默认的异常处理器,将详细的输出相关错误与错误来源。
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package cc.carm.lib.easysql.api.table;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.action.asyncable.AsyncablePreparedBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.asyncable.AsyncablePreparedUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.PreparedSQLBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.PreparedSQLUpdateAction;
|
||||
import cc.carm.lib.easysql.api.builder.*;
|
||||
import cc.carm.lib.easysql.api.function.SQLHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -100,40 +100,40 @@ public interface SQLTable {
|
||||
return sqlManager.updateInto(getTableName());
|
||||
}
|
||||
|
||||
default @NotNull InsertBuilder<AsyncablePreparedUpdateAction<Integer>> createInsert() {
|
||||
default @NotNull InsertBuilder<PreparedSQLUpdateAction.Advanced<Integer>> createInsert() {
|
||||
return Optional.ofNullable(getSQLManager()).map(this::createInsert)
|
||||
.orElseThrow(() -> new NullPointerException("This table doesn't have a SQLManger."));
|
||||
}
|
||||
|
||||
default @NotNull InsertBuilder<AsyncablePreparedUpdateAction<Integer>> createInsert(@NotNull SQLManager sqlManager) {
|
||||
default @NotNull InsertBuilder<PreparedSQLUpdateAction.Advanced<Integer>> createInsert(@NotNull SQLManager sqlManager) {
|
||||
return sqlManager.insertInto(getTableName());
|
||||
}
|
||||
|
||||
default @NotNull InsertBuilder<AsyncablePreparedBatchUpdateAction<Integer>> createInsertBatch() {
|
||||
default @NotNull InsertBuilder<PreparedSQLBatchUpdateAction.Advanced<Integer>> createInsertBatch() {
|
||||
return Optional.ofNullable(getSQLManager()).map(this::createInsertBatch)
|
||||
.orElseThrow(() -> new NullPointerException("This table doesn't have a SQLManger."));
|
||||
}
|
||||
|
||||
default @NotNull InsertBuilder<AsyncablePreparedBatchUpdateAction<Integer>> createInsertBatch(@NotNull SQLManager sqlManager) {
|
||||
default @NotNull InsertBuilder<PreparedSQLBatchUpdateAction.Advanced<Integer>> createInsertBatch(@NotNull SQLManager sqlManager) {
|
||||
return sqlManager.insertBatchInto(getTableName());
|
||||
}
|
||||
|
||||
default @NotNull ReplaceBuilder<AsyncablePreparedUpdateAction<Integer>> createReplace() {
|
||||
default @NotNull ReplaceBuilder<PreparedSQLUpdateAction.Advanced<Integer>> createReplace() {
|
||||
return Optional.ofNullable(getSQLManager()).map(this::createReplace)
|
||||
.orElseThrow(() -> new NullPointerException("This table doesn't have a SQLManger."));
|
||||
|
||||
}
|
||||
|
||||
default @NotNull ReplaceBuilder<AsyncablePreparedUpdateAction<Integer>> createReplace(@NotNull SQLManager sqlManager) {
|
||||
default @NotNull ReplaceBuilder<PreparedSQLUpdateAction.Advanced<Integer>> createReplace(@NotNull SQLManager sqlManager) {
|
||||
return sqlManager.replaceInto(getTableName());
|
||||
}
|
||||
|
||||
default @NotNull ReplaceBuilder<AsyncablePreparedBatchUpdateAction<Integer>> createReplaceBatch() {
|
||||
default @NotNull ReplaceBuilder<PreparedSQLBatchUpdateAction.Advanced<Integer>> createReplaceBatch() {
|
||||
return Optional.ofNullable(getSQLManager()).map(this::createReplaceBatch)
|
||||
.orElseThrow(() -> new NullPointerException("This table doesn't have a SQLManger."));
|
||||
}
|
||||
|
||||
default @NotNull ReplaceBuilder<AsyncablePreparedBatchUpdateAction<Integer>> createReplaceBatch(@NotNull SQLManager sqlManager) {
|
||||
default @NotNull ReplaceBuilder<PreparedSQLBatchUpdateAction.Advanced<Integer>> createReplaceBatch(@NotNull SQLManager sqlManager) {
|
||||
return sqlManager.replaceBatchInto(getTableName());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package cc.carm.lib.easysql.api.transaction;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.base.PreparedUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.base.BatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.base.UpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.query.PreparedSQLQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.query.SQLQueryAction;
|
||||
import cc.carm.lib.easysql.api.action.update.PreparedSQLBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.PreparedSQLUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.SQLBatchUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.update.SQLUpdateAction;
|
||||
import cc.carm.lib.easysql.api.builder.*;
|
||||
import cc.carm.lib.easysql.api.enums.IsolationLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -56,7 +58,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
*
|
||||
* @param sql SQL语句内容
|
||||
* @return 更新的行数
|
||||
* @see UpdateAction
|
||||
* @see SQLUpdateAction
|
||||
*/
|
||||
@Nullable Integer executeSQL(String sql);
|
||||
|
||||
@@ -66,7 +68,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param sql SQL语句内容
|
||||
* @param params SQL语句中 ? 的对应参数
|
||||
* @return 更新的行数
|
||||
* @see PreparedUpdateAction
|
||||
* @see PreparedSQLUpdateAction
|
||||
*/
|
||||
@Nullable Integer executeSQL(String sql, Object[] params);
|
||||
|
||||
@@ -76,7 +78,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param sql SQL语句内容
|
||||
* @param paramsBatch SQL语句中对应?的参数组
|
||||
* @return 对应参数返回的行数
|
||||
* @see PreparedBatchUpdateAction
|
||||
* @see PreparedSQLBatchUpdateAction
|
||||
*/
|
||||
@Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
|
||||
|
||||
@@ -87,7 +89,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param sql SQL语句内容
|
||||
* @param moreSQL 更多SQL语句内容
|
||||
* @return 对应参数返回的行数
|
||||
* @see BatchUpdateAction
|
||||
* @see SQLBatchUpdateAction
|
||||
*/
|
||||
@Nullable List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL);
|
||||
|
||||
@@ -104,7 +106,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
*
|
||||
* @return {@link QueryBuilder}
|
||||
*/
|
||||
@NotNull QueryBuilder createQuery();
|
||||
@NotNull QueryBuilder<SQLQueryAction.Base, PreparedSQLQueryAction.Base> createQuery();
|
||||
|
||||
/**
|
||||
* 创建一条插入操作。
|
||||
@@ -112,7 +114,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link InsertBuilder}
|
||||
*/
|
||||
@NotNull InsertBuilder<PreparedUpdateAction<Integer>> insertInto(@NotNull String tableName);
|
||||
@NotNull InsertBuilder<PreparedSQLUpdateAction.Base<Integer>> insertInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建支持多组数据的插入操作。
|
||||
@@ -120,7 +122,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link InsertBuilder}
|
||||
*/
|
||||
@NotNull InsertBuilder<PreparedBatchUpdateAction<Integer>> insertBatchInto(@NotNull String tableName);
|
||||
@NotNull InsertBuilder<PreparedSQLBatchUpdateAction.Base<Integer>> insertBatchInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建一条替换操作。
|
||||
@@ -128,7 +130,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link ReplaceBuilder}
|
||||
*/
|
||||
@NotNull ReplaceBuilder<PreparedUpdateAction<Integer>> replaceInto(@NotNull String tableName);
|
||||
@NotNull ReplaceBuilder<PreparedSQLUpdateAction.Base<Integer>> replaceInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建支持多组数据的替换操作。
|
||||
@@ -136,7 +138,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link ReplaceBuilder}
|
||||
*/
|
||||
@NotNull ReplaceBuilder<PreparedBatchUpdateAction<Integer>> replaceBatchInto(@NotNull String tableName);
|
||||
@NotNull ReplaceBuilder<PreparedSQLBatchUpdateAction.Base<Integer>> replaceBatchInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建更新操作。
|
||||
@@ -144,7 +146,7 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link UpdateBuilder}
|
||||
*/
|
||||
@NotNull UpdateBuilder updateInto(@NotNull String tableName);
|
||||
@NotNull UpdateBuilder<PreparedSQLUpdateAction.Base<Integer>> updateInto(@NotNull String tableName);
|
||||
|
||||
/**
|
||||
* 创建删除操作。
|
||||
@@ -152,6 +154,6 @@ public interface SQLTransaction extends AutoCloseable {
|
||||
* @param tableName 目标表名
|
||||
* @return {@link DeleteBuilder}
|
||||
*/
|
||||
@NotNull DeleteBuilder deleteFrom(@NotNull String tableName);
|
||||
@NotNull DeleteBuilder<PreparedSQLUpdateAction.Base<Integer>> deleteFrom(@NotNull String tableName);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cc.carm.lib.easysql.api.transaction;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLSource;
|
||||
import cc.carm.lib.easysql.api.action.SQLAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLBaseAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface TransactionAction<T> extends SQLAction<T> {
|
||||
public interface TransactionAction<T> extends SQLBaseAction<T> {
|
||||
|
||||
@NotNull SQLTransaction getTransaction();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user