0

add tests for JdbcTemplate

This commit is contained in:
2021-01-03 00:00:29 +03:00
parent c0c1ede462
commit 395b0a015f
4 changed files with 293 additions and 4 deletions

View File

@@ -1,12 +1,28 @@
package ghast.database;
import lombok.Getter;
@SuppressWarnings("java:S1165")
@Getter
public class DataAccessException extends RuntimeException {
private String sql;
public DataAccessException(String msg) {
super(msg);
}
public DataAccessException(String msg, String sql) {
this(msg);
this.sql = sql;
}
public DataAccessException(String msg, Throwable cause) {
super(msg, cause);
}
public DataAccessException(String msg, String sql, Throwable cause) {
this(msg, cause);
this.sql = sql;
}
}

View File

@@ -33,7 +33,7 @@ public class JdbcTemplate implements JdbcOperations {
statement = connection.createStatement();
statement.execute(sql);
} catch (SQLException e) {
XLog.error("Error execute SQL: {0}", e.getMessage(), e);
throw new DataAccessException("Error execute SQL", sql, e);
} finally {
closeStatement(statement);
closeConnection(connection);
@@ -52,8 +52,7 @@ public class JdbcTemplate implements JdbcOperations {
resultSet = statement.executeQuery(sql);
return rse.extractData(resultSet);
} catch (SQLException e) {
XLog.error("Error execute SQL: {0}", e.getMessage(), e);
return null;
throw new DataAccessException("Error execute SQL", sql, e);
} finally {
closeResultSet(resultSet);
closeStatement(statement);