use of liquibase.statement.core.DeleteStatement 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.core.DeleteStatement in project liquibase by liquibase.
the class CustomChange method generateRollbackStatements.
@Override
public SqlStatement[] generateRollbackStatements(Database database) throws CustomChangeException, RollbackImpossibleException {
SqlStatement[] st = new SqlStatement[1];
DeleteStatement ds = new DeleteStatement(null, null, "persons");
ds.setWhereClause("id=1");
st[0] = ds;
return st;
}
use of liquibase.statement.core.DeleteStatement in project liquibase by liquibase.
the class DeleteGeneratorTest method testGenerateSql.
@Test
public void testGenerateSql() {
// given
DeleteStatement statement = new DeleteStatement(null, null, "DATABASECHANGELOG");
statement.setWhere(":name = :value AND :name = :value AND :name = :value");
statement.addWhereColumnName("ID");
statement.addWhereColumnName("AUTHOR");
statement.addWhereColumnName("FILENAME");
statement.addWhereParameter("1");
statement.addWhereParameter("a");
statement.addWhereParameter("server_principals/BUILTIN$Administrators.xml");
Database database = new MSSQLDatabase();
DeleteGenerator generator = new DeleteGenerator();
// when
Sql[] sqls = generator.generateSql(statement, database, null);
// then
assertEquals("DELETE FROM [DATABASECHANGELOG] " + "WHERE [ID] = '1' " + "AND [AUTHOR] = 'a' " + "AND [FILENAME] = 'server_principals/BUILTIN$Administrators.xml'", sqls[0].toSql());
}
use of liquibase.statement.core.DeleteStatement in project liquibase by liquibase.
the class DeleteDataChange method generateStatements.
@Override
public SqlStatement[] generateStatements(Database database) {
DeleteStatement statement = new DeleteStatement(getCatalogName(), getSchemaName(), getTableName());
statement.setWhereClause(where);
for (ColumnConfig whereParam : whereParams) {
if (whereParam.getName() != null) {
statement.addWhereColumnName(whereParam.getName());
}
statement.addWhereParameter(whereParam.getValueObject());
}
return new SqlStatement[] { statement };
}
Aggregations