mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-04 23:41:15 +08:00
feat(sql): 预备支持事务(v0.5.0)
This commit is contained in:
@@ -0,0 +1,152 @@
|
|||||||
|
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.SQLBiFunction;
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public interface NewSQLManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到用于该管理器的 {@link SQLSource}
|
||||||
|
*
|
||||||
|
* @return {@link SQLSource}
|
||||||
|
*/
|
||||||
|
@NotNull SQLSource getSource();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取并操作 {@link DatabaseMetaData} 以得到需要的数据库消息。
|
||||||
|
*
|
||||||
|
* @param reader 操作与读取的方法
|
||||||
|
* @param <R> 最终结果的返回类型
|
||||||
|
* @return 最终结果,通过 {@link CompletableFuture#get()} 可阻塞并等待结果返回。
|
||||||
|
*/
|
||||||
|
default <R> CompletableFuture<R> fetchMetadata(@NotNull SQLFunction<DatabaseMetaData, R> reader) {
|
||||||
|
return fetchMetadata((meta, conn) -> reader.apply(meta));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取并操作 {@link DatabaseMetaData} 提供的指定 {@link ResultSet} 以得到需要的数据库消息。
|
||||||
|
* <br> 该方法会自动关闭 {@link ResultSet} 。
|
||||||
|
*
|
||||||
|
* @param supplier 操作 {@link DatabaseMetaData} 以提供信息所在的 {@link ResultSet}
|
||||||
|
* @param reader 读取 {@link ResultSet} 中指定信息的方法
|
||||||
|
* @param <R> 最终结果的返回类型
|
||||||
|
* @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) {
|
||||||
|
return fetchMetadata((meta, conn) -> supplier.apply(meta), reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取并操作 {@link DatabaseMetaData} 以得到需要的数据库消息。
|
||||||
|
*
|
||||||
|
* @param reader 操作与读取的方法
|
||||||
|
* @param <R> 最终结果的返回类型
|
||||||
|
* @return 最终结果,通过 {@link CompletableFuture#get()} 可阻塞并等待结果返回。
|
||||||
|
*/
|
||||||
|
<R> CompletableFuture<R> fetchMetadata(@NotNull SQLBiFunction<DatabaseMetaData, Connection, R> reader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取并操作 {@link DatabaseMetaData} 提供的指定 {@link ResultSet} 以得到需要的数据库消息。
|
||||||
|
* <br> 该方法会自动关闭 {@link ResultSet} 。
|
||||||
|
*
|
||||||
|
* @param supplier 操作 {@link DatabaseMetaData} 以提供信息所在的 {@link ResultSet}
|
||||||
|
* @param reader 读取 {@link ResultSet} 中指定信息的方法
|
||||||
|
* @param <R> 最终结果的返回类型
|
||||||
|
* @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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在库中创建一个表。
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return {@link TableCreateBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull TableCreateBuilder createTable(@NotNull String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对库中的某个表执行更改。
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return {@link TableAlterBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull TableAlterBuilder alterTable(@NotNull String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 快速获取表的部分元数据。
|
||||||
|
* <br> 当需要获取其他元数据时,请使用 {@link #fetchMetadata(SQLFunction, SQLFunction)} 方法。
|
||||||
|
*
|
||||||
|
* @param tablePattern 表名通配符
|
||||||
|
* @return {@link TableMetadataBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull TableMetadataBuilder fetchTableMetadata(@NotNull String tablePattern);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建一个查询。
|
||||||
|
*
|
||||||
|
* @return {@link QueryBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull QueryBuilder createQuery();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一条插入操作。
|
||||||
|
*
|
||||||
|
* @param tableName 目标表名
|
||||||
|
* @return {@link InsertBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull InsertBuilder<PreparedSQLUpdateAction<Integer>> insertInto(@NotNull String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建支持多组数据的插入操作。
|
||||||
|
*
|
||||||
|
* @param tableName 目标表名
|
||||||
|
* @return {@link InsertBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull InsertBuilder<PreparedSQLUpdateBatchAction<Integer>> insertBatchInto(@NotNull String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一条替换操作。
|
||||||
|
*
|
||||||
|
* @param tableName 目标表名
|
||||||
|
* @return {@link ReplaceBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull ReplaceBuilder<PreparedSQLUpdateAction<Integer>> replaceInto(@NotNull String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建支持多组数据的替换操作。
|
||||||
|
*
|
||||||
|
* @param tableName 目标表名
|
||||||
|
* @return {@link ReplaceBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull ReplaceBuilder<PreparedSQLUpdateBatchAction<Integer>> replaceBatchInto(@NotNull String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建更新操作。
|
||||||
|
*
|
||||||
|
* @param tableName 目标表名
|
||||||
|
* @return {@link UpdateBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull UpdateBuilder updateInto(@NotNull String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建删除操作。
|
||||||
|
*
|
||||||
|
* @param tableName 目标表名
|
||||||
|
* @return {@link DeleteBuilder}
|
||||||
|
*/
|
||||||
|
@NotNull DeleteBuilder deleteFrom(@NotNull String tableName);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,9 +35,6 @@ public interface SQLManager {
|
|||||||
|
|
||||||
Logger getLogger();
|
Logger getLogger();
|
||||||
|
|
||||||
boolean isDebugMode();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用于执行 {@link SQLAction#executeAsync()} 的线程池。
|
* 获取用于执行 {@link SQLAction#executeAsync()} 的线程池。
|
||||||
* <br> 默认线程池为 {@link #defaultExecutorPool(String)} 。
|
* <br> 默认线程池为 {@link #defaultExecutorPool(String)} 。
|
||||||
@@ -62,6 +59,7 @@ public interface SQLManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isDebugMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定是否启用调试模式。
|
* 设定是否启用调试模式。
|
||||||
|
|||||||
@@ -0,0 +1,175 @@
|
|||||||
|
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.action.SQLUpdateAction;
|
||||||
|
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLDebugHandler;
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public interface SQLSource {
|
||||||
|
|
||||||
|
Logger getLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用于执行 {@link SQLAction#executeAsync()} 的线程池。
|
||||||
|
* <br> 默认线程池为 {@link #defaultExecutorPool(String)} 。
|
||||||
|
*
|
||||||
|
* @return {@link ExecutorService}
|
||||||
|
*/
|
||||||
|
@NotNull ExecutorService getExecutorPool();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设定用于执行 {@link SQLAction#executeAsync()} 的线程池.
|
||||||
|
* <br> 默认线程池为 {@link #defaultExecutorPool(String)} 。
|
||||||
|
*
|
||||||
|
* @param executorPool {@link ExecutorService}
|
||||||
|
*/
|
||||||
|
void setExecutorPool(@NotNull ExecutorService executorPool);
|
||||||
|
|
||||||
|
static @NotNull ExecutorService defaultExecutorPool(@NotNull String threadName) {
|
||||||
|
return Executors.newFixedThreadPool(4, r -> {
|
||||||
|
Thread thread = new Thread(r, threadName);
|
||||||
|
thread.setDaemon(true);
|
||||||
|
return thread;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isDebugMode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设定是否启用调试模式。
|
||||||
|
* 启用调试模式后,会在每次执行SQL语句时,调用 {@link #getDebugHandler()} 来输出调试信息。
|
||||||
|
*
|
||||||
|
* @param debugMode 是否启用调试模式
|
||||||
|
*/
|
||||||
|
void setDebugMode(@NotNull Supplier<@NotNull Boolean> debugMode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设定是否启用调试模式。
|
||||||
|
* 启用调试模式后,会在每次执行SQL语句时,调用 {@link #getDebugHandler()} 来输出调试信息。
|
||||||
|
*
|
||||||
|
* @param enable 是否启用调试模式
|
||||||
|
*/
|
||||||
|
default void setDebugMode(boolean enable) {
|
||||||
|
setDebugMode(() -> enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取调试处理器,用于处理调试信息。
|
||||||
|
*
|
||||||
|
* @return {@link SQLDebugHandler}
|
||||||
|
*/
|
||||||
|
@NotNull SQLDebugHandler getDebugHandler();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设定调试处理器,默认为 {@link SQLDebugHandler#defaultHandler(Logger)} 。
|
||||||
|
*
|
||||||
|
* @param debugHandler {@link SQLDebugHandler}
|
||||||
|
*/
|
||||||
|
void setDebugHandler(@NotNull SQLDebugHandler debugHandler);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到连接池源
|
||||||
|
*
|
||||||
|
* @return DataSource
|
||||||
|
*/
|
||||||
|
@NotNull DataSource getDataSource();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到一个数据库连接实例
|
||||||
|
*
|
||||||
|
* @return Connection
|
||||||
|
* @throws SQLException 见 {@link DataSource#getConnection()}
|
||||||
|
*/
|
||||||
|
@NotNull Connection getConnection() throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到正使用的查询。
|
||||||
|
*
|
||||||
|
* @return 查询列表
|
||||||
|
*/
|
||||||
|
@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方法)
|
||||||
|
* 该方法使用 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 PreparedSQLUpdateBatchAction
|
||||||
|
*/
|
||||||
|
@Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行多条不需要返回结果的SQL。
|
||||||
|
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||||
|
*
|
||||||
|
* @param sql SQL语句内容
|
||||||
|
* @param moreSQL 更多SQL语句内容
|
||||||
|
* @return 对应参数返回的行数
|
||||||
|
* @see SQLUpdateBatchAction
|
||||||
|
*/
|
||||||
|
@Nullable List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行多条不需要返回结果的SQL。
|
||||||
|
*
|
||||||
|
* @param sqlBatch SQL语句内容
|
||||||
|
* @return 对应参数返回的行数
|
||||||
|
*/
|
||||||
|
@Nullable List<Integer> executeSQLBatch(@NotNull Iterable<String> sqlBatch);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -45,7 +45,7 @@ public interface SQLTable {
|
|||||||
static @NotNull NamedSQLTable of(@NotNull String tableName,
|
static @NotNull NamedSQLTable of(@NotNull String tableName,
|
||||||
@NotNull String[] columns, @Nullable String tableSettings) {
|
@NotNull String[] columns, @Nullable String tableSettings) {
|
||||||
return of(tableName, builder -> {
|
return of(tableName, builder -> {
|
||||||
builder.setColumns(columns);
|
builder.columns(columns);
|
||||||
if (tableSettings != null) builder.setTableSettings(tableSettings);
|
if (tableSettings != null) builder.setTableSettings(tableSettings);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ public interface SQLTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default @NotNull TableQueryBuilder createQuery(@NotNull SQLManager sqlManager) {
|
default @NotNull TableQueryBuilder createQuery(@NotNull SQLManager sqlManager) {
|
||||||
return sqlManager.createQuery().inTable(getTableName());
|
return sqlManager.createQuery().fromTable(getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
default @NotNull DeleteBuilder createDelete() {
|
default @NotNull DeleteBuilder createDelete() {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public interface PreparedSQLUpdateAction<T extends Number> extends SQLUpdateActi
|
|||||||
* @param params 参数内容
|
* @param params 参数内容
|
||||||
* @return {@link PreparedSQLUpdateAction}
|
* @return {@link PreparedSQLUpdateAction}
|
||||||
*/
|
*/
|
||||||
PreparedSQLUpdateAction<T> setParams(Object... params);
|
PreparedSQLUpdateAction<T> params(Object... params);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定SQL语句中所有 ? 对应的参数
|
* 设定SQL语句中所有 ? 对应的参数
|
||||||
@@ -19,6 +19,6 @@ public interface PreparedSQLUpdateAction<T extends Number> extends SQLUpdateActi
|
|||||||
* @return {@link PreparedSQLUpdateAction}
|
* @return {@link PreparedSQLUpdateAction}
|
||||||
* @since 0.4.0
|
* @since 0.4.0
|
||||||
*/
|
*/
|
||||||
PreparedSQLUpdateAction<T> setParams(@Nullable Iterable<Object> params);
|
PreparedSQLUpdateAction<T> params(@Nullable Iterable<Object> params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package cc.carm.lib.easysql.api.action;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
|
||||||
|
public class SQLTransaction implements SQLManager {
|
||||||
|
|
||||||
|
public SQLTransaction savepoint() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SQLTransaction releaseSavepoint() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SQLTransaction rollbackToSavepoint() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
|
|||||||
* @param limit 条数限制
|
* @param limit 条数限制
|
||||||
* @return {@link B}
|
* @return {@link B}
|
||||||
*/
|
*/
|
||||||
B setLimit(int limit);
|
B limit(int limit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 直接设定条件的源文本,不需要以WHERE开头。
|
* 直接设定条件的源文本,不需要以WHERE开头。
|
||||||
@@ -32,7 +32,7 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
|
|||||||
* @param condition 条件文本,不需要以WHERE开头。
|
* @param condition 条件文本,不需要以WHERE开头。
|
||||||
* @return {@link B}
|
* @return {@link B}
|
||||||
*/
|
*/
|
||||||
B setConditions(@Nullable String condition);
|
B where(@Nullable String condition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 直接设定每个条件的文本与其对应数值,将以AND链接,且不需要以WHERE开头。
|
* 直接设定每个条件的文本与其对应数值,将以AND链接,且不需要以WHERE开头。
|
||||||
@@ -41,7 +41,7 @@ public interface ConditionalBuilder<B extends ConditionalBuilder<B, T>, T extend
|
|||||||
* @param conditionSQLs 条件内容,将以AND链接,且不需要以WHERE开头。
|
* @param conditionSQLs 条件内容,将以AND链接,且不需要以WHERE开头。
|
||||||
* @return {@link B}
|
* @return {@link B}
|
||||||
*/
|
*/
|
||||||
B setConditions(LinkedHashMap<@NotNull String, @Nullable Object> conditionSQLs);
|
B where(LinkedHashMap<@NotNull String, @Nullable Object> conditionSQLs);
|
||||||
|
|
||||||
B addCondition(@Nullable String condition);
|
B addCondition(@Nullable String condition);
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ public interface InsertBuilder<T extends SQLAction<?>> {
|
|||||||
|
|
||||||
String getTableName();
|
String getTableName();
|
||||||
|
|
||||||
T setColumnNames(List<String> columnNames);
|
T columns(List<String> columnNames);
|
||||||
|
|
||||||
default T setColumnNames(String... columnNames) {
|
default T columns(String... columnNames) {
|
||||||
return setColumnNames(columnNames == null ? null : Arrays.asList(columnNames));
|
return columns(columnNames == null ? null : Arrays.asList(columnNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ public interface QueryBuilder extends SQLBuilder {
|
|||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @return {@link TableQueryBuilder}
|
* @return {@link TableQueryBuilder}
|
||||||
*/
|
*/
|
||||||
TableQueryBuilder inTable(@NotNull String tableName);
|
TableQueryBuilder fromTable(@NotNull String tableName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ public interface ReplaceBuilder<T extends SQLAction<?>> {
|
|||||||
|
|
||||||
String getTableName();
|
String getTableName();
|
||||||
|
|
||||||
T setColumnNames(List<String> columnNames);
|
T columns(List<String> columnNames);
|
||||||
|
|
||||||
default T setColumnNames(String... columnNames) {
|
default T columns(String... columnNames) {
|
||||||
return setColumnNames(columnNames == null ? null : Arrays.asList(columnNames));
|
return columns(columnNames == null ? null : Arrays.asList(columnNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public interface TableCreateBuilder extends SQLBuilder {
|
|||||||
* @param columns 列的相关信息 (包括列设定)
|
* @param columns 列的相关信息 (包括列设定)
|
||||||
* @return {@link TableCreateBuilder}
|
* @return {@link TableCreateBuilder}
|
||||||
*/
|
*/
|
||||||
TableCreateBuilder setColumns(@NotNull String... columns);
|
TableCreateBuilder columns(@NotNull String... columns);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为该表添加一个列
|
* 为该表添加一个列
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public interface TableQueryBuilder extends ConditionalBuilder<TableQueryBuilder,
|
|||||||
* @param columnNames 列名
|
* @param columnNames 列名
|
||||||
* @return {@link TableQueryBuilder}
|
* @return {@link TableQueryBuilder}
|
||||||
*/
|
*/
|
||||||
TableQueryBuilder selectColumns(@NotNull String... columnNames);
|
TableQueryBuilder select(@NotNull String... columnNames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对结果进行排序
|
* 对结果进行排序
|
||||||
@@ -32,6 +32,6 @@ public interface TableQueryBuilder extends ConditionalBuilder<TableQueryBuilder,
|
|||||||
* @return {@link TableQueryBuilder}
|
* @return {@link TableQueryBuilder}
|
||||||
* @since 0.2.6
|
* @since 0.2.6
|
||||||
*/
|
*/
|
||||||
TableQueryBuilder setPageLimit(int start, int end);
|
TableQueryBuilder limit(int start, int end);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLActi
|
|||||||
* @return {@link UpdateBuilder}
|
* @return {@link UpdateBuilder}
|
||||||
* @since 0.3.7
|
* @since 0.3.7
|
||||||
*/
|
*/
|
||||||
UpdateBuilder addColumnValue(@NotNull String columnName, @Nullable Object columnValue);
|
UpdateBuilder set(@NotNull String columnName, @Nullable Object columnValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
||||||
@@ -27,7 +27,7 @@ public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLActi
|
|||||||
* @param columnData 字段名和值的键值对
|
* @param columnData 字段名和值的键值对
|
||||||
* @return {@link UpdateBuilder}
|
* @return {@link UpdateBuilder}
|
||||||
*/
|
*/
|
||||||
UpdateBuilder setColumnValues(LinkedHashMap<@NotNull String, @Nullable Object> columnData);
|
UpdateBuilder setAll(LinkedHashMap<@NotNull String, @Nullable Object> columnData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
||||||
@@ -37,19 +37,19 @@ public interface UpdateBuilder extends ConditionalBuilder<UpdateBuilder, SQLActi
|
|||||||
* @param columnValues 字段名对应的值
|
* @param columnValues 字段名对应的值
|
||||||
* @return {@link UpdateBuilder}
|
* @return {@link UpdateBuilder}
|
||||||
*/
|
*/
|
||||||
UpdateBuilder setColumnValues(@NotNull String[] columnNames, @Nullable Object[] columnValues);
|
UpdateBuilder setAll(@NotNull String[] columnNames, @Nullable Object[] columnValues);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
* 设定更新的全部字段值 <b>(此操作会覆盖之前的设定)</b>
|
||||||
* <p> 如需同时更新多条字段,请使用 {@link #setColumnValues(String[], Object[])} 或 {@link #setColumnValues(LinkedHashMap)}
|
* <p> 如需同时更新多条字段,请使用 {@link #setAll(String[], Object[])} 或 {@link #setAll(LinkedHashMap)}
|
||||||
* <br>也可以使用 {@link #addColumnValue(String, Object)} 一条条的添加字段
|
* <br>也可以使用 {@link #set(String, Object)} 一条条的添加字段
|
||||||
*
|
*
|
||||||
* @param columnName 字段名
|
* @param columnName 字段名
|
||||||
* @param columnValue 字段名对应的值
|
* @param columnValue 字段名对应的值
|
||||||
* @return {@link UpdateBuilder}
|
* @return {@link UpdateBuilder}
|
||||||
*/
|
*/
|
||||||
default UpdateBuilder setColumnValues(@NotNull String columnName, @Nullable Object columnValue) {
|
default UpdateBuilder setAll(@NotNull String columnName, @Nullable Object columnValue) {
|
||||||
return setColumnValues(new String[]{columnName}, new Object[]{columnValue});
|
return setAll(new String[]{columnName}, new Object[]{columnValue});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package cc.carm.lib.easysql.api.condition;
|
||||||
|
|
||||||
|
public class SQLCondition {
|
||||||
|
}
|
||||||
@@ -84,8 +84,8 @@ public class EasySQLDemo {
|
|||||||
public void sqlQuery(SQLManager sqlManager) {
|
public void sqlQuery(SQLManager sqlManager) {
|
||||||
// 同步SQL查询
|
// 同步SQL查询
|
||||||
try (SQLQuery query = sqlManager.createQuery()
|
try (SQLQuery query = sqlManager.createQuery()
|
||||||
.inTable("users") // 在users表中查询
|
.fromTable("users") // 在users表中查询
|
||||||
.selectColumns("id", "name") // 选中 id 与 name列
|
.select("id", "name") // 选中 id 与 name列
|
||||||
.addCondition("age", ">", 18) // 限定 age 要大于5
|
.addCondition("age", ">", 18) // 限定 age 要大于5
|
||||||
.addCondition("email", null) // 限定查询 email 字段为空
|
.addCondition("email", null) // 限定查询 email 字段为空
|
||||||
.addNotNullCondition("phone") // 限定 phone 字段不为空
|
.addNotNullCondition("phone") // 限定 phone 字段不为空
|
||||||
@@ -101,10 +101,10 @@ public class EasySQLDemo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UUID userUUID = sqlManager.createQuery()
|
UUID userUUID = sqlManager.createQuery()
|
||||||
.inTable("users") // 在users表中查询
|
.fromTable("users") // 在users表中查询
|
||||||
.selectColumns("uuid")
|
.select("uuid")
|
||||||
.addCondition("id", 5) // 限定 id 为 5
|
.addCondition("id", 5) // 限定 id 为 5
|
||||||
.setLimit(1) // 只取出一个数据
|
.limit(1) // 只取出一个数据
|
||||||
.build().execute(query -> {
|
.build().execute(query -> {
|
||||||
//可以直接进行数据处理
|
//可以直接进行数据处理
|
||||||
ResultSet result = query.getResultSet();
|
ResultSet result = query.getResultSet();
|
||||||
@@ -118,9 +118,9 @@ public class EasySQLDemo {
|
|||||||
public void sqlQueryAsync(SQLManager sqlManager) {
|
public void sqlQueryAsync(SQLManager sqlManager) {
|
||||||
// 异步SQL查询
|
// 异步SQL查询
|
||||||
sqlManager.createQuery()
|
sqlManager.createQuery()
|
||||||
.inTable("users") // 在users表中查询
|
.fromTable("users") // 在users表中查询
|
||||||
.addCondition("id", 5) // 限定 id 为 5
|
.addCondition("id", 5) // 限定 id 为 5
|
||||||
.setLimit(1) // 只取出一个数据
|
.limit(1) // 只取出一个数据
|
||||||
.build().executeAsync(success -> {
|
.build().executeAsync(success -> {
|
||||||
ResultSet resultSet = success.getResultSet();
|
ResultSet resultSet = success.getResultSet();
|
||||||
if (resultSet != null && resultSet.next()) {
|
if (resultSet != null && resultSet.next()) {
|
||||||
@@ -137,8 +137,8 @@ public class EasySQLDemo {
|
|||||||
public void sqlInsert(SQLManager sqlManager) {
|
public void sqlInsert(SQLManager sqlManager) {
|
||||||
// 同步SQL插入 (不使用try-catch的情况下,返回的数值可能为空。)
|
// 同步SQL插入 (不使用try-catch的情况下,返回的数值可能为空。)
|
||||||
int id = sqlManager.createInsert("users")
|
int id = sqlManager.createInsert("users")
|
||||||
.setColumnNames("username", "phone", "email", "registerTime")
|
.columns("username", "phone", "email", "registerTime")
|
||||||
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
.params("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
||||||
.returnGeneratedKey() // 设定在后续返回自增主键
|
.returnGeneratedKey() // 设定在后续返回自增主键
|
||||||
.execute((exception, action) -> {
|
.execute((exception, action) -> {
|
||||||
// 处理异常
|
// 处理异常
|
||||||
@@ -148,8 +148,8 @@ public class EasySQLDemo {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
int userID = sqlManager.createInsert("users")
|
int userID = sqlManager.createInsert("users")
|
||||||
.setColumnNames("username", "phone", "email", "registerTime")
|
.columns("username", "phone", "email", "registerTime")
|
||||||
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
.params("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
||||||
.returnGeneratedKey().execute();
|
.returnGeneratedKey().execute();
|
||||||
|
|
||||||
System.out.println("新用户的ID为 " + userID);
|
System.out.println("新用户的ID为 " + userID);
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package cc.carm.lib.easysql;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.action.SQLTransaction;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public interface DemoTransaction {
|
||||||
|
|
||||||
|
SQLTransactionResult commitTransaction(Consumer<SQLTransaction> consumer);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -12,9 +12,9 @@ public class QueryAsyncTest extends TestHandler {
|
|||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
|
|
||||||
sqlManager.createQuery()
|
sqlManager.createQuery()
|
||||||
.inTable("test_user_table")
|
.fromTable("test_user_table")
|
||||||
.orderBy("id", false)
|
.orderBy("id", false)
|
||||||
.setLimit(1)
|
.limit(1)
|
||||||
.build().executeAsync(query -> {
|
.build().executeAsync(query -> {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000L);
|
Thread.sleep(1000L);
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ public class QueryCloseTest extends TestHandler {
|
|||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
|
|
||||||
try (SQLQuery query = sqlManager.createQuery()
|
try (SQLQuery query = sqlManager.createQuery()
|
||||||
.inTable("test_user_table")
|
.fromTable("test_user_table")
|
||||||
.orderBy("id", false)
|
.orderBy("id", false)
|
||||||
.setLimit(5)
|
.limit(5)
|
||||||
.build().execute()) {
|
.build().execute()) {
|
||||||
ResultSet resultSet = query.getResultSet();
|
ResultSet resultSet = query.getResultSet();
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ public class QueryFunctionTest extends TestHandler {
|
|||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
|
|
||||||
Integer id_1 = sqlManager.createQuery()
|
Integer id_1 = sqlManager.createQuery()
|
||||||
.inTable("test_user_table")
|
.fromTable("test_user_table")
|
||||||
.orderBy("id", false)
|
.orderBy("id", false)
|
||||||
.setLimit(1)
|
.limit(1)
|
||||||
.build().executeFunction(query -> {
|
.build().executeFunction(query -> {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000L);
|
Thread.sleep(1000L);
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ public class QueryFutureTest extends TestHandler {
|
|||||||
|
|
||||||
|
|
||||||
Future<Integer> future = sqlManager.createQuery()
|
Future<Integer> future = sqlManager.createQuery()
|
||||||
.inTable("test_user_table")
|
.fromTable("test_user_table")
|
||||||
.orderBy("id", false)
|
.orderBy("id", false)
|
||||||
.setLimit(1)
|
.limit(1)
|
||||||
.build().executeFuture((query) -> {
|
.build().executeFuture((query) -> {
|
||||||
if (!query.getResultSet().next()) {
|
if (!query.getResultSet().next()) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ public class QueryNotCloseTest extends TestHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
SQLQuery query = sqlManager.createQuery()
|
SQLQuery query = sqlManager.createQuery()
|
||||||
.inTable("test_user_table")
|
.fromTable("test_user_table")
|
||||||
.orderBy("id", false)
|
.orderBy("id", false)
|
||||||
.setLimit(5)
|
.limit(5)
|
||||||
.build().execute();
|
.build().execute();
|
||||||
|
|
||||||
ResultSet resultSet = query.getResultSet();
|
ResultSet resultSet = query.getResultSet();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class SQLUpdateBatchTests extends TestHandler {
|
|||||||
public void onTest(SQLManager sqlManager) throws SQLException {
|
public void onTest(SQLManager sqlManager) throws SQLException {
|
||||||
|
|
||||||
List<Long> updates = sqlManager.createInsertBatch("test_user_table")
|
List<Long> updates = sqlManager.createInsertBatch("test_user_table")
|
||||||
.setColumnNames("uuid", "username", "age")
|
.columns("uuid", "username", "age")
|
||||||
.setAllParams(generateParams())
|
.setAllParams(generateParams())
|
||||||
.returnGeneratedKeys(Long.class)
|
.returnGeneratedKeys(Long.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|||||||
@@ -12,7 +12,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<Integer> generatedKeys = sqlManager.createInsertBatch("test_user_table")
|
||||||
.setColumnNames("uuid", "username", "age")
|
.columns("uuid", "username", "age")
|
||||||
.setAllParams(generateParams())
|
.setAllParams(generateParams())
|
||||||
.returnGeneratedKeys(Integer.class)
|
.returnGeneratedKeys(Integer.class)
|
||||||
.execute();
|
.execute();
|
||||||
|
|||||||
@@ -46,19 +46,19 @@ public class PreparedSQLUpdateActionImpl<T extends Number>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateActionImpl<T> setParams(Object... params) {
|
public PreparedSQLUpdateActionImpl<T> params(Object... params) {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateActionImpl<T> setParams(@Nullable Iterable<Object> params) {
|
public PreparedSQLUpdateActionImpl<T> params(@Nullable Iterable<Object> params) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
return setParams((Object[]) null);
|
return params((Object[]) null);
|
||||||
} else {
|
} else {
|
||||||
List<Object> paramsList = new ArrayList<>();
|
List<Object> paramsList = new ArrayList<>();
|
||||||
params.forEach(paramsList::add);
|
params.forEach(paramsList::add);
|
||||||
return setParams(paramsList.toArray());
|
return params(paramsList.toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
|
|||||||
protected abstract B getThis();
|
protected abstract B getThis();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public B setConditions(@Nullable String condition) {
|
public B where(@Nullable String condition) {
|
||||||
this.conditionSQLs = new ArrayList<>();
|
this.conditionSQLs = new ArrayList<>();
|
||||||
this.conditionParams = new ArrayList<>();
|
this.conditionParams = new ArrayList<>();
|
||||||
if (condition != null) this.conditionSQLs.add(condition);
|
if (condition != null) this.conditionSQLs.add(condition);
|
||||||
@@ -35,7 +35,7 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public B setConditions(
|
public B where(
|
||||||
LinkedHashMap<@NotNull String, @Nullable Object> conditions
|
LinkedHashMap<@NotNull String, @Nullable Object> conditions
|
||||||
) {
|
) {
|
||||||
conditions.forEach(this::addCondition);
|
conditions.forEach(this::addCondition);
|
||||||
@@ -119,7 +119,7 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public B setLimit(int limit) {
|
public B limit(int limit) {
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class QueryBuilderImpl extends AbstractSQLBuilder implements QueryBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableQueryBuilder inTable(@NotNull String tableName) {
|
public TableQueryBuilder fromTable(@NotNull String tableName) {
|
||||||
Objects.requireNonNull(tableName, "tableName could not be null");
|
Objects.requireNonNull(tableName, "tableName could not be null");
|
||||||
return new TableQueryBuilderImpl(getManager(), tableName);
|
return new TableQueryBuilderImpl(getManager(), tableName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableCreateBuilder setColumns(@NotNull String... columns) {
|
public TableCreateBuilder columns(@NotNull String... columns) {
|
||||||
Objects.requireNonNull(columns, "columns could not be null");
|
Objects.requireNonNull(columns, "columns could not be null");
|
||||||
this.columns = Arrays.asList(columns);
|
this.columns = Arrays.asList(columns);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class TableQueryBuilderImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableQueryBuilderImpl selectColumns(@NotNull String... columnNames) {
|
public TableQueryBuilderImpl select(@NotNull String... columnNames) {
|
||||||
Objects.requireNonNull(columnNames, "columnNames could not be null");
|
Objects.requireNonNull(columnNames, "columnNames could not be null");
|
||||||
this.columns = columnNames;
|
this.columns = columnNames;
|
||||||
return this;
|
return this;
|
||||||
@@ -82,7 +82,7 @@ public class TableQueryBuilderImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableQueryBuilder setPageLimit(int start, int end) {
|
public TableQueryBuilder limit(int start, int end) {
|
||||||
this.pageLimit = new int[]{start, end};
|
this.pageLimit = new int[]{start, end};
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,20 +56,20 @@ public class UpdateBuilderImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateBuilder addColumnValue(@NotNull String columnName, Object columnValue) {
|
public UpdateBuilder set(@NotNull String columnName, Object columnValue) {
|
||||||
Objects.requireNonNull(columnName, "columnName could not be null");
|
Objects.requireNonNull(columnName, "columnName could not be null");
|
||||||
this.columnData.put(columnName, columnValue);
|
this.columnData.put(columnName, columnValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateBuilder setColumnValues(LinkedHashMap<String, Object> columnData) {
|
public UpdateBuilder setAll(LinkedHashMap<String, Object> columnData) {
|
||||||
this.columnData = columnData;
|
this.columnData = columnData;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateBuilder setColumnValues(@NotNull String[] columnNames, @Nullable Object[] columnValues) {
|
public UpdateBuilder setAll(@NotNull String[] columnNames, @Nullable Object[] columnValues) {
|
||||||
Objects.requireNonNull(columnNames, "columnName could not be null");
|
Objects.requireNonNull(columnNames, "columnName could not be null");
|
||||||
if (columnNames.length != columnValues.length) {
|
if (columnNames.length != columnValues.length) {
|
||||||
throw new RuntimeException("columnNames are not match with columnValues");
|
throw new RuntimeException("columnNames are not match with columnValues");
|
||||||
@@ -78,7 +78,7 @@ public class UpdateBuilderImpl
|
|||||||
for (int i = 0; i < columnNames.length; i++) {
|
for (int i = 0; i < columnNames.length; i++) {
|
||||||
columnData.put(columnNames[i], columnValues[i]);
|
columnData.put(columnNames[i], columnValues[i]);
|
||||||
}
|
}
|
||||||
return setColumnValues(columnData);
|
return setAll(columnData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ public class SQLManagerImpl implements SQLManager {
|
|||||||
public InsertBuilder<PreparedSQLUpdateBatchAction<Integer>> createInsertBatch(@NotNull String tableName) {
|
public InsertBuilder<PreparedSQLUpdateBatchAction<Integer>> createInsertBatch(@NotNull String tableName) {
|
||||||
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
|
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateBatchAction<Integer> setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateBatchAction<Integer> columns(List<String> columnNames) {
|
||||||
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -213,7 +213,7 @@ public class SQLManagerImpl implements SQLManager {
|
|||||||
public InsertBuilder<PreparedSQLUpdateAction<Integer>> createInsert(@NotNull String tableName) {
|
public InsertBuilder<PreparedSQLUpdateAction<Integer>> createInsert(@NotNull String tableName) {
|
||||||
return new InsertBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
|
return new InsertBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateAction<Integer> setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateAction<Integer> columns(List<String> columnNames) {
|
||||||
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -223,7 +223,7 @@ public class SQLManagerImpl implements SQLManager {
|
|||||||
public ReplaceBuilder<PreparedSQLUpdateBatchAction<Integer>> createReplaceBatch(@NotNull String tableName) {
|
public ReplaceBuilder<PreparedSQLUpdateBatchAction<Integer>> createReplaceBatch(@NotNull String tableName) {
|
||||||
return new ReplaceBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
|
return new ReplaceBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateBatchAction<Integer> setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateBatchAction<Integer> columns(List<String> columnNames) {
|
||||||
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -233,7 +233,7 @@ public class SQLManagerImpl implements SQLManager {
|
|||||||
public ReplaceBuilder<PreparedSQLUpdateAction<Integer>> createReplace(@NotNull String tableName) {
|
public ReplaceBuilder<PreparedSQLUpdateAction<Integer>> createReplace(@NotNull String tableName) {
|
||||||
return new ReplaceBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
|
return new ReplaceBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateAction<Integer> setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateAction<Integer> columns(List<String> columnNames) {
|
||||||
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user