Search in sources :

Example 1 with CallableSql

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);
        }
    }
}
Also used : CallableSql(liquibase.sql.CallableSql) CallableStatement(java.sql.CallableStatement) CompoundStatement(liquibase.statement.CompoundStatement) ExecutablePreparedStatement(liquibase.statement.ExecutablePreparedStatement) SqlStatement(liquibase.statement.SqlStatement) CallableSqlStatement(liquibase.statement.CallableSqlStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) DatabaseConnection(liquibase.database.DatabaseConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) OfflineConnection(liquibase.database.OfflineConnection) DatabaseException(liquibase.exception.DatabaseException) SQLException(java.sql.SQLException) DatabaseException(liquibase.exception.DatabaseException) Sql(liquibase.sql.Sql) CallableSql(liquibase.sql.CallableSql)

Aggregations

CallableStatement (java.sql.CallableStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 DatabaseConnection (liquibase.database.DatabaseConnection)1 OfflineConnection (liquibase.database.OfflineConnection)1 JdbcConnection (liquibase.database.jvm.JdbcConnection)1 DatabaseException (liquibase.exception.DatabaseException)1 CallableSql (liquibase.sql.CallableSql)1 Sql (liquibase.sql.Sql)1 CallableSqlStatement (liquibase.statement.CallableSqlStatement)1 CompoundStatement (liquibase.statement.CompoundStatement)1 ExecutablePreparedStatement (liquibase.statement.ExecutablePreparedStatement)1 SqlStatement (liquibase.statement.SqlStatement)1