diff --git a/easysql-api/src/main/java/cc/carm/lib/easysql/api/SQLAction.java b/easysql-api/src/main/java/cc/carm/lib/easysql/api/SQLAction.java index 5cfc2e1..c8a9d87 100644 --- a/easysql-api/src/main/java/cc/carm/lib/easysql/api/SQLAction.java +++ b/easysql-api/src/main/java/cc/carm/lib/easysql/api/SQLAction.java @@ -84,24 +84,6 @@ public interface SQLAction { return execute(t -> t, exceptionHandler); } - /** - * 执行语句并处理返回值 - * - * @param function 处理方法 - * @param 需要返回的内容 - * @return 指定类型数据 - * @throws SQLException 当SQL操作出现问题时抛出 - */ - @Nullable - default R executeFunction(@NotNull SQLFunction function) throws SQLException { - try { - T value = execute(); - return function.apply(value); - } catch (SQLException exception) { - throw new SQLException(exception); - } - } - /** * 执行语句并处理返回值 * @@ -121,6 +103,24 @@ public interface SQLAction { } } + /** + * 执行语句并处理返回值 + * + * @param function 处理方法 + * @param 需要返回的内容 + * @return 指定类型数据 + * @throws SQLException 当SQL操作出现问题时抛出 + */ + @Nullable + default R executeFunction(@NotNull SQLFunction function) throws SQLException { + try { + T value = execute(); + return function.apply(value); + } catch (SQLException exception) { + throw new SQLException(exception); + } + } + /** * 异步执行SQL语句,采用默认异常处理,无需返回值。 */ @@ -147,7 +147,7 @@ public interface SQLAction { @Nullable SQLExceptionHandler failure); default void handleException(@Nullable SQLExceptionHandler handler, SQLException exception) { - if (handler == null) handler = defaultExceptionHandler(); + if (handler == null) handler = getExceptionHandler(); handler.accept(exception, this); } @@ -162,5 +162,22 @@ public interface SQLAction { }; } + /** + * 得到通用的异常处理器。 + *
若未使用 {@link #setExceptionHandler(SQLExceptionHandler)} 方法 + *
则会返回 {@link #defaultExceptionHandler()} 。 + * + * @return 通用异常处理器。 + */ + @NotNull SQLExceptionHandler getExceptionHandler(); + + /** + * 设定通用的异常处理器。 + *
在使用 {@link #execute(SQLExceptionHandler)} 等相关方法时,若传入的处理器为null,则会采用此处理器。 + *
若该方法传入参数为 null,则会使用 {@link #defaultExceptionHandler()} 。 + * + * @param handler 异常处理器 + */ + void setExceptionHandler(@Nullable SQLExceptionHandler handler); } diff --git a/easysql-impl/src/main/java/cc/carm/lib/easysql/query/SQLQueryImpl.java b/easysql-impl/src/main/java/cc/carm/lib/easysql/query/SQLQueryImpl.java index 9d24d6a..978181a 100644 --- a/easysql-impl/src/main/java/cc/carm/lib/easysql/query/SQLQueryImpl.java +++ b/easysql-impl/src/main/java/cc/carm/lib/easysql/query/SQLQueryImpl.java @@ -70,7 +70,7 @@ public class SQLQueryImpl implements SQLQuery { ); getManager().getActiveQuery().remove(getAction().getActionUUID()); } catch (SQLException e) { - getAction().handleException(getAction().defaultExceptionHandler(), e); + getAction().handleException(getAction().getExceptionHandler(), e); } this.queryAction = null; }