Search in sources :

Example 6 with SqlStatement

use of liquibase.statement.SqlStatement in project liquibase by liquibase.

the class LoadUpdateDataChange method generateRollbackStatements.

@Override
public SqlStatement[] generateRollbackStatements(Database database) throws RollbackImpossibleException {
    List<SqlStatement> statements = new ArrayList<SqlStatement>();
    SqlStatement[] forward = this.generateStatements(database);
    for (SqlStatement thisForward : forward) {
        InsertOrUpdateStatement thisInsert = (InsertOrUpdateStatement) thisForward;
        DeleteStatement delete = new DeleteStatement(getCatalogName(), getSchemaName(), getTableName());
        delete.setWhere(getWhere(thisInsert, database));
        statements.add(delete);
    }
    return statements.toArray(new SqlStatement[statements.size()]);
}
Also used : SqlStatement(liquibase.statement.SqlStatement) InsertOrUpdateStatement(liquibase.statement.core.InsertOrUpdateStatement) ArrayList(java.util.ArrayList) DeleteStatement(liquibase.statement.core.DeleteStatement)

Example 7 with SqlStatement

use of liquibase.statement.SqlStatement in project liquibase by liquibase.

the class DropColumnChange method generateSingleColumn.

private SqlStatement[] generateSingleColumn(Database database) {
    if (database instanceof SQLiteDatabase) {
        // return special statements for SQLite databases
        return generateStatementsForSQLiteDatabase(database, getColumnName());
    }
    List<SqlStatement> statements = new ArrayList<SqlStatement>();
    statements.add(new DropColumnStatement(getCatalogName(), getSchemaName(), getTableName(), getColumnName()));
    if (database instanceof DB2Database) {
        statements.add(new ReorganizeTableStatement(getCatalogName(), getSchemaName(), getTableName()));
    }
    return statements.toArray(new SqlStatement[statements.size()]);
}
Also used : DB2Database(liquibase.database.core.DB2Database) SqlStatement(liquibase.statement.SqlStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) ReorganizeTableStatement(liquibase.statement.core.ReorganizeTableStatement) ArrayList(java.util.ArrayList) DropColumnStatement(liquibase.statement.core.DropColumnStatement)

Example 8 with SqlStatement

use of liquibase.statement.SqlStatement in project liquibase by liquibase.

the class DropPrimaryKeyChange method generateStatements.

@Override
public SqlStatement[] generateStatements(Database database) {
    if (database instanceof SQLiteDatabase) {
        // return special statements for SQLite databases
        return generateStatementsForSQLiteDatabase(database);
    }
    DropPrimaryKeyStatement statement = new DropPrimaryKeyStatement(getCatalogName(), getSchemaName(), getTableName(), getConstraintName());
    statement.setDropIndex(this.dropIndex);
    return new SqlStatement[] { statement };
}
Also used : SqlStatement(liquibase.statement.SqlStatement) DropPrimaryKeyStatement(liquibase.statement.core.DropPrimaryKeyStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase)

Example 9 with SqlStatement

use of liquibase.statement.SqlStatement in project liquibase by liquibase.

the class ExecuteShellCommandChange method generateStatements.

@Override
public SqlStatement[] generateStatements(final Database database) {
    boolean shouldRun = true;
    if (os != null && os.size() > 0) {
        String currentOS = System.getProperty("os.name");
        if (!os.contains(currentOS)) {
            shouldRun = false;
            LogFactory.getLogger().info("Not executing on os " + currentOS + " when " + os + " was specified");
        }
    }
    // check if running under not-executed mode (logging output)
    boolean nonExecutedMode = false;
    Executor executor = ExecutorService.getInstance().getExecutor(database);
    if (executor instanceof LoggingExecutor) {
        nonExecutedMode = true;
    }
    this.finalCommandArray = createFinalCommandArray(database);
    if (shouldRun && !nonExecutedMode) {
        return new SqlStatement[] { new RuntimeStatement() {

            @Override
            public Sql[] generate(Database database) {
                try {
                    executeCommand(database);
                } catch (Exception e) {
                    throw new UnexpectedLiquibaseException("Error executing command: " + e.getLocalizedMessage(), e);
                }
                return null;
            }
        } };
    }
    if (nonExecutedMode) {
        try {
            return new SqlStatement[] { new CommentStatement(getCommandString()) };
        } finally {
            nonExecutedCleanup();
        }
    }
    return new SqlStatement[0];
}
Also used : SqlStatement(liquibase.statement.SqlStatement) Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) CommentStatement(liquibase.statement.core.CommentStatement) LoggingExecutor(liquibase.executor.LoggingExecutor) Database(liquibase.database.Database) RuntimeStatement(liquibase.statement.core.RuntimeStatement) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) Sql(liquibase.sql.Sql)

Example 10 with SqlStatement

use of liquibase.statement.SqlStatement in project liquibase by liquibase.

the class RenameSequenceChange method generateStatements.

@Override
public SqlStatement[] generateStatements(Database database) {
    List<SqlStatement> statements = new ArrayList<SqlStatement>();
    statements.add(new RenameSequenceStatement(getCatalogName(), getSchemaName(), getOldSequenceName(), getNewSequenceName()));
    return statements.toArray(new SqlStatement[statements.size()]);
}
Also used : SqlStatement(liquibase.statement.SqlStatement) ArrayList(java.util.ArrayList) RenameSequenceStatement(liquibase.statement.core.RenameSequenceStatement)

Aggregations

SqlStatement (liquibase.statement.SqlStatement)49 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)9 Column (liquibase.structure.core.Column)8 DB2Database (liquibase.database.core.DB2Database)7 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)7 ReorganizeTableStatement (liquibase.statement.core.ReorganizeTableStatement)7 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)6 DatabaseException (liquibase.exception.DatabaseException)6 Database (liquibase.database.Database)5 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)5 Sql (liquibase.sql.Sql)5 RawSqlStatement (liquibase.statement.core.RawSqlStatement)5 UpdateStatement (liquibase.statement.core.UpdateStatement)5 Index (liquibase.structure.core.Index)5 Change (liquibase.change.Change)4 ColumnConfig (liquibase.change.ColumnConfig)4 AddColumnChange (liquibase.change.core.AddColumnChange)3 PostgresDatabase (liquibase.database.core.PostgresDatabase)3 AlterTableVisitor (liquibase.database.core.SQLiteDatabase.AlterTableVisitor)3