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

feat: 提交进度 [ci skip]

This commit is contained in:
2023-03-15 23:06:08 +08:00
parent f606fd4efc
commit 479c23f985
67 changed files with 994 additions and 913 deletions
@@ -1,120 +1,61 @@
package cc.carm.lib.easysql.manager;
package cc.carm.lib.easysql;
import cc.carm.lib.easysql.action.PreparedBatchUpdateActionImpl;
import cc.carm.lib.easysql.action.PreparedUpdateActionImpl;
import cc.carm.lib.easysql.action.PreparedSQLBatchUpdateActionImpl;
import cc.carm.lib.easysql.action.PreparedSQLUpdateActionImpl;
import cc.carm.lib.easysql.action.SQLBatchUpdateActionImpl;
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.base.PreparedUpdateAction;
import cc.carm.lib.easysql.api.action.base.PreparedBatchUpdateAction;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.action.base.BatchUpdateAction;
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.update.PreparedSQLBatchUpdateAction;
import cc.carm.lib.easysql.api.action.update.PreparedSQLUpdateAction;
import cc.carm.lib.easysql.api.builder.*;
import cc.carm.lib.easysql.api.enums.IsolationLevel;
import cc.carm.lib.easysql.api.function.SQLBiFunction;
import cc.carm.lib.easysql.api.function.SQLDebugHandler;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import cc.carm.lib.easysql.api.function.SQLFunction;
import cc.carm.lib.easysql.api.transaction.SQLTransaction;
import cc.carm.lib.easysql.builder.impl.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;
public class SQLManagerImpl implements SQLManager {
private final Logger LOGGER;
private final DataSource dataSource;
private final ConcurrentHashMap<UUID, SQLQuery> activeQuery = new ConcurrentHashMap<>();
protected ExecutorService executorPool;
@NotNull Supplier<Boolean> debugMode = () -> Boolean.FALSE;
@NotNull SQLExceptionHandler exceptionHandler;
@NotNull SQLDebugHandler debugHandler;
public class SQLManagerImpl extends SQLSourceImpl implements SQLManager {
public SQLManagerImpl(@NotNull DataSource dataSource) {
this(dataSource, null);
super(dataSource);
}
public SQLManagerImpl(@NotNull DataSource dataSource, @Nullable String name) {
this(dataSource, LoggerFactory.getLogger(SQLManagerImpl.class), name);
super(dataSource, name);
}
public SQLManagerImpl(@NotNull DataSource dataSource, @NotNull Logger logger) {
super(dataSource, logger);
}
public SQLManagerImpl(@NotNull DataSource dataSource, @NotNull Logger logger, @Nullable String name) {
String managerName = "SQLManager" + (name != null ? "#" + name : "");
this.LOGGER = logger;
this.dataSource = dataSource;
this.executorPool = SQLManager.defaultExecutorPool(managerName);
this.exceptionHandler = SQLExceptionHandler.detailed(getLogger());
this.debugHandler = SQLDebugHandler.defaultHandler(getLogger());
super(dataSource, logger, name);
}
@Override
public boolean isDebugMode() {
return this.debugMode.get();
}
@Override
public void setDebugMode(@NotNull Supplier<@NotNull Boolean> debugMode) {
this.debugMode = debugMode;
}
@Override
public @NotNull SQLDebugHandler getDebugHandler() {
return this.debugHandler;
}
@Override
public void setDebugHandler(@NotNull SQLDebugHandler debugHandler) {
this.debugHandler = debugHandler;
}
@Override
public Logger getLogger() {
return LOGGER;
}
public @NotNull ExecutorService getExecutorPool() {
return executorPool;
}
public void setExecutorPool(@NotNull ExecutorService executorPool) {
this.executorPool = executorPool;
}
@Override
public @NotNull DataSource getDataSource() {
return this.dataSource;
}
@Override
public @NotNull Connection getConnection() throws SQLException {
return getDataSource().getConnection();
}
@Override
public @NotNull Map<UUID, SQLQuery> getActiveQuery() {
return this.activeQuery;
}
@Override
public @NotNull SQLExceptionHandler getExceptionHandler() {
return this.exceptionHandler;
}
@Override
public void setExceptionHandler(@Nullable SQLExceptionHandler handler) {
if (handler == null) this.exceptionHandler = SQLExceptionHandler.detailed(getLogger());
else this.exceptionHandler = handler;
public SQLManagerImpl(@NotNull DataSource dataSource, @NotNull Logger logger, @NotNull ExecutorService executorPool,
@NotNull Supplier<Boolean> debugMode, @NotNull SQLDebugHandler debugHandler,
@NotNull SQLExceptionHandler exceptionHandler) {
super(dataSource, logger, executorPool, debugMode, debugHandler, exceptionHandler);
}
@Override
@@ -124,17 +65,17 @@ public class SQLManagerImpl implements SQLManager {
@Override
public Integer executeSQL(String sql, Object[] params) {
return new PreparedUpdateActionImpl<>(this, Integer.class, sql, params).execute(null);
return new PreparedSQLUpdateActionImpl<>(this, Integer.class, sql, params).execute(null);
}
@Override
public List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
return new PreparedBatchUpdateActionImpl<>(this, Integer.class, sql).allValues(paramsBatch).execute(null);
return new PreparedSQLBatchUpdateActionImpl<>(this, Integer.class, sql).allValues(paramsBatch).execute(null);
}
@Override
public List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL) {
BatchUpdateAction action = new BatchUpdateActionImpl(this, sql);
BatchUpdateAction action = new SQLBatchUpdateActionImpl(this, sql);
if (moreSQL != null && moreSQL.length > 0) {
Arrays.stream(moreSQL).forEach(action::addBatch);
}
@@ -146,7 +87,7 @@ public class SQLManagerImpl implements SQLManager {
Iterator<String> iterator = sqlBatch.iterator();
if (!iterator.hasNext()) return null; // PLEASE GIVE IT SOMETHING
BatchUpdateAction action = new BatchUpdateActionImpl(this, iterator.next());
BatchUpdateAction action = new SQLBatchUpdateActionImpl(this, iterator.next());
while (iterator.hasNext()) {
action.addBatch(iterator.next());
}
@@ -154,6 +95,11 @@ public class SQLManagerImpl implements SQLManager {
return action.execute(null);
}
@Override
public @NotNull SQLTransaction createTransaction(@Nullable IsolationLevel level) {
return null;
}
@Override
public <R> CompletableFuture<R> fetchMetadata(@NotNull SQLBiFunction<DatabaseMetaData, Connection, R> reader) {
return CompletableFuture.supplyAsync(() -> {
@@ -203,7 +149,7 @@ public class SQLManagerImpl implements SQLManager {
return new InsertBuilderImpl<PreparedBatchUpdateAction<Integer>>(this, tableName) {
@Override
public PreparedBatchUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
}
};
}
@@ -213,17 +159,42 @@ public class SQLManagerImpl implements SQLManager {
return new InsertBuilderImpl<PreparedUpdateAction<Integer>>(this, tableName) {
@Override
public PreparedUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
}
};
}
@Override
public @NotNull InsertBuilder<PreparedSQLBatchUpdateAction.Advanced<Integer>> insertBatchInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull ReplaceBuilder<PreparedSQLUpdateAction.Advanced<Integer>> replaceInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull ReplaceBuilder<PreparedSQLBatchUpdateAction.Advanced<Integer>> replaceBatchInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull UpdateBuilder<PreparedSQLUpdateAction.Advanced<Integer>> updateInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull DeleteBuilder<PreparedSQLUpdateAction.Advanced<Integer>> deleteFrom(@NotNull String tableName) {
return null;
}
@Override
public ReplaceBuilder<PreparedBatchUpdateAction<Integer>> createReplaceBatch(@NotNull String tableName) {
return new ReplaceBuilderImpl<PreparedBatchUpdateAction<Integer>>(this, tableName) {
@Override
public PreparedBatchUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
}
};
}
@@ -233,7 +204,7 @@ public class SQLManagerImpl implements SQLManager {
return new ReplaceBuilderImpl<PreparedUpdateAction<Integer>>(this, tableName) {
@Override
public PreparedUpdateAction<Integer> columns(List<String> columnNames) {
return new PreparedUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, buildSQL(getTableName(), columnNames));
}
};
}
@@ -0,0 +1,126 @@
package cc.carm.lib.easysql;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.api.SQLSource;
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 org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;
public class SQLSourceImpl implements SQLSource {
protected final @NotNull Logger logger;
protected final @NotNull DataSource dataSource;
protected @NotNull ExecutorService executorPool;
protected @NotNull Supplier<Boolean> debugMode = () -> Boolean.FALSE;
protected @NotNull SQLDebugHandler debugHandler;
protected @NotNull SQLExceptionHandler exceptionHandler;
protected final ConcurrentHashMap<UUID, SQLQuery> activeQueries = new ConcurrentHashMap<>();
public SQLSourceImpl(@NotNull DataSource dataSource) {
this(dataSource, (String) null);
}
public SQLSourceImpl(@NotNull DataSource dataSource, @Nullable String name) {
this(dataSource, LoggerFactory.getLogger(SQLManagerImpl.class), name);
}
public SQLSourceImpl(@NotNull DataSource dataSource, @NotNull Logger logger) {
this(dataSource, logger, null);
}
public SQLSourceImpl(@NotNull DataSource dataSource, @NotNull Logger logger, @Nullable String name) {
this(
dataSource, logger,
SQLSource.defaultExecutorPool("SQLSource" + (name != null ? "#" + name : "")),
() -> false, SQLDebugHandler.defaultHandler(logger), SQLExceptionHandler.detailed(logger)
);
}
public SQLSourceImpl(@NotNull DataSource dataSource, @NotNull Logger logger, @NotNull ExecutorService executorPool,
@NotNull Supplier<Boolean> debugMode, @NotNull SQLDebugHandler debugHandler,
@NotNull SQLExceptionHandler exceptionHandler) {
this.logger = logger;
this.dataSource = dataSource;
this.executorPool = executorPool;
this.exceptionHandler = exceptionHandler;
this.debugMode = debugMode;
this.debugHandler = debugHandler;
}
@Override
public @NotNull Map<UUID, SQLQuery> getActiveQueries() {
return this.activeQueries;
}
@Override
public @NotNull DataSource getDataSource() {
return this.dataSource;
}
@Override
public @NotNull Connection getConnection() throws SQLException {
return getDataSource().getConnection();
}
@Override
public @NotNull Logger getLogger() {
return this.logger;
}
@Override
public @NotNull ExecutorService getExecutorPool() {
return this.executorPool;
}
@Override
public void setExecutorPool(@NotNull ExecutorService executorPool) {
this.executorPool = executorPool;
}
@Override
public boolean isDebugMode() {
return this.debugMode.get();
}
@Override
public void setDebugMode(@NotNull Supplier<@NotNull Boolean> debugMode) {
this.debugMode = debugMode;
}
@Override
public @NotNull SQLDebugHandler getDebugHandler() {
return this.debugHandler;
}
@Override
public void setDebugHandler(@NotNull SQLDebugHandler debugHandler) {
this.debugHandler = debugHandler;
}
@Override
public @NotNull SQLExceptionHandler getExceptionHandler() {
return this.exceptionHandler;
}
@Override
public void setExceptionHandler(@Nullable SQLExceptionHandler handler) {
if (handler == null) this.exceptionHandler = SQLExceptionHandler.detailed(getLogger());
else this.exceptionHandler = handler;
}
}
@@ -0,0 +1,108 @@
package cc.carm.lib.easysql;
import cc.carm.lib.easysql.api.SQLManager;
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.builder.*;
import cc.carm.lib.easysql.api.enums.IsolationLevel;
import cc.carm.lib.easysql.api.transaction.SQLSavepoint;
import cc.carm.lib.easysql.api.transaction.SQLTransaction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class SQLTransactionImpl implements SQLTransaction {
@Override
public @NotNull SQLManager getManager() {
return null;
}
@Override
public @NotNull IsolationLevel getIsolationLevel() {
return null;
}
@Override
public void commit() {
}
@Override
public @NotNull SQLSavepoint savepoint(@NotNull String name) {
return null;
}
@Override
public void rollback(@Nullable SQLSavepoint savepoint) {
}
@Override
public @Nullable Integer executeSQL(String sql) {
return null;
}
@Override
public @Nullable Integer executeSQL(String sql, Object[] params) {
return null;
}
@Override
public @Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
return null;
}
@Override
public @Nullable List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL) {
return null;
}
@Override
public @Nullable List<Integer> executeSQLBatch(@NotNull Iterable<String> sqlBatch) {
return null;
}
@Override
public @NotNull QueryBuilder<SQLQueryAction.Base, PreparedSQLQueryAction.Base> createQuery() {
return null;
}
@Override
public @NotNull InsertBuilder<PreparedSQLUpdateAction.Base<Integer>> insertInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull InsertBuilder<PreparedSQLBatchUpdateAction.Base<Integer>> insertBatchInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull ReplaceBuilder<PreparedSQLUpdateAction.Base<Integer>> replaceInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull ReplaceBuilder<PreparedSQLBatchUpdateAction.Base<Integer>> replaceBatchInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull UpdateBuilder<PreparedSQLUpdateAction.Base<Integer>> updateInto(@NotNull String tableName) {
return null;
}
@Override
public @NotNull DeleteBuilder<PreparedSQLUpdateAction.Base<Integer>> deleteFrom(@NotNull String tableName) {
return null;
}
@Override
public void close() throws Exception {
}
}
@@ -3,7 +3,7 @@ package cc.carm.lib.easysql.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 cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.sql.SQLException;
@@ -1,7 +1,7 @@
package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.action.base.PreparedBatchUpdateAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import cc.carm.lib.easysql.util.StatementUtil;
import org.jetbrains.annotations.NotNull;
@@ -15,7 +15,7 @@ import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class PreparedBatchUpdateActionImpl<T extends Number>
public class PreparedSQLBatchUpdateActionImpl<T extends Number>
extends AbstractSQLAction<List<T>>
implements PreparedBatchUpdateAction<T> {
@@ -24,21 +24,21 @@ public class PreparedBatchUpdateActionImpl<T extends Number>
protected final @NotNull Class<T> numberClass;
public PreparedBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
super(manager, sql);
this.numberClass = numberClass;
this.allParams = new ArrayList<>();
}
public PreparedBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql) {
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql) {
super(manager, sql, uuid);
this.numberClass = numberClass;
}
@Override
public PreparedBatchUpdateActionImpl<T> allValues(Iterable<Object[]> allValues) {
public PreparedSQLBatchUpdateActionImpl<T> allValues(Iterable<Object[]> allValues) {
List<Object[]> paramsList = new ArrayList<>();
allValues.forEach(paramsList::add);
this.allParams = paramsList;
@@ -46,20 +46,20 @@ public class PreparedBatchUpdateActionImpl<T extends Number>
}
@Override
public PreparedBatchUpdateActionImpl<T> values(Object... values) {
public PreparedSQLBatchUpdateActionImpl<T> addValues(Object... values) {
this.allParams.add(values);
return this;
}
@Override
public PreparedBatchUpdateActionImpl<T> returnGeneratedKeys() {
public PreparedSQLBatchUpdateActionImpl<T> returnGeneratedKeys() {
this.returnKeys = true;
return this;
}
@Override
public <N extends Number> PreparedBatchUpdateActionImpl<N> returnGeneratedKeys(Class<N> keyTypeClass) {
return new PreparedBatchUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent())
public <N extends Number> PreparedSQLBatchUpdateActionImpl<N> returnGeneratedKeys(Class<N> keyTypeClass) {
return new PreparedSQLBatchUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent())
.allValues(allParams).returnGeneratedKeys();
}
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.action;
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.SQLManagerImpl;
import cc.carm.lib.easysql.util.StatementUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -16,43 +16,43 @@ import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class PreparedUpdateActionImpl<T extends Number>
public class PreparedSQLUpdateActionImpl<T extends Number>
extends UpdateActionImpl<T>
implements PreparedUpdateAction<T> {
Object[] params;
public PreparedUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql) {
this(manager, numberClass, sql, (Object[]) null);
}
public PreparedUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql, @Nullable List<Object> params) {
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql, @Nullable List<Object> params) {
this(manager, numberClass, sql, params == null ? null : params.toArray());
}
public PreparedUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql, @Nullable Object[] params) {
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull String sql, @Nullable Object[] params) {
super(manager, numberClass, sql);
this.params = params;
}
public PreparedUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull Class<T> numberClass,
@NotNull UUID uuid, @NotNull String sql,
Object[] params) {
public PreparedSQLUpdateActionImpl(@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 PreparedUpdateActionImpl<T> values(Object... params) {
public PreparedSQLUpdateActionImpl<T> values(Object... params) {
this.params = params;
return this;
}
@Override
public PreparedUpdateActionImpl<T> values(@Nullable Iterable<Object> params) {
public PreparedSQLUpdateActionImpl<T> values(@Nullable Iterable<Object> params) {
if (params == null) {
return values((Object[]) null);
} else {
@@ -87,7 +87,7 @@ public class PreparedUpdateActionImpl<T extends Number>
@Override
public <N extends Number> UpdateAction<N> returnGeneratedKey(Class<N> keyTypeClass) {
PreparedUpdateActionImpl<N> newAction = new PreparedUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent(), params);
PreparedSQLUpdateActionImpl<N> newAction = new PreparedSQLUpdateActionImpl<>(getManager(), keyTypeClass, getActionUUID(), getSQLContent(), params);
newAction.returnGeneratedKey();
return newAction;
}
@@ -1,7 +1,7 @@
package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.action.base.BatchUpdateAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.sql.Connection;
@@ -13,13 +13,13 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class BatchUpdateActionImpl
public class SQLBatchUpdateActionImpl
extends AbstractSQLAction<List<Integer>>
implements BatchUpdateAction {
protected final List<String> sqlContents = new ArrayList<>();
public BatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
public SQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
super(manager, sql);
this.sqlContents.add(sql);
}
@@ -1,7 +1,7 @@
package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.action.base.UpdateAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.sql.Connection;
@@ -1,7 +1,7 @@
package cc.carm.lib.easysql.action.query;
import cc.carm.lib.easysql.api.action.base.PreparedQueryAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import cc.carm.lib.easysql.query.SQLQueryImpl;
import cc.carm.lib.easysql.util.StatementUtil;
import org.jetbrains.annotations.NotNull;
@@ -15,23 +15,23 @@ import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
public class PreparedQueryActionImpl extends QueryActionImpl implements PreparedQueryAction {
public class PreparedSQLQueryActionImpl extends SQLQueryActionImpl implements PreparedQueryAction {
Consumer<PreparedStatement> handler;
Object[] params;
public PreparedQueryActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
public PreparedSQLQueryActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
super(manager, sql);
}
@Override
public PreparedQueryActionImpl setParams(@Nullable Object... params) {
public @NotNull PreparedSQLQueryActionImpl setParams(@Nullable Object... params) {
this.params = params;
return this;
}
@Override
public PreparedQueryActionImpl setParams(@Nullable Iterable<Object> params) {
public PreparedSQLQueryActionImpl setParams(@Nullable Iterable<Object> params) {
if (params == null) {
return setParams((Object[]) null);
} else {
@@ -42,7 +42,7 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
}
@Override
public PreparedQueryActionImpl handleStatement(@Nullable Consumer<PreparedStatement> statement) {
public PreparedSQLQueryActionImpl handleStatement(@Nullable Consumer<PreparedStatement> statement) {
this.handler = statement;
return this;
}
@@ -72,7 +72,7 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
connection, preparedStatement,
preparedStatement.executeQuery()
);
getManager().getActiveQuery().put(getActionUUID(), query);
getManager().getActiveQueries().put(getActionUUID(), query);
return query;
} catch (SQLException exception) {
preparedStatement.close();
@@ -2,10 +2,10 @@ package cc.carm.lib.easysql.action.query;
import cc.carm.lib.easysql.action.AbstractSQLAction;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.api.action.base.QueryAction;
import cc.carm.lib.easysql.api.action.query.SQLQueryAction;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import cc.carm.lib.easysql.api.function.SQLHandler;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import cc.carm.lib.easysql.query.SQLQueryImpl;
import org.jetbrains.annotations.NotNull;
@@ -14,9 +14,9 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements QueryAction {
public class SQLQueryActionImpl extends AbstractSQLAction<SQLQuery> implements SQLQueryAction<SQLQueryActionImpl> {
public QueryActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
public SQLQueryActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
super(manager, sql);
}
@@ -40,7 +40,7 @@ public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements Quer
connection, statement,
statement.executeQuery(getSQLContent())
);
getManager().getActiveQuery().put(getActionUUID(), query);
getManager().getActiveQueries().put(getActionUUID(), query);
return query;
} catch (SQLException exception) {
@@ -1,7 +1,7 @@
package cc.carm.lib.easysql.builder;
import cc.carm.lib.easysql.SQLManagerImpl;
import cc.carm.lib.easysql.api.SQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
@@ -20,4 +20,5 @@ public abstract class AbstractSQLBuilder implements SQLBuilder {
public @NotNull SQLManagerImpl getManager() {
return this.sqlManager;
}
}
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.api.builder.ConditionalBuilder;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -1,9 +1,9 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.action.PreparedUpdateActionImpl;
import cc.carm.lib.easysql.action.PreparedSQLUpdateActionImpl;
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 cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
@@ -32,7 +32,7 @@ public class DeleteBuilderImpl
if (hasConditions()) sqlBuilder.append(" ").append(buildConditionSQL());
if (limit > 0) sqlBuilder.append(" ").append(buildLimitSQL());
return new PreparedUpdateActionImpl<>(
return new PreparedSQLUpdateActionImpl<>(
getManager(), Integer.class, sqlBuilder.toString(),
(hasConditionParams() ? getConditionParams() : null)
);
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.api.builder.InsertBuilder;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
@@ -1,13 +1,13 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.action.query.PreparedQueryActionImpl;
import cc.carm.lib.easysql.action.query.QueryActionImpl;
import cc.carm.lib.easysql.action.query.PreparedSQLQueryActionImpl;
import cc.carm.lib.easysql.action.query.SQLQueryActionImpl;
import cc.carm.lib.easysql.api.action.base.PreparedQueryAction;
import cc.carm.lib.easysql.api.action.base.QueryAction;
import cc.carm.lib.easysql.api.builder.QueryBuilder;
import cc.carm.lib.easysql.api.builder.TableQueryBuilder;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
@@ -21,13 +21,13 @@ public class QueryBuilderImpl extends AbstractSQLBuilder implements QueryBuilder
@Deprecated
public QueryAction withSQL(@NotNull String sql) {
Objects.requireNonNull(sql, "sql could not be null");
return new QueryActionImpl(getManager(), sql);
return new SQLQueryActionImpl(getManager(), sql);
}
@Override
public PreparedQueryAction withPreparedSQL(@NotNull String sql) {
Objects.requireNonNull(sql, "sql could not be null");
return new PreparedQueryActionImpl(getManager(), sql);
return new PreparedSQLQueryActionImpl(getManager(), sql);
}
@Override
@@ -2,7 +2,7 @@ package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.api.builder.ReplaceBuilder;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -4,7 +4,7 @@ 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;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -7,7 +7,7 @@ import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
import cc.carm.lib.easysql.api.enums.IndexType;
import cc.carm.lib.easysql.api.enums.NumberType;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -4,7 +4,7 @@ import cc.carm.lib.easysql.api.builder.TableMetadataBuilder;
import cc.carm.lib.easysql.api.function.SQLBiFunction;
import cc.carm.lib.easysql.api.function.SQLFunction;
import cc.carm.lib.easysql.builder.AbstractSQLBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -1,9 +1,9 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.action.query.PreparedQueryActionImpl;
import cc.carm.lib.easysql.action.query.PreparedSQLQueryActionImpl;
import cc.carm.lib.easysql.api.action.base.PreparedQueryAction;
import cc.carm.lib.easysql.api.builder.TableQueryBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -30,7 +30,7 @@ public class TableQueryBuilderImpl
}
@Override
public PreparedQueryActionImpl build() {
public PreparedSQLQueryActionImpl build() {
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("SELECT").append(" ");
if (columns == null || columns.length < 1) {
@@ -58,7 +58,7 @@ public class TableQueryBuilderImpl
}
return new PreparedQueryActionImpl(getManager(), sqlBuilder.toString())
return new PreparedSQLQueryActionImpl(getManager(), sqlBuilder.toString())
.setParams(hasConditionParams() ? getConditionParams() : null);
}
@@ -1,9 +1,9 @@
package cc.carm.lib.easysql.builder.impl;
import cc.carm.lib.easysql.action.PreparedUpdateActionImpl;
import cc.carm.lib.easysql.action.PreparedSQLUpdateActionImpl;
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 cc.carm.lib.easysql.SQLManagerImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -46,7 +46,7 @@ public class UpdateBuilderImpl
if (limit > 0) sqlBuilder.append(" ").append(buildLimitSQL());
return new PreparedUpdateActionImpl<>(getManager(), Integer.class, sqlBuilder.toString(), allParams);
return new PreparedSQLUpdateActionImpl<>(getManager(), Integer.class, sqlBuilder.toString(), allParams);
}
@Override
@@ -1,8 +1,8 @@
package cc.carm.lib.easysql.query;
import cc.carm.lib.easysql.action.query.QueryActionImpl;
import cc.carm.lib.easysql.action.query.SQLQueryActionImpl;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.SQLManagerImpl;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -18,17 +18,17 @@ public class SQLQueryImpl implements SQLQuery {
protected final Connection connection;
protected final Statement statement;
protected final ResultSet resultSet;
protected QueryActionImpl queryAction;
protected SQLQueryActionImpl queryAction;
public SQLQueryImpl(
SQLManagerImpl sqlManager, QueryActionImpl queryAction,
SQLManagerImpl sqlManager, SQLQueryActionImpl queryAction,
Connection connection, Statement statement, ResultSet resultSet
) {
this(sqlManager, queryAction, connection, statement, resultSet, System.nanoTime());
}
public SQLQueryImpl(
SQLManagerImpl sqlManager, QueryActionImpl queryAction,
SQLManagerImpl sqlManager, SQLQueryActionImpl queryAction,
Connection connection, Statement statement, ResultSet resultSet,
long executeTime
) {
@@ -51,7 +51,7 @@ public class SQLQueryImpl implements SQLQuery {
}
@Override
public QueryActionImpl getAction() {
public SQLQueryActionImpl getAction() {
return this.queryAction;
}
@@ -79,7 +79,7 @@ public class SQLQueryImpl implements SQLQuery {
ex.printStackTrace();
}
}
getManager().getActiveQuery().remove(getAction().getActionUUID());
getManager().getActiveQueries().remove(getAction().getActionUUID());
} catch (SQLException e) {
getAction().handleException(getAction().defaultExceptionHandler(), e);
}