mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-05 00:25:32 +08:00
[v0.2.7] [U] 进一步简化操作使用逻辑
This commit is contained in:
@@ -1,23 +1,23 @@
|
|||||||
package cc.carm.lib.easysql.api;
|
package cc.carm.lib.easysql.api;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||||
import cc.carm.lib.easysql.api.function.SQLFunction;
|
import cc.carm.lib.easysql.api.function.SQLFunction;
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLHandler;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLAction 是用于承载SQL语句并进行处理、返回的基本类。
|
* SQLAction 是用于承载SQL语句并进行处理、返回的基本类。
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>同步执行 {@link #execute()}, {@link #execute(SQLFunction, BiConsumer)}
|
* <li>同步执行 {@link #execute()}, {@link #execute(SQLFunction, SQLExceptionHandler)}
|
||||||
* <br>同步执行方法中有会抛出异常的方法与不抛出异常的方法,
|
* <br>同步执行方法中有会抛出异常的方法与不抛出异常的方法,
|
||||||
* <br>若选择不抛出异常,则返回值可能为空,需要特殊处理。</li>
|
* <br>若选择不抛出异常,则返回值可能为空,需要特殊处理。</li>
|
||||||
*
|
*
|
||||||
* <li>异步执行 {@link #executeAsync(Consumer, BiConsumer)}
|
* <li>异步执行 {@link #executeAsync(SQLHandler, SQLExceptionHandler)}
|
||||||
* <br>异步执行时将提供成功与异常两种处理方式
|
* <br>异步执行时将提供成功与异常两种处理方式
|
||||||
* <br>可自行选择是否对数据或异常进行处理
|
* <br>可自行选择是否对数据或异常进行处理
|
||||||
* <br>默认的异常处理器为 {@link #defaultExceptionHandler()}</li>
|
* <br>默认的异常处理器为 {@link #defaultExceptionHandler()}</li>
|
||||||
@@ -29,138 +29,138 @@ import java.util.function.Consumer;
|
|||||||
*/
|
*/
|
||||||
public interface SQLAction<T> {
|
public interface SQLAction<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到该Action的UUID
|
* 得到该Action的UUID
|
||||||
*
|
*
|
||||||
* @return UUID
|
* @return UUID
|
||||||
*/
|
*/
|
||||||
@NotNull UUID getActionUUID();
|
@NotNull UUID getActionUUID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到短八位格式的UUID
|
* 得到短八位格式的UUID
|
||||||
*
|
*
|
||||||
* @return UUID(8)
|
* @return UUID(8)
|
||||||
*/
|
*/
|
||||||
@NotNull String getShortID();
|
@NotNull String getShortID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到该Action的创建时间
|
* 得到该Action的创建时间
|
||||||
*
|
*
|
||||||
* @return 创建时间
|
* @return 创建时间
|
||||||
*/
|
*/
|
||||||
long getCreateTime();
|
long getCreateTime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到该Action所要执行的源SQL语句
|
* 得到该Action所要执行的源SQL语句
|
||||||
*
|
*
|
||||||
* @return 源SQL语句
|
* @return 源SQL语句
|
||||||
*/
|
*/
|
||||||
@NotNull String getSQLContent();
|
@NotNull String getSQLContent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到承载该Action的对应{@link SQLManager}
|
* 得到承载该Action的对应{@link SQLManager}
|
||||||
*
|
*
|
||||||
* @return {@link SQLManager}
|
* @return {@link SQLManager}
|
||||||
*/
|
*/
|
||||||
@NotNull SQLManager getManager();
|
@NotNull SQLManager getManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行该Action对应的SQL语句
|
* 执行该Action对应的SQL语句
|
||||||
*
|
*
|
||||||
* @return 指定数据类型
|
* @return 指定数据类型
|
||||||
* @throws SQLException 当SQL操作出现问题时抛出
|
* @throws SQLException 当SQL操作出现问题时抛出
|
||||||
*/
|
*/
|
||||||
@NotNull T execute() throws SQLException;
|
@NotNull T execute() throws SQLException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行语句并返回值
|
* 执行语句并返回值
|
||||||
*
|
*
|
||||||
* @param exceptionHandler 异常处理器 默认为 {@link #defaultExceptionHandler()}
|
* @param exceptionHandler 异常处理器 默认为 {@link #defaultExceptionHandler()}
|
||||||
* @return 指定类型数据
|
* @return 指定类型数据
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default T execute(@Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler) {
|
default T execute(@Nullable SQLExceptionHandler exceptionHandler) {
|
||||||
return execute(t -> t, exceptionHandler);
|
return execute(t -> t, exceptionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行语句并处理返回值
|
* 执行语句并处理返回值
|
||||||
*
|
*
|
||||||
* @param function 处理方法
|
* @param function 处理方法
|
||||||
* @param <R> 需要返回的内容
|
* @param <R> 需要返回的内容
|
||||||
* @return 指定类型数据
|
* @return 指定类型数据
|
||||||
* @throws SQLException 当SQL操作出现问题时抛出
|
* @throws SQLException 当SQL操作出现问题时抛出
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default <R> R executeFunction(@NotNull SQLFunction<T, R> function) throws SQLException {
|
default <R> R executeFunction(@NotNull SQLFunction<T, R> function) throws SQLException {
|
||||||
try {
|
try {
|
||||||
T value = execute();
|
T value = execute();
|
||||||
return function.apply(value);
|
return function.apply(value);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
throw new SQLException(exception);
|
throw new SQLException(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行语句并处理返回值
|
* 执行语句并处理返回值
|
||||||
*
|
*
|
||||||
* @param function 处理方法
|
* @param function 处理方法
|
||||||
* @param exceptionHandler 异常处理器 默认为 {@link #defaultExceptionHandler()}
|
* @param exceptionHandler 异常处理器 默认为 {@link #defaultExceptionHandler()}
|
||||||
* @param <R> 需要返回的内容
|
* @param <R> 需要返回的内容
|
||||||
* @return 指定类型数据
|
* @return 指定类型数据
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default <R> R execute(@NotNull SQLFunction<T, R> function,
|
default <R> R execute(@NotNull SQLFunction<T, R> function,
|
||||||
@Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler) {
|
@Nullable SQLExceptionHandler exceptionHandler) {
|
||||||
try {
|
try {
|
||||||
return executeFunction(function);
|
return executeFunction(function);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
handleException(exceptionHandler, exception);
|
handleException(exceptionHandler, exception);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步执行SQL语句,采用默认异常处理,无需返回值。
|
* 异步执行SQL语句,采用默认异常处理,无需返回值。
|
||||||
*/
|
*/
|
||||||
default void executeAsync() {
|
default void executeAsync() {
|
||||||
executeAsync(null);
|
executeAsync(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步执行SQL语句
|
* 异步执行SQL语句
|
||||||
*
|
*
|
||||||
* @param success 成功时的操作
|
* @param success 成功时的操作
|
||||||
*/
|
*/
|
||||||
default void executeAsync(@Nullable Consumer<T> success) {
|
default void executeAsync(@Nullable SQLHandler<T> success) {
|
||||||
executeAsync(success, null);
|
executeAsync(success, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步执行SQL语句
|
* 异步执行SQL语句
|
||||||
*
|
*
|
||||||
* @param success 成功时的操作
|
* @param success 成功时的操作
|
||||||
* @param failure 异常处理器 默认为 {@link SQLAction#defaultExceptionHandler()}
|
* @param failure 异常处理器 默认为 {@link SQLAction#defaultExceptionHandler()}
|
||||||
*/
|
*/
|
||||||
void executeAsync(@Nullable Consumer<T> success, @Nullable BiConsumer<SQLException, SQLAction<T>> failure);
|
void executeAsync(@Nullable SQLHandler<T> success,
|
||||||
|
@Nullable SQLExceptionHandler failure);
|
||||||
|
|
||||||
|
default void handleException(@Nullable SQLExceptionHandler handler, SQLException exception) {
|
||||||
|
if (handler == null) handler = defaultExceptionHandler();
|
||||||
|
handler.accept(exception, this);
|
||||||
|
}
|
||||||
|
|
||||||
default void handleException(@Nullable BiConsumer<SQLException, SQLAction<T>> handler, SQLException exception) {
|
/**
|
||||||
if (handler == null) handler = defaultExceptionHandler();
|
* @return 默认的异常处理器
|
||||||
handler.accept(exception, this);
|
*/
|
||||||
}
|
default SQLExceptionHandler defaultExceptionHandler() {
|
||||||
|
return (exception, action) -> {
|
||||||
/**
|
getManager().getLogger().severe("Error when execute [" + action.getSQLContent() + "]");
|
||||||
* @return 默认的异常处理器
|
getManager().getLogger().severe(exception.getLocalizedMessage());
|
||||||
*/
|
exception.printStackTrace();
|
||||||
default BiConsumer<SQLException, SQLAction<T>> defaultExceptionHandler() {
|
};
|
||||||
return (exception, action) -> {
|
}
|
||||||
getManager().getLogger().severe("Error when execute [" + action.getSQLContent() + "]");
|
|
||||||
getManager().getLogger().severe(exception.getLocalizedMessage());
|
|
||||||
exception.printStackTrace();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-23
@@ -1,36 +1,35 @@
|
|||||||
package cc.carm.lib.easysql.api.action;
|
package cc.carm.lib.easysql.api.action;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
|
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
|
|
||||||
public interface SQLUpdateBatchAction extends SQLAction<List<Integer>> {
|
public interface SQLUpdateBatchAction extends SQLAction<List<Integer>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条批量执行的SQL语句
|
* 添加一条批量执行的SQL语句
|
||||||
*
|
*
|
||||||
* @param sql SQL语句
|
* @param sql SQL语句
|
||||||
* @return {@link SQLUpdateBatchAction}
|
* @return {@link SQLUpdateBatchAction}
|
||||||
*/
|
*/
|
||||||
SQLUpdateBatchAction addBatch(@NotNull String sql);
|
SQLUpdateBatchAction addBatch(@NotNull String sql);
|
||||||
|
|
||||||
List<String> getSQLContents();
|
List<String> getSQLContents();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default BiConsumer<SQLException, SQLAction<List<Integer>>> defaultExceptionHandler() {
|
default SQLExceptionHandler<List<Integer>> defaultExceptionHandler() {
|
||||||
return (exception, action) -> {
|
return (exception, action) -> {
|
||||||
getManager().getLogger().severe("Error when execute SQLs : ");
|
getManager().getLogger().severe("Error when execute SQLs : ");
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (String content : getSQLContents()) {
|
for (String content : getSQLContents()) {
|
||||||
getManager().getLogger().severe("#" + i + " [" + content + "]");
|
getManager().getLogger().severe("#" + i + " [" + content + "]");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
getManager().getLogger().severe(exception.getLocalizedMessage());
|
getManager().getLogger().severe(exception.getLocalizedMessage());
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package cc.carm.lib.easysql.api.function;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SQLExceptionHandler extends BiConsumer<SQLException, SQLAction<?>> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
package cc.carm.lib.easysql.api.function;
|
package cc.carm.lib.easysql.api.function;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
public interface SQLFunction<T, R> {
|
public interface SQLFunction<T, R> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
R apply(T t) throws SQLException;
|
R apply(T t) throws SQLException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package cc.carm.lib.easysql.api.function;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SQLHandler<T> {
|
||||||
|
|
||||||
|
void accept(@NotNull T t) throws SQLException;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Contract(pure = true)
|
||||||
|
default SQLHandler<T> andThen(@NotNull SQLHandler<? super T> after) {
|
||||||
|
Objects.requireNonNull(after);
|
||||||
|
return (T t) -> {
|
||||||
|
accept(t);
|
||||||
|
after.accept(t);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,100 +9,96 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class EasySQLDemo {
|
public class EasySQLDemo {
|
||||||
|
|
||||||
public void createTable(SQLManager sqlManager) {
|
public void createTable(SQLManager sqlManager) {
|
||||||
// 同步创建表
|
// 同步创建表
|
||||||
sqlManager.createTable("users")
|
sqlManager.createTable("users")
|
||||||
.addColumn("id", "INT(11) AUTO_INCREMENT NOT NULL PRIMARY KEY")
|
.addColumn("id", "INT(11) AUTO_INCREMENT NOT NULL PRIMARY KEY")
|
||||||
.addColumn("uuid", "VARCHAR(32) NOT NULL UNIQUE KEY")
|
.addColumn("uuid", "VARCHAR(32) NOT NULL UNIQUE KEY")
|
||||||
.addColumn("username", "VARCHAR(16) NOT NULL UNIQUE KEY")
|
.addColumn("username", "VARCHAR(16) NOT NULL UNIQUE KEY")
|
||||||
.addColumn("age", "INT(3) NOT NULL DEFAULT 1")
|
.addColumn("age", "INT(3) NOT NULL DEFAULT 1")
|
||||||
.addColumn("email", "VARCHAR(32)")
|
.addColumn("email", "VARCHAR(32)")
|
||||||
.addColumn("phone", "VARCHAR(16)")
|
.addColumn("phone", "VARCHAR(16)")
|
||||||
.addColumn("registerTime", "DATETIME NOT NULL")
|
.addColumn("registerTime", "DATETIME NOT NULL")
|
||||||
.build().execute(null /* 不处理错误 */);
|
.build().execute(null /* 不处理错误 */);
|
||||||
}
|
}
|
||||||
|
|
||||||
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表中查询
|
.inTable("users") // 在users表中查询
|
||||||
.selectColumns("id", "name") // 选中 id 与 name列
|
.selectColumns("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 字段不为空
|
||||||
.addTimeCondition("registerTime", // 时间字段
|
.addTimeCondition("registerTime", // 时间字段
|
||||||
System.currentTimeMillis() - 100000, //限制开始时间
|
System.currentTimeMillis() - 100000, //限制开始时间
|
||||||
-1//不限制结束时间
|
-1//不限制结束时间
|
||||||
).build().execute()) {
|
).build().execute()) {
|
||||||
ResultSet resultSet = query.getResultSet();
|
ResultSet resultSet = query.getResultSet();
|
||||||
//do something
|
//do something
|
||||||
|
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID userUUID = sqlManager.createQuery()
|
UUID userUUID = sqlManager.createQuery()
|
||||||
.inTable("users") // 在users表中查询
|
.inTable("users") // 在users表中查询
|
||||||
.selectColumns("uuid")
|
.selectColumns("uuid")
|
||||||
.addCondition("id", 5) // 限定 id 为 5
|
.addCondition("id", 5) // 限定 id 为 5
|
||||||
.setLimit(1) // 只取出一个数据
|
.setLimit(1) // 只取出一个数据
|
||||||
.build().execute(query -> {
|
.build().execute(query -> {
|
||||||
//可以直接进行数据处理
|
//可以直接进行数据处理
|
||||||
ResultSet result = query.getResultSet();
|
ResultSet result = query.getResultSet();
|
||||||
return result.next() ? UUIDUtil.toUUID(result.getString("uuid")) : null;
|
return result.next() ? UUIDUtil.toUUID(result.getString("uuid")) : null;
|
||||||
}, (exception, action) -> {
|
}, (exception, action) -> {
|
||||||
// 处理异常,不想处理直接填null
|
// 处理异常,不想处理直接填null
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sqlQueryAsync(SQLManager sqlManager) {
|
public void sqlQueryAsync(SQLManager sqlManager) {
|
||||||
// 异步SQL查询
|
// 异步SQL查询
|
||||||
sqlManager.createQuery()
|
sqlManager.createQuery()
|
||||||
.inTable("users") // 在users表中查询
|
.inTable("users") // 在users表中查询
|
||||||
.addCondition("id", 5) // 限定 id 为 5
|
.addCondition("id", 5) // 限定 id 为 5
|
||||||
.setLimit(1) // 只取出一个数据
|
.setLimit(1) // 只取出一个数据
|
||||||
.build().executeAsync(success -> {
|
.build().executeAsync(success -> {
|
||||||
ResultSet resultSet = success.getResultSet();
|
ResultSet resultSet = success.getResultSet();
|
||||||
try {
|
if (resultSet != null && resultSet.next()) {
|
||||||
if (resultSet != null && resultSet.next()) {
|
String username = resultSet.getString("username");
|
||||||
String username = resultSet.getString("username");
|
}
|
||||||
}
|
}, (exception, action) -> {
|
||||||
} catch (SQLException e) {
|
//do something
|
||||||
e.printStackTrace();
|
long createTIme = action.getCreateTime();
|
||||||
}
|
String shortID = action.getShortID();
|
||||||
}, (exception, action) -> {
|
String sqlContent = action.getSQLContent();
|
||||||
//do something
|
});
|
||||||
long createTIme = action.getCreateTime();
|
}
|
||||||
String shortID = action.getShortID();
|
|
||||||
String sqlContent = action.getSQLContent();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sqlInsert(SQLManager sqlManager) {
|
public void sqlInsert(SQLManager sqlManager) {
|
||||||
// 同步SQL插入 (不使用try-catch的情况下,返回的数值可能为空。)
|
// 同步SQL插入 (不使用try-catch的情况下,返回的数值可能为空。)
|
||||||
Integer id = sqlManager.createInsert("users")
|
Integer id = sqlManager.createInsert("users")
|
||||||
.setColumnNames("username", "phone", "email", "registerTime")
|
.setColumnNames("username", "phone", "email", "registerTime")
|
||||||
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
||||||
.setKeyIndex(1) // 设定自增主键的index,将会在后续返回自增主键
|
.setKeyIndex(1) // 设定自增主键的index,将会在后续返回自增主键
|
||||||
.execute((exception, action) -> {
|
.execute((exception, action) -> {
|
||||||
// 处理异常
|
// 处理异常
|
||||||
System.out.println("#" + action.getShortID() + " -> " + action.getSQLContent());
|
System.out.println("#" + action.getShortID() + " -> " + action.getSQLContent());
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Integer userID = sqlManager.createInsert("users")
|
Integer userID = sqlManager.createInsert("users")
|
||||||
.setColumnNames("username", "phone", "email", "registerTime")
|
.setColumnNames("username", "phone", "email", "registerTime")
|
||||||
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
.setParams("CarmJos", "18888888888", "carm@carm.cc", TimeDateUtils.getCurrentTime())
|
||||||
.setKeyIndex(1) // 设定自增主键的index,将会在后续返回自增主键
|
.setKeyIndex(1) // 设定自增主键的index,将会在后续返回自增主键
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
System.out.println("新用户的ID为 " + userID);
|
System.out.println("新用户的ID为 " + userID);
|
||||||
|
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package cc.carm.lib.easysql.action;
|
package cc.carm.lib.easysql.action;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
import cc.carm.lib.easysql.api.SQLAction;
|
||||||
|
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.manager.SQLManagerImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -8,88 +10,78 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public abstract class AbstractSQLAction<T> implements SQLAction<T> {
|
public abstract class AbstractSQLAction<T> implements SQLAction<T> {
|
||||||
|
|
||||||
private final @NotNull SQLManagerImpl sqlManager;
|
private final @NotNull SQLManagerImpl sqlManager;
|
||||||
|
|
||||||
private final @NotNull UUID uuid;
|
private final @NotNull UUID uuid;
|
||||||
private final long createTime;
|
private final long createTime;
|
||||||
|
|
||||||
protected @NotNull String sqlContent;
|
protected @NotNull String sqlContent;
|
||||||
|
|
||||||
protected @Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler = null;
|
protected @Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler = null;
|
||||||
|
|
||||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||||
this(manager, sql, System.currentTimeMillis());
|
this(manager, sql, System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql, @NotNull UUID uuid) {
|
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql, @NotNull UUID uuid) {
|
||||||
this(manager, sql, uuid, System.currentTimeMillis());
|
this(manager, sql, uuid, System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql, long createTime) {
|
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql, long createTime) {
|
||||||
this(manager, sql, UUID.randomUUID(), createTime);
|
this(manager, sql, UUID.randomUUID(), createTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
||||||
@NotNull UUID uuid, long createTime) {
|
@NotNull UUID uuid, long createTime) {
|
||||||
this.sqlManager = manager;
|
this.sqlManager = manager;
|
||||||
this.sqlContent = sql;
|
this.sqlContent = sql;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.createTime = createTime;
|
this.createTime = createTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull UUID getActionUUID() {
|
public @NotNull UUID getActionUUID() {
|
||||||
return this.uuid;
|
return this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getShortID() {
|
public @NotNull String getShortID() {
|
||||||
return getActionUUID().toString().substring(0, 8);
|
return getActionUUID().toString().substring(0, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCreateTime() {
|
public long getCreateTime() {
|
||||||
return this.createTime;
|
return this.createTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getSQLContent() {
|
public @NotNull String getSQLContent() {
|
||||||
return this.sqlContent.trim();
|
return this.sqlContent.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull SQLManagerImpl getManager() {
|
public @NotNull SQLManagerImpl getManager() {
|
||||||
return this.sqlManager;
|
return this.sqlManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void outputDebugMessage() {
|
protected void outputDebugMessage() {
|
||||||
getManager().debug("#" + getShortID() + " ->" + getSQLContent());
|
getManager().debug("#" + getShortID() + " ->" + getSQLContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleException(SQLException exception) {
|
|
||||||
if (this.exceptionHandler == null) {
|
|
||||||
defaultExceptionHandler().accept(exception, this);
|
|
||||||
} else {
|
|
||||||
this.exceptionHandler.accept(exception, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeAsync(Consumer<T> success, BiConsumer<SQLException, SQLAction<T>> failure) {
|
|
||||||
getManager().getExecutorPool().submit(() -> {
|
|
||||||
try {
|
|
||||||
T returnedValue = execute();
|
|
||||||
if (success != null) success.accept(returnedValue);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
(failure == null ? defaultExceptionHandler() : failure).accept(e, this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeAsync(SQLHandler<T> success, SQLExceptionHandler failure) {
|
||||||
|
getManager().getExecutorPool().submit(() -> {
|
||||||
|
try {
|
||||||
|
T returnedValue = execute();
|
||||||
|
if (success != null) success.accept(returnedValue);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
handleException(failure, e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -14,7 +14,9 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PreparedSQLBatchUpdateActionImpl extends AbstractSQLAction<List<Integer>> implements PreparedSQLUpdateBatchAction {
|
public class PreparedSQLBatchUpdateActionImpl
|
||||||
|
extends AbstractSQLAction<List<Integer>>
|
||||||
|
implements PreparedSQLUpdateBatchAction {
|
||||||
|
|
||||||
int keyIndex = -1;
|
int keyIndex = -1;
|
||||||
List<Object[]> allParams;
|
List<Object[]> allParams;
|
||||||
|
|||||||
+53
-51
@@ -13,66 +13,68 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PreparedSQLUpdateActionImpl extends SQLUpdateActionImpl implements PreparedSQLUpdateAction {
|
public class PreparedSQLUpdateActionImpl
|
||||||
|
extends SQLUpdateActionImpl
|
||||||
|
implements PreparedSQLUpdateAction {
|
||||||
|
|
||||||
Object[] params;
|
Object[] params;
|
||||||
|
|
||||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||||
this(manager, sql, (Object[]) null);
|
this(manager, sql, (Object[]) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
||||||
@Nullable List<Object> params) {
|
@Nullable List<Object> params) {
|
||||||
this(manager, sql, params == null ? null : params.toArray());
|
this(manager, sql, params == null ? null : params.toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql,
|
||||||
@Nullable Object[] params) {
|
@Nullable Object[] params) {
|
||||||
super(manager, sql);
|
super(manager, sql);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateActionImpl setParams(Object[] params) {
|
public PreparedSQLUpdateActionImpl setParams(Object[] params) {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateAction setParams(@Nullable Iterable<Object> params) {
|
public PreparedSQLUpdateAction setParams(@Nullable Iterable<Object> params) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
return setParams((Object[]) null);
|
return setParams((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 setParams(paramsList.toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Integer execute() throws SQLException {
|
public @NotNull Integer execute() throws SQLException {
|
||||||
int value = -1;
|
int value = -1;
|
||||||
|
|
||||||
Connection connection = getManager().getConnection();
|
Connection connection = getManager().getConnection();
|
||||||
PreparedStatement statement = StatementUtil.createPrepareStatement(
|
PreparedStatement statement = StatementUtil.createPrepareStatement(
|
||||||
connection, getSQLContent(), params, keyIndex > 0
|
connection, getSQLContent(), params, keyIndex > 0
|
||||||
);
|
);
|
||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
if (keyIndex > 0) {
|
if (keyIndex > 0) {
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
ResultSet resultSet = statement.getGeneratedKeys();
|
ResultSet resultSet = statement.getGeneratedKeys();
|
||||||
if (resultSet != null) {
|
if (resultSet != null) {
|
||||||
if (resultSet.next()) value = resultSet.getInt(keyIndex);
|
if (resultSet.next()) value = resultSet.getInt(keyIndex);
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = statement.executeUpdate();
|
value = statement.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
statement.close();
|
statement.close();
|
||||||
connection.close();
|
connection.close();
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
public class SQLUpdateActionImpl extends AbstractSQLAction<Integer> implements SQLUpdateAction {
|
public class SQLUpdateActionImpl
|
||||||
|
extends AbstractSQLAction<Integer>
|
||||||
|
implements SQLUpdateAction {
|
||||||
|
|
||||||
int keyIndex = -1;
|
int keyIndex = -1;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> implements SQLUpdateBatchAction {
|
public class SQLUpdateBatchActionImpl
|
||||||
|
extends AbstractSQLAction<List<Integer>>
|
||||||
|
implements SQLUpdateBatchAction {
|
||||||
|
|
||||||
List<String> sqlContents = new ArrayList<>();
|
List<String> sqlContents = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
+39
-39
@@ -17,51 +17,51 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class PreparedQueryActionImpl extends QueryActionImpl implements PreparedQueryAction {
|
public class PreparedQueryActionImpl extends QueryActionImpl implements PreparedQueryAction {
|
||||||
|
|
||||||
Consumer<PreparedStatement> handler;
|
Consumer<PreparedStatement> handler;
|
||||||
Object[] params;
|
Object[] params;
|
||||||
|
|
||||||
public PreparedQueryActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
public PreparedQueryActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||||
super(manager, sql);
|
super(manager, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedQueryActionImpl setParams(@Nullable Object[] params) {
|
public PreparedQueryActionImpl setParams(@Nullable Object[] params) {
|
||||||
this.params = params;
|
this.params = params;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedQueryActionImpl setParams(@Nullable Iterable<Object> params) {
|
public PreparedQueryActionImpl setParams(@Nullable Iterable<Object> params) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
return setParams((Object[]) null);
|
return setParams((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 setParams(paramsList.toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedQueryActionImpl handleStatement(@Nullable Consumer<PreparedStatement> statement) {
|
public PreparedQueryActionImpl handleStatement(@Nullable Consumer<PreparedStatement> statement) {
|
||||||
this.handler = statement;
|
this.handler = statement;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull SQLQueryImpl execute() throws SQLException {
|
public @NotNull SQLQueryImpl execute() throws SQLException {
|
||||||
Connection connection = getManager().getConnection();
|
Connection connection = getManager().getConnection();
|
||||||
getManager().debug("#" + getShortID() + " ->" + getSQLContent());
|
getManager().debug("#" + getShortID() + " ->" + getSQLContent());
|
||||||
PreparedStatement preparedStatement;
|
PreparedStatement preparedStatement;
|
||||||
if (handler == null) {
|
if (handler == null) {
|
||||||
preparedStatement = StatementUtil.createPrepareStatement(connection, getSQLContent(), this.params);
|
preparedStatement = StatementUtil.createPrepareStatement(connection, getSQLContent(), this.params);
|
||||||
} else {
|
} else {
|
||||||
preparedStatement = connection.prepareStatement(getSQLContent());
|
preparedStatement = connection.prepareStatement(getSQLContent());
|
||||||
handler.accept(preparedStatement);
|
handler.accept(preparedStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
return new SQLQueryImpl(getManager(), this, connection, preparedStatement, resultSet);
|
return new SQLQueryImpl(getManager(), this, connection, preparedStatement, resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package cc.carm.lib.easysql.action.query;
|
package cc.carm.lib.easysql.action.query;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.action.AbstractSQLAction;
|
import cc.carm.lib.easysql.action.AbstractSQLAction;
|
||||||
import cc.carm.lib.easysql.api.SQLAction;
|
|
||||||
import cc.carm.lib.easysql.api.action.query.QueryAction;
|
import cc.carm.lib.easysql.api.action.query.QueryAction;
|
||||||
import cc.carm.lib.easysql.api.action.query.SQLQuery;
|
import cc.carm.lib.easysql.api.action.query.SQLQuery;
|
||||||
|
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.manager.SQLManagerImpl;
|
||||||
import cc.carm.lib.easysql.query.SQLQueryImpl;
|
import cc.carm.lib.easysql.query.SQLQueryImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -12,36 +13,34 @@ import java.sql.Connection;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements QueryAction {
|
public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements QueryAction {
|
||||||
|
|
||||||
public QueryActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
public QueryActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||||
super(manager, sql);
|
super(manager, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull SQLQueryImpl execute() throws SQLException {
|
public @NotNull SQLQueryImpl execute() throws SQLException {
|
||||||
Connection connection = getManager().getConnection();
|
Connection connection = getManager().getConnection();
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
|
|
||||||
outputDebugMessage();
|
outputDebugMessage();
|
||||||
|
|
||||||
ResultSet resultSet = statement.executeQuery(getSQLContent());
|
ResultSet resultSet = statement.executeQuery(getSQLContent());
|
||||||
SQLQueryImpl query = new SQLQueryImpl(getManager(), this, connection, statement, resultSet);
|
SQLQueryImpl query = new SQLQueryImpl(getManager(), this, connection, statement, resultSet);
|
||||||
getManager().getActiveQuery().put(getActionUUID(), query);
|
getManager().getActiveQuery().put(getActionUUID(), query);
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeAsync(Consumer<SQLQuery> success, BiConsumer<SQLException, SQLAction<SQLQuery>> failure) {
|
public void executeAsync(SQLHandler<SQLQuery> success, SQLExceptionHandler failure) {
|
||||||
try (SQLQueryImpl query = execute()) {
|
try (SQLQueryImpl query = execute()) {
|
||||||
if (success != null) success.accept(query);
|
if (success != null) success.accept(query);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
(exceptionHandler == null ? defaultExceptionHandler() : exceptionHandler).accept(exception, this);
|
handleException(failure, exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,77 +11,77 @@ import java.sql.Statement;
|
|||||||
|
|
||||||
public class SQLQueryImpl implements SQLQuery {
|
public class SQLQueryImpl implements SQLQuery {
|
||||||
|
|
||||||
protected final long executeTime;
|
protected final long executeTime;
|
||||||
|
|
||||||
protected SQLManagerImpl sqlManager;
|
protected SQLManagerImpl sqlManager;
|
||||||
protected QueryActionImpl queryAction;
|
protected QueryActionImpl queryAction;
|
||||||
|
|
||||||
Connection connection;
|
Connection connection;
|
||||||
Statement statement;
|
Statement statement;
|
||||||
|
|
||||||
ResultSet resultSet;
|
ResultSet resultSet;
|
||||||
|
|
||||||
public SQLQueryImpl(
|
public SQLQueryImpl(
|
||||||
SQLManagerImpl sqlManager, QueryActionImpl queryAction,
|
SQLManagerImpl sqlManager, QueryActionImpl queryAction,
|
||||||
Connection connection, Statement statement, ResultSet resultSet
|
Connection connection, Statement statement, ResultSet resultSet
|
||||||
) {
|
) {
|
||||||
this.executeTime = System.currentTimeMillis();
|
this.executeTime = System.currentTimeMillis();
|
||||||
this.sqlManager = sqlManager;
|
this.sqlManager = sqlManager;
|
||||||
this.queryAction = queryAction;
|
this.queryAction = queryAction;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.statement = statement;
|
this.statement = statement;
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getExecuteTime() {
|
public long getExecuteTime() {
|
||||||
return this.executeTime;
|
return this.executeTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLManagerImpl getManager() {
|
public SQLManagerImpl getManager() {
|
||||||
return this.sqlManager;
|
return this.sqlManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryActionImpl getAction() {
|
public QueryActionImpl getAction() {
|
||||||
return this.queryAction;
|
return this.queryAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet getResultSet() {
|
public ResultSet getResultSet() {
|
||||||
return this.resultSet;
|
return this.resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSQLContent() {
|
public String getSQLContent() {
|
||||||
return getAction().getSQLContent();
|
return getAction().getSQLContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
if (getResultSet() != null) getResultSet().close();
|
if (getResultSet() != null) getResultSet().close();
|
||||||
if (getStatement() != null) getStatement().close();
|
if (getStatement() != null) getStatement().close();
|
||||||
if (getConnection() != null) getConnection().close();
|
if (getConnection() != null) getConnection().close();
|
||||||
|
|
||||||
getManager().debug("#" + getAction().getShortID() +
|
getManager().debug("#" + getAction().getShortID() +
|
||||||
" -> finished after " + (System.currentTimeMillis() - getExecuteTime()) + " ms."
|
" -> finished after " + (System.currentTimeMillis() - getExecuteTime()) + " ms."
|
||||||
);
|
);
|
||||||
getManager().getActiveQuery().remove(getAction().getActionUUID());
|
getManager().getActiveQuery().remove(getAction().getActionUUID());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
getAction().handleException(e);
|
getAction().handleException(getAction().defaultExceptionHandler(), e);
|
||||||
}
|
}
|
||||||
this.queryAction = null;
|
this.queryAction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement getStatement() {
|
public Statement getStatement() {
|
||||||
return this.statement;
|
return this.statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
return this.connection;
|
return this.connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user