Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* Note: This class is currently intended for Liquibase-internal use only and may change without notice in the future
*/
public class JdbcExecutor extends AbstractExecutor {
private Logger log = LogService.getLog(getClass());
@Override
public boolean updatesDatabase() {
return true;
}
public Object execute(StatementCallback action, List sqlVisitors) throws DatabaseException {
DatabaseConnection con = database.getConnection();
Statement stmt = null;
try {
if (con instanceof OfflineConnection) {
throw new DatabaseException("Cannot execute commands against an offline database");
}
stmt = ((JdbcConnection) con).getUnderlyingConnection().createStatement();
Statement stmtToUse = stmt;
return action.doInStatement(stmtToUse);
}
catch (SQLException ex) {
// Release Connection early, to avoid potential connection pool deadlock
// in the case when the exception translator hasn't been initialized yet.
JdbcUtils.closeStatement(stmt);
stmt = null;
String url;
if (con.isClosed()) {
url = "CLOSED CONNECTION";
} else {
url = con.getURL();
}
throw new DatabaseException("Error executing SQL " + StringUtils.join(applyVisitors(action.getStatement(), sqlVisitors), "; on "+ url)+": "+ex.getMessage(), ex);
}
finally {
JdbcUtils.closeStatement(stmt);
}
}
// Incorrect warning, at least at this point. The situation here is not that we inject some unsanitised parameter
// into a query. Instead, we process a whole query. The check should be performed at the places where
// the query is composed.
@SuppressWarnings("squid:S2077")
public Object execute(CallableStatementCallback action, List sqlVisitors) throws DatabaseException {
DatabaseConnection con = database.getConnection();
if (con instanceof OfflineConnection) {
throw new DatabaseException("Cannot execute commands against an offline database");
}
CallableStatement stmt = null;
try {
String sql = applyVisitors(action.getStatement(), sqlVisitors)[0];
stmt = ((JdbcConnection) con).getUnderlyingConnection().prepareCall(sql);
return action.doInCallableStatement(stmt);
}
catch (SQLException ex) {
// Release Connection early, to avoid potential connection pool deadlock
// in the case when the exception translator hasn't been initialized yet.
JdbcUtils.closeStatement(stmt);
stmt = null;
throw new DatabaseException("Error executing SQL " + StringUtils.join(applyVisitors(action.getStatement(), sqlVisitors), "; on "+ con.getURL())+": "+ex.getMessage(), ex);
}
finally {
JdbcUtils.closeStatement(stmt);
}
}
@Override
public void execute(final SqlStatement sql) throws DatabaseException {
execute(sql, new ArrayList());
}
@Override
public void execute(final SqlStatement sql, final List sqlVisitors) throws DatabaseException {
if(sql instanceof ExecutablePreparedStatement) {
((ExecutablePreparedStatement) sql).execute(new PreparedStatementFactory((JdbcConnection)database.getConnection()));
return;
}
if (sql instanceof CompoundStatement) {
if (database instanceof Db2zDatabase) {
executeDb2ZosComplexStatement(sql);
return;
}
}
execute(new ExecuteStatementCallback(sql, sqlVisitors), sqlVisitors);
}
public Object query(final SqlStatement sql, final ResultSetExtractor rse) throws DatabaseException {
return query(sql, rse, new ArrayList());
}
public Object query(final SqlStatement sql, final ResultSetExtractor rse, final List sqlVisitors) throws DatabaseException {
if (sql instanceof CallableSqlStatement) {
return execute(new QueryCallableStatementCallback(sql, rse), sqlVisitors);
}
return execute(new QueryStatementCallback(sql, rse, sqlVisitors), sqlVisitors);
}
public List query(SqlStatement sql, RowMapper rowMapper) throws DatabaseException {
return query(sql, rowMapper, new ArrayList());
}
public List query(SqlStatement sql, RowMapper rowMapper, List sqlVisitors) throws DatabaseException {
return (List) query(sql, new RowMapperResultSetExtractor(rowMapper), sqlVisitors);
}
public Object queryForObject(SqlStatement sql, RowMapper rowMapper) throws DatabaseException {
return queryForObject(sql, rowMapper, new ArrayList());
}
public Object queryForObject(SqlStatement sql, RowMapper rowMapper, List sqlVisitors) throws DatabaseException {
List results = query(sql, rowMapper, sqlVisitors);
try {
return JdbcUtils.requiredSingleResult(results);
} catch (DatabaseException e) {
throw new DatabaseException("Expected single row from " + sql + " but got "+results.size(), e);
}
}
@Override
public T queryForObject(SqlStatement sql, Class requiredType) throws DatabaseException {
return (T) queryForObject(sql, requiredType, new ArrayList());
}
@Override
public T queryForObject(SqlStatement sql, Class requiredType, List sqlVisitors) throws DatabaseException {
return (T) queryForObject(sql, getSingleColumnRowMapper(requiredType), sqlVisitors);
}
@Override
public long queryForLong(SqlStatement sql) throws DatabaseException {
return queryForLong(sql, new ArrayList());
}
@Override
public long queryForLong(SqlStatement sql, List sqlVisitors) throws DatabaseException {
Number number = queryForObject(sql, Long.class, sqlVisitors);
return ((number != null) ? number.longValue() : 0);
}
@Override
public int queryForInt(SqlStatement sql) throws DatabaseException {
return queryForInt(sql, new ArrayList());
}
@Override
public int queryForInt(SqlStatement sql, List sqlVisitors) throws DatabaseException {
Number number = queryForObject(sql, Integer.class, sqlVisitors);
return ((number != null) ? number.intValue() : 0);
}
@Override
public List queryForList(SqlStatement sql, Class elementType) throws DatabaseException {
return queryForList(sql, elementType, new ArrayList());
}
@Override
public List queryForList(SqlStatement sql, Class elementType, List sqlVisitors) throws DatabaseException {
return query(sql, getSingleColumnRowMapper(elementType), sqlVisitors);
}
@Override
public List