Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
youfanx committed Dec 20, 2024
1 parent ee74de7 commit ffc18e7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
8 changes: 8 additions & 0 deletions rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public interface JdbcExecutable {

ResultSet executeQuery(String sql, Object[] params, long executeTimeoutMillis);

<T> T executeScalar(String sql, Object[] params);

<T> T executeScalar(String sql, Object[] params, long executeTimeoutMillis);

<T> T executeQuery(String sql, Object[] params, BiFunc<ResultSet, T> func);

<T> T executeQuery(String sql, Object[] params, BiFunc<ResultSet, T> func, long executeTimeoutMillis);
Expand All @@ -32,6 +36,10 @@ public interface JdbcExecutable {

ResultSet executeQuery(String sql, long executeTimeoutMillis);

<T> T executeScalar(String sql);

<T> T executeScalar(String sql, long executeTimeoutMillis);

<T> T executeQuery(String sql, BiFunc<ResultSet, T> func);

<T> T executeQuery(String sql, BiFunc<ResultSet, T> func, long executeTimeoutMillis);
Expand Down
32 changes: 32 additions & 0 deletions rxlib-x/src/main/java/org/rx/jdbc/JdbcExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,22 @@ public ResultSet executeQuery(String sql, Object[] params, int cursorType, long
}
}

@Override
public <T> T executeScalar(String sql, Object[] params) {
return executeScalar(sql, params, executeTimeoutMillis);
}

@SneakyThrows
@Override
public <T> 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> T executeQuery(String sql, Object[] params, BiFunc<ResultSet, T> func) {
return executeQuery(sql, params, func, executeTimeoutMillis);
Expand Down Expand Up @@ -500,6 +516,22 @@ public ResultSet executeQuery(String sql, long executeTimeoutMillis) {
}
}

@Override
public <T> T executeScalar(String sql) {
return executeScalar(sql, executeTimeoutMillis);
}

@SneakyThrows
@Override
public <T> 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> T executeQuery(String sql, BiFunc<ResultSet, T> func) {
return executeQuery(sql, func, executeTimeoutMillis);
Expand Down
10 changes: 0 additions & 10 deletions rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,6 @@ public static void print(ResultSet resultSet) {
}
}

@SneakyThrows
public static <T> T executeScalar(ResultSet resultSet) {
try (ResultSet rs = resultSet) {
if (rs.next()) {
return (T) rs.getObject(1);
}
return null;
}
}

public static final BiFunc<String, String> TO_CAMEL_COLUMN_MAPPING = p -> CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, p);

public static <T> List<T> readAs(ResultSet resultSet, Type type) {
Expand Down

0 comments on commit ffc18e7

Please sign in to comment.