add tests for JdbcTemplate
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user