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()]);
}
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()]);
}
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 };
}
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];
}
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()]);
}
Aggregations