Search in sources :

Example 1 with DeleteStatement

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()]);
}
Also used : SqlStatement(liquibase.statement.SqlStatement) InsertOrUpdateStatement(liquibase.statement.core.InsertOrUpdateStatement) ArrayList(java.util.ArrayList) DeleteStatement(liquibase.statement.core.DeleteStatement)

Example 2 with DeleteStatement

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;
}
Also used : SqlStatement(liquibase.statement.SqlStatement) DeleteStatement(liquibase.statement.core.DeleteStatement)

Example 3 with DeleteStatement

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());
}
Also used : MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Database(liquibase.database.Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) DeleteStatement(liquibase.statement.core.DeleteStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Example 4 with DeleteStatement

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 };
}
Also used : SqlStatement(liquibase.statement.SqlStatement) DeleteStatement(liquibase.statement.core.DeleteStatement)

Aggregations

DeleteStatement (liquibase.statement.core.DeleteStatement)4 SqlStatement (liquibase.statement.SqlStatement)3 ArrayList (java.util.ArrayList)1 Database (liquibase.database.Database)1 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)1 Sql (liquibase.sql.Sql)1 InsertOrUpdateStatement (liquibase.statement.core.InsertOrUpdateStatement)1 Test (org.junit.Test)1