use of liquibase.sql.CallableSql in project liquibase by liquibase.
the class JdbcExecutor method executeDb2ZosComplexStatement.
private void executeDb2ZosComplexStatement(SqlStatement sqlStatement) throws DatabaseException {
DatabaseConnection con = database.getConnection();
if (con instanceof OfflineConnection) {
throw new DatabaseException("Cannot execute commands against an offline database");
}
Sql[] sqls = SqlGeneratorFactory.getInstance().generateSql(sqlStatement, database);
for (Sql sql : sqls) {
try {
if (sql instanceof CallableSql) {
CallableStatement call = null;
ResultSet resultSet = null;
try {
call = ((JdbcConnection) con).getUnderlyingConnection().prepareCall(sql.toSql());
resultSet = call.executeQuery();
checkCallStatus(resultSet, ((CallableSql) sql).getExpectedStatus());
} finally {
JdbcUtil.close(resultSet, call);
}
} else {
Statement stmt = null;
try {
stmt = ((JdbcConnection) con).getUnderlyingConnection().createStatement();
stmt.execute(sql.toSql());
con.commit();
} finally {
JdbcUtil.closeStatement(stmt);
}
}
} catch (Exception e) {
throw new DatabaseException(e.getMessage() + " [Failed SQL: " + getErrorCode(e) + sql.toSql() + "]", e);
}
}
}
Aggregations