use of liquibase.sql.visitor.SqlVisitor in project liquibase by liquibase.
the class AbstractJdbcDatabaseTest method executeRollbackStatements_WithStatementsOverload_ShouldIncludeAppendTextFromApplyToRollbackTrueVisitor.
@Test
public void executeRollbackStatements_WithStatementsOverload_ShouldIncludeAppendTextFromApplyToRollbackTrueVisitor() throws Exception {
Database database = getDatabase();
final MockExecutor mockExecutor = new MockExecutor();
ExecutorService.getInstance().setExecutor(database, mockExecutor);
final List<SqlVisitor> sqlVisitors = new ArrayList<SqlVisitor>();
final SqlStatement dropTableStatement = new DropTableStatement(null, null, "test_table", false);
final AppendSqlVisitor appendSqlVisitor = new AppendSqlVisitor();
appendSqlVisitor.setApplyToRollback(true);
appendSqlVisitor.setValue(" SHOULD BE APPENDED");
sqlVisitors.add(appendSqlVisitor);
database.executeRollbackStatements(new SqlStatement[] { dropTableStatement }, sqlVisitors);
assertEquals("DROP TABLE test_table SHOULD BE APPENDED;", mockExecutor.getRanSql().trim());
}
use of liquibase.sql.visitor.SqlVisitor in project liquibase by liquibase.
the class AbstractJdbcDatabaseTest method executeRollbackStatements_WithChangeOverload_ShouldNotIncludeAppendTextFromApplyToRollbackFalseVisitor.
@Test
public void executeRollbackStatements_WithChangeOverload_ShouldNotIncludeAppendTextFromApplyToRollbackFalseVisitor() throws Exception {
Database database = getDatabase();
final MockExecutor mockExecutor = new MockExecutor();
ExecutorService.getInstance().setExecutor(database, mockExecutor);
final List<SqlVisitor> sqlVisitors = new ArrayList<SqlVisitor>();
final CreateTableChange change = new CreateTableChange();
change.setTableName("test_table");
final AppendSqlVisitor appendSqlVisitor = new AppendSqlVisitor();
appendSqlVisitor.setApplyToRollback(false);
appendSqlVisitor.setValue(" SHOULD NOT BE APPENDED");
sqlVisitors.add(appendSqlVisitor);
database.executeRollbackStatements(change, sqlVisitors);
assertEquals("DROP TABLE test_table;", mockExecutor.getRanSql().trim());
}
use of liquibase.sql.visitor.SqlVisitor in project liquibase by liquibase.
the class ContextChangeSetFilter method accepts.
@Override
public ChangeSetFilterResult accepts(ChangeSet changeSet) {
List<SqlVisitor> visitorsToRemove = new ArrayList<SqlVisitor>();
for (SqlVisitor visitor : changeSet.getSqlVisitors()) {
if (visitor.getContexts() != null && !visitor.getContexts().matches(contexts)) {
visitorsToRemove.add(visitor);
}
}
changeSet.getSqlVisitors().removeAll(visitorsToRemove);
if (contexts == null || contexts.isEmpty()) {
return new ChangeSetFilterResult(true, "No runtime context specified, all contexts will run", this.getClass());
}
Collection<ContextExpression> inheritableContexts = changeSet.getInheritableContexts();
if (changeSet.getContexts().isEmpty() && inheritableContexts.isEmpty()) {
return new ChangeSetFilterResult(true, "Change set runs under all contexts", this.getClass());
}
if (changeSet.getContexts().matches(contexts) && ContextExpression.matchesAll(inheritableContexts, contexts)) {
return new ChangeSetFilterResult(true, "Context matches '" + contexts.toString() + "'", this.getClass());
} else {
return new ChangeSetFilterResult(false, "Context does not match '" + contexts.toString() + "'", this.getClass());
}
}
use of liquibase.sql.visitor.SqlVisitor in project liquibase by liquibase.
the class DbmsChangeSetFilter method accepts.
@Override
public ChangeSetFilterResult accepts(ChangeSet changeSet) {
if (database == null) {
return new ChangeSetFilterResult(true, "No database connection, cannot evaluate dbms attribute", this.getClass());
}
List<SqlVisitor> visitorsToRemove = new ArrayList<SqlVisitor>();
for (SqlVisitor visitor : changeSet.getSqlVisitors()) {
if (!DatabaseList.definitionMatches(visitor.getApplicableDbms(), database, true)) {
visitorsToRemove.add(visitor);
}
}
changeSet.getSqlVisitors().removeAll(visitorsToRemove);
String dbmsList;
if (changeSet.getDbmsSet() == null || changeSet.getDbmsSet().size() == 0) {
dbmsList = "all databases";
} else {
dbmsList = "'" + StringUtils.join(changeSet.getDbmsSet(), ", ") + "'";
}
if (DatabaseList.definitionMatches(changeSet.getDbmsSet(), database, true)) {
return new ChangeSetFilterResult(true, "Database '" + database.getShortName() + "' matches " + dbmsList, this.getClass());
} else {
return new ChangeSetFilterResult(false, "Database '" + database.getShortName() + "' does not match " + dbmsList, this.getClass());
}
}
use of liquibase.sql.visitor.SqlVisitor in project liquibase by liquibase.
the class LabelChangeSetFilter method accepts.
@Override
public ChangeSetFilterResult accepts(ChangeSet changeSet) {
List<SqlVisitor> visitorsToRemove = new ArrayList<SqlVisitor>();
for (SqlVisitor visitor : changeSet.getSqlVisitors()) {
if (visitor.getLabels() != null && !labelExpression.matches(visitor.getLabels())) {
visitorsToRemove.add(visitor);
}
}
changeSet.getSqlVisitors().removeAll(visitorsToRemove);
if (labelExpression == null || labelExpression.isEmpty()) {
return new ChangeSetFilterResult(true, "No runtime labels specified, all labels will run", this.getClass());
}
if (changeSet.getLabels() == null || changeSet.getLabels().isEmpty()) {
return new ChangeSetFilterResult(true, "Change set runs under all labels", this.getClass());
}
if (labelExpression.matches(changeSet.getLabels())) {
return new ChangeSetFilterResult(true, "Labels matches '" + labelExpression.toString() + "'", this.getClass());
} else {
return new ChangeSetFilterResult(false, "Labels does not match '" + labelExpression.toString() + "'", this.getClass());
}
}
Aggregations