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

chore(sql): 尝试分离async部分

This commit is contained in:
2022-12-22 09:35:02 +08:00
parent b6871b1000
commit 81f065a85a
71 changed files with 646 additions and 616 deletions
@@ -1,6 +1,5 @@
package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import cc.carm.lib.easysql.api.function.SQLFunction;
import cc.carm.lib.easysql.api.function.SQLHandler;
@@ -1,6 +1,6 @@
package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
import cc.carm.lib.easysql.api.action.base.BatchUpdateAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
@@ -13,13 +13,13 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class SQLUpdateBatchActionImpl
public class BatchUpdateActionImpl
extends AbstractSQLAction<List<Integer>>
implements SQLUpdateBatchAction {
implements BatchUpdateAction {
protected final List<String> sqlContents = new ArrayList<>();
public SQLUpdateBatchActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
public BatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
super(manager, sql);
this.sqlContents.add(sql);
}
@@ -30,7 +30,7 @@ public class SQLUpdateBatchActionImpl
}
@Override
public SQLUpdateBatchAction addBatch(@NotNull String sql) {
public BatchUpdateAction addBatch(@NotNull String sql) {
Objects.requireNonNull(sql, "sql could not be null");
this.sqlContents.add(sql);
return this;
@@ -1,6 +1,6 @@
package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
import cc.carm.lib.easysql.api.action.base.PreparedBatchUpdateAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.util.StatementUtil;
import org.jetbrains.annotations.NotNull;
@@ -15,30 +15,30 @@ import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class PreparedSQLBatchUpdateActionImpl<T extends Number>
public class PreparedBatchUpdateActionImpl<T extends Number>
extends AbstractSQLAction<List<T>>
implements PreparedSQLUpdateBatchAction<T> {
implements PreparedBatchUpdateAction<T> {
boolean returnKeys = false;
@NotNull List<Object[]> allParams = new ArrayList<>();
protected final @NotNull Class<T> numberClass;
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
public PreparedBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
super(manager, sql);
this.numberClass = numberClass;
this.allParams = new ArrayList<>();
}
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql) {
public PreparedBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql) {
super(manager, sql, uuid);
this.numberClass = numberClass;
}
@Override
public PreparedSQLBatchUpdateActionImpl<T> allValues(Iterable<Object[]> allValues) {
public PreparedBatchUpdateActionImpl<T> allValues(Iterable<Object[]> allValues) {
List<Object[]> paramsList = new ArrayList<>();
allValues.forEach(paramsList::add);
this.allParams = paramsList;
@@ -46,20 +46,20 @@ public class PreparedSQLBatchUpdateActionImpl<T extends Number>
}
@Override
public PreparedSQLBatchUpdateActionImpl<T> values(Object... values) {
public PreparedBatchUpdateActionImpl<T> values(Object... values) {
this.allParams.add(values);
return this;
}
@Override
public PreparedSQLBatchUpdateActionImpl<T> returnGeneratedKeys() {
public PreparedBatchUpdateActionImpl<T> returnGeneratedKeys() {
this.returnKeys = true;
return this;
}
@Override
public <N extends Number> PreparedSQLBatchUpdateActionImpl<N> returnGeneratedKeys(Class<N> keyTypeClass) {
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent())
public <N extends Number> PreparedBatchUpdateActionImpl<N> returnGeneratedKeys(Class<N> keyTypeClass) {
return new PreparedBatchUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent())
.allValues(allParams).returnGeneratedKeys();
}
@@ -1,7 +1,7 @@
package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
import cc.carm.lib.easysql.api.action.SQLUpdateAction;
import cc.carm.lib.easysql.api.action.base.PreparedUpdateAction;
import cc.carm.lib.easysql.api.action.base.UpdateAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.util.StatementUtil;
import org.jetbrains.annotations.NotNull;
@@ -16,43 +16,43 @@ import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class PreparedSQLUpdateActionImpl<T extends Number>
extends SQLUpdateActionImpl<T>
implements PreparedSQLUpdateAction<T> {
public class PreparedUpdateActionImpl<T extends Number>
extends UpdateActionImpl<T>
implements PreparedUpdateAction<T> {
Object[] params;
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
public PreparedUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
this(manager, numberClass, sql, (Object[]) null);
}
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql, @Nullable List<Object> params) {
public PreparedUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql, @Nullable List<Object> params) {
this(manager, numberClass, sql, params == null ? null : params.toArray());
}
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql, @Nullable Object[] params) {
public PreparedUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql, @Nullable Object[] params) {
super(manager, numberClass, sql);
this.params = params;
}
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql,
Object[] params) {
public PreparedUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql,
Object[] params) {
super(manager, numberClass, uuid, sql);
this.params = params;
}
@Override
public PreparedSQLUpdateActionImpl<T> values(Object... params) {
public PreparedUpdateActionImpl<T> values(Object... params) {
this.params = params;
return this;
}
@Override
public PreparedSQLUpdateActionImpl<T> values(@Nullable Iterable<Object> params) {
public PreparedUpdateActionImpl<T> values(@Nullable Iterable<Object> params) {
if (params == null) {
return values((Object[]) null);
} else {
@@ -86,8 +86,8 @@ public class PreparedSQLUpdateActionImpl<T extends Number>
}
@Override
public <N extends Number> SQLUpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass) {
PreparedSQLUpdateActionImpl<N> newAction = new PreparedSQLUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent(), params);
public <N extends Number> UpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass) {
PreparedUpdateActionImpl<N> newAction = new PreparedUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent(), params);
newAction.returnGeneratedKey();
return newAction;
}
@@ -1,6 +1,6 @@
package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.action.SQLUpdateAction;
import cc.carm.lib.easysql.api.action.base.UpdateAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
@@ -11,22 +11,22 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.UUID;
public class SQLUpdateActionImpl<T extends Number>
public class UpdateActionImpl<T extends Number>
extends AbstractSQLAction<T>
implements SQLUpdateAction<T> {
implements UpdateAction<T> {
protected final @NotNull Class<T> numberClass;
protected boolean returnGeneratedKeys = false;
public SQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
public UpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
super(manager, sql);
this.numberClass = numberClass;
}
public SQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql) {
public UpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql) {
super(manager, sql, uuid);
this.numberClass = numberClass;
}
@@ -52,14 +52,14 @@ public class SQLUpdateActionImpl<T extends Number>
}
@Override
public SQLUpdateAction<T> returnGeneratedKey() {
public UpdateAction<T> returnGeneratedKey() {
this.returnGeneratedKeys = true;
return this;
}
@Override
public <N extends Number> SQLUpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass) {
return new SQLUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent()).returnGeneratedKey();
public <N extends Number> UpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass) {
return new UpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent()).returnGeneratedKey();
}
}
@@ -1,6 +1,5 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.builder.ConditionalBuilder;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
@@ -1,8 +1,7 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.action.PreparedSQLUpdateActionImpl;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
import cc.carm.lib.easysql.action.PreparedUpdateActionImpl;
import cc.carm.lib.easysql.api.action.base.PreparedUpdateAction;
import cc.carm.lib.easysql.api.builder.DeleteBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
@@ -24,7 +23,7 @@ public class DeleteBuilderImpl
}
@Override
public PreparedSQLUpdateAction<Integer> build() {
public PreparedUpdateAction<Integer> build() {
StringBuilder sqlBuilder = new StringBuilder();
@@ -33,7 +32,7 @@ public class DeleteBuilderImpl
if (hasConditions()) sqlBuilder.append(" ").append(buildConditionSQL());
if (limit > 0) sqlBuilder.append(" ").append(buildLimitSQL());
return new PreparedSQLUpdateActionImpl<>(
return new PreparedUpdateActionImpl<>(
getManager(), Integer.class, sqlBuilder.toString(),
(hasConditionParams() ? getConditionParams() : null)
);
@@ -1,6 +1,5 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.builder.InsertBuilder;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
@@ -10,8 +10,6 @@ import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
public class QueryBuilderImpl extends AbstractSQLBuilder implements QueryBuilder {
@@ -1,6 +1,5 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.builder.ReplaceBuilder;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
@@ -1,7 +1,6 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.action.SQLUpdateActionImpl;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.action.UpdateActionImpl;
import cc.carm.lib.easysql.api.builder.TableAlterBuilder;
import cc.carm.lib.easysql.api.enums.IndexType;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
@@ -141,7 +140,7 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
);
}
private SQLUpdateActionImpl<Integer> createAction(@NotNull String sql) {
return new SQLUpdateActionImpl<>(getManager(), Integer.class, sql);
private UpdateActionImpl<Integer> createAction(@NotNull String sql) {
return new UpdateActionImpl<>(getManager(), Integer.class, sql);
}
}
@@ -1,7 +1,7 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.action.SQLUpdateActionImpl;
import cc.carm.lib.easysql.api.action.SQLUpdateAction;
import cc.carm.lib.easysql.action.UpdateActionImpl;
import cc.carm.lib.easysql.api.action.base.UpdateAction;
import cc.carm.lib.easysql.api.builder.TableCreateBuilder;
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
import cc.carm.lib.easysql.api.enums.IndexType;
@@ -75,7 +75,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
}
@Override
public SQLUpdateAction<Integer> build() {
public UpdateAction<Integer> build() {
StringBuilder createSQL = new StringBuilder();
createSQL.append("CREATE TABLE IF NOT EXISTS ").append(withBackQuote(tableName));
createSQL.append("(");
@@ -94,7 +94,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
createSQL.append(" COMMENT ").append(withQuote(tableComment));
}
return new SQLUpdateActionImpl<>(getManager(), Integer.class, createSQL.toString());
return new UpdateActionImpl<>(getManager(), Integer.class, createSQL.toString());
}
@Override
@@ -1,8 +1,7 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.action.PreparedSQLUpdateActionImpl;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
import cc.carm.lib.easysql.action.PreparedUpdateActionImpl;
import cc.carm.lib.easysql.api.action.base.PreparedUpdateAction;
import cc.carm.lib.easysql.api.builder.UpdateBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
@@ -27,7 +26,7 @@ public class UpdateBuilderImpl
}
@Override
public PreparedSQLUpdateAction<Integer> build() {
public PreparedUpdateAction<Integer> build() {
StringBuilder sqlBuilder = new StringBuilder();
@@ -47,7 +46,7 @@ public class UpdateBuilderImpl
if (limit > 0) sqlBuilder.append(" ").append(buildLimitSQL());
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, sqlBuilder.toString(), allParams);
return new PreparedUpdateActionImpl<>(getManager(), Integer.class, sqlBuilder.toString(), allParams);
}
@Override
@@ -1,14 +1,13 @@
package cc.carm.lib.easysql.manager;
import cc.carm.lib.easysql.action.PreparedSQLBatchUpdateActionImpl;
import cc.carm.lib.easysql.action.PreparedSQLUpdateActionImpl;
import cc.carm.lib.easysql.action.SQLUpdateActionImpl;
import cc.carm.lib.easysql.action.SQLUpdateBatchActionImpl;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.action.PreparedBatchUpdateActionImpl;
import cc.carm.lib.easysql.action.PreparedUpdateActionImpl;
import cc.carm.lib.easysql.action.UpdateActionImpl;
import cc.carm.lib.easysql.action.BatchUpdateActionImpl;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
import cc.carm.lib.easysql.api.action.base.PreparedUpdateAction;
import cc.carm.lib.easysql.api.action.base.PreparedBatchUpdateAction;
import cc.carm.lib.easysql.api.action.base.BatchUpdateAction;
import cc.carm.lib.easysql.api.builder.*;
import cc.carm.lib.easysql.api.function.SQLBiFunction;
import cc.carm.lib.easysql.api.function.SQLDebugHandler;
@@ -120,22 +119,22 @@ public class SQLManagerImpl implements SQLManager {
@Override
public Integer executeSQL(String sql) {
return new SQLUpdateActionImpl<>(this, Integer.class, sql).execute(null);
return new UpdateActionImpl<>(this, Integer.class, sql).execute(null);
}
@Override
public Integer executeSQL(String sql, Object[] params) {
return new PreparedSQLUpdateActionImpl<>(this, Integer.class, sql, params).execute(null);
return new PreparedUpdateActionImpl<>(this, Integer.class, sql, params).execute(null);
}
@Override
public List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
return new PreparedSQLBatchUpdateActionImpl<>(this, Integer.class, sql).allValues(paramsBatch).execute(null);
return new PreparedBatchUpdateActionImpl<>(this, Integer.class, sql).allValues(paramsBatch).execute(null);
}
@Override
public List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL) {
SQLUpdateBatchAction action = new SQLUpdateBatchActionImpl(this, sql);
BatchUpdateAction action = new BatchUpdateActionImpl(this, sql);
if (moreSQL != null && moreSQL.length > 0) {
Arrays.stream(moreSQL).forEach(action::addBatch);
}
@@ -147,7 +146,7 @@ public class SQLManagerImpl implements SQLManager {
Iterator<String> iterator = sqlBatch.iterator();
if (!iterator.hasNext()) return null; // PLEASE GIVE IT SOMETHING
SQLUpdateBatchAction action = new SQLUpdateBatchActionImpl(this, iterator.next());
BatchUpdateAction action = new BatchUpdateActionImpl(this, iterator.next());
while (iterator.hasNext()) {
action.addBatch(iterator.next());
}
@@ -200,41 +199,41 @@ public class SQLManagerImpl implements SQLManager {
}
@Override
public InsertBuilder<PreparedSQLUpdateBatchAction<Integer>> createInsertBatch(@NotNull String tableName) {
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
public InsertBuilder<PreparedBatchUpdateAction<Integer>> createInsertBatch(@NotNull String tableName) {
return new InsertBuilderImpl<PreparedBatchUpdateAction<Integer>>(this, tableName) {
@Override
public PreparedSQLUpdateBatchAction<Integer> columns(List<String> columnNames) {
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
public PreparedBatchUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
}
};
}
@Override
public InsertBuilder<PreparedSQLUpdateAction<Integer>> insertInto(@NotNull String tableName) {
return new InsertBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
public InsertBuilder<PreparedUpdateAction<Integer>> insertInto(@NotNull String tableName) {
return new InsertBuilderImpl<PreparedUpdateAction<Integer>>(this, tableName) {
@Override
public PreparedSQLUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
public PreparedUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
}
};
}
@Override
public ReplaceBuilder<PreparedSQLUpdateBatchAction<Integer>> createReplaceBatch(@NotNull String tableName) {
return new ReplaceBuilderImpl<PreparedSQLUpdateBatchAction<Integer>>(this, tableName) {
public ReplaceBuilder<PreparedBatchUpdateAction<Integer>> createReplaceBatch(@NotNull String tableName) {
return new ReplaceBuilderImpl<PreparedBatchUpdateAction<Integer>>(this, tableName) {
@Override
public PreparedSQLUpdateBatchAction<Integer> columns(List<String> columnNames) {
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
public PreparedBatchUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
}
};
}
@Override
public ReplaceBuilder<PreparedSQLUpdateAction<Integer>> createReplace(@NotNull String tableName) {
return new ReplaceBuilderImpl<PreparedSQLUpdateAction<Integer>>(this, tableName) {
public ReplaceBuilder<PreparedUpdateAction<Integer>> createReplace(@NotNull String tableName) {
return new ReplaceBuilderImpl<PreparedUpdateAction<Integer>>(this, tableName) {
@Override
public PreparedSQLUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
public PreparedUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
}
};
}