diff --git a/rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutable.java b/rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutable.java index 8f080420..2396736d 100644 --- a/rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutable.java +++ b/rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutable.java @@ -12,6 +12,10 @@ public interface JdbcExecutable { ResultSet executeQuery(String sql, Object[] params, long executeTimeoutMillis); + T executeScalar(String sql, Object[] params); + + T executeScalar(String sql, Object[] params, long executeTimeoutMillis); + T executeQuery(String sql, Object[] params, BiFunc func); T executeQuery(String sql, Object[] params, BiFunc func, long executeTimeoutMillis); @@ -32,6 +36,10 @@ public interface JdbcExecutable { ResultSet executeQuery(String sql, long executeTimeoutMillis); + T executeScalar(String sql); + + T executeScalar(String sql, long executeTimeoutMillis); + T executeQuery(String sql, BiFunc func); T executeQuery(String sql, BiFunc func, long executeTimeoutMillis); diff --git a/rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutor.java b/rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutor.java index 1ca021f6..c996e520 100644 --- a/rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutor.java +++ b/rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutor.java @@ -342,6 +342,22 @@ public ResultSet executeQuery(String sql, Object[] params, int cursorType, long } } + @Override + public T executeScalar(String sql, Object[] params) { + return executeScalar(sql, params, executeTimeoutMillis); + } + + @SneakyThrows + @Override + public T executeScalar(String sql, Object[] params, long executeTimeoutMillis) { + try (ResultSet rs = executeQuery(sql, params, executeTimeoutMillis)) { + if (rs.next()) { + return (T) rs.getObject(1); + } + return null; + } + } + @Override public T executeQuery(String sql, Object[] params, BiFunc func) { return executeQuery(sql, params, func, executeTimeoutMillis); @@ -500,6 +516,22 @@ public ResultSet executeQuery(String sql, long executeTimeoutMillis) { } } + @Override + public T executeScalar(String sql) { + return executeScalar(sql, executeTimeoutMillis); + } + + @SneakyThrows + @Override + public T executeScalar(String sql, long executeTimeoutMillis) { + try (ResultSet rs = executeQuery(sql, executeTimeoutMillis)) { + if (rs.next()) { + return (T) rs.getObject(1); + } + return null; + } + } + @Override public T executeQuery(String sql, BiFunc func) { return executeQuery(sql, func, executeTimeoutMillis); diff --git a/rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java b/rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java index 35e7a9bb..b40d912b 100644 --- a/rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java +++ b/rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java @@ -205,16 +205,6 @@ public static void print(ResultSet resultSet) { } } - @SneakyThrows - public static T executeScalar(ResultSet resultSet) { - try (ResultSet rs = resultSet) { - if (rs.next()) { - return (T) rs.getObject(1); - } - return null; - } - } - public static final BiFunc TO_CAMEL_COLUMN_MAPPING = p -> CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, p); public static List readAs(ResultSet resultSet, Type type) {