1
mirror of https://github.com/CarmJos/EasySQL.git synced 2026-06-04 15:28:20 +08:00

实装 executeAsync 功能,修改异常处理方式,提供action方便获取相关信息。

This commit is contained in:
2021-12-14 16:11:22 +08:00
parent 6de493afbc
commit d7db2fbb52
18 changed files with 59 additions and 61 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<version>v0.0.1</version>
<version>0.2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable;
import java.sql.SQLException;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public interface SQLAction<T> {
@@ -22,13 +23,13 @@ public interface SQLAction<T> {
@NotNull T execute() throws SQLException;
@Nullable
default T execute(@Nullable Consumer<SQLException> exceptionHandler) {
default T execute(@Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler) {
if (exceptionHandler == null) exceptionHandler = defaultExceptionHandler();
T value = null;
try {
value = execute();
} catch (SQLException exception) {
exceptionHandler.accept(exception);
exceptionHandler.accept(exception, this);
}
return value;
}
@@ -37,22 +38,16 @@ public interface SQLAction<T> {
executeAsync(null);
}
default void executeAsync(Consumer<T> success) {
default void executeAsync(@Nullable Consumer<T> success) {
executeAsync(success, null);
}
void executeAsync(Consumer<T> success, Consumer<SQLException> failure);
void executeAsync(@Nullable Consumer<T> success, @Nullable BiConsumer<SQLException, SQLAction<T>> failure);
SQLAction<T> handleException(Consumer<SQLException> failure);
@NotNull Consumer<SQLException> getExceptionHandler();
default Consumer<SQLException> defaultExceptionHandler() {
return Throwable::printStackTrace;
}
default Consumer<T> defaultResultHandler() {
return t -> {
default BiConsumer<SQLException, SQLAction<T>> defaultExceptionHandler() {
return (exception, action) -> {
getManager().getLogger().severe("Error when execute [" + action.getSQLContent() + "]");
getManager().getLogger().severe(exception.getLocalizedMessage());
};
}
@@ -12,9 +12,12 @@ import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
public interface SQLManager {
Logger getLogger();
boolean isDebugMode();
void setDebugMode(boolean enable);
@@ -0,0 +1,4 @@
package cc.carm.lib.easysql.api.builder;
public interface UpsertBuilder {
}