this.changeSetFilters = Arrays.asList(changeSetFilters);
}
public void run(ChangeSetVisitor visitor, RuntimeEnvironment env) throws LiquibaseException {
Logger log = LogFactory.getLogger();
databaseChangeLog.setRuntimeEnvironment(env);
log.setChangeLog(databaseChangeLog);
try {
List<ChangeSet> changeSetList = new ArrayList<ChangeSet>(databaseChangeLog.getChangeSets());
if (visitor.getDirection().equals(ChangeSetVisitor.Direction.REVERSE)) {
Collections.reverse(changeSetList);
}
for (ChangeSet changeSet : changeSetList) {
boolean shouldVisit = true;
Set<ChangeSetFilterResult> reasonsAccepted = new HashSet<ChangeSetFilterResult>();
Set<ChangeSetFilterResult> reasonsDenied = new HashSet<ChangeSetFilterResult>();
if (changeSetFilters != null) {
for (ChangeSetFilter filter : changeSetFilters) {
ChangeSetFilterResult acceptsResult = filter.accepts(changeSet);
if (acceptsResult.isAccepted()) {
reasonsAccepted.add(acceptsResult);
} else {
shouldVisit = false;
reasonsDenied.add(acceptsResult);
break;
}
}
}
log.setChangeSet(changeSet);
if (shouldVisit) {
visitor.visit(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsAccepted);
} else {
if (visitor instanceof SkippedChangeSetVisitor) {
((SkippedChangeSetVisitor) visitor).skipped(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsDenied);
}
}
log.setChangeSet(null);
}
} finally {
log.setChangeLog(null);
databaseChangeLog.setRuntimeEnvironment(null);
}
}