01: package liquibase.parser;
02:
03: import liquibase.ChangeSet;
04: import liquibase.DatabaseChangeLog;
05: import liquibase.exception.LiquibaseException;
06: import liquibase.parser.filter.ChangeSetFilter;
07: import liquibase.parser.visitor.ChangeSetVisitor;
08:
09: import java.util.Arrays;
10: import java.util.Collections;
11: import java.util.List;
12:
13: public class ChangeLogIterator {
14: private DatabaseChangeLog databaseChangeLog;
15: private List<ChangeSetFilter> changeSetFilters;
16:
17: public ChangeLogIterator(DatabaseChangeLog databaseChangeLog,
18: ChangeSetFilter... changeSetFilters) {
19: this .databaseChangeLog = databaseChangeLog;
20: this .changeSetFilters = Arrays.asList(changeSetFilters);
21: }
22:
23: public void run(ChangeSetVisitor visitor) throws LiquibaseException {
24: List<ChangeSet> changeSetList = databaseChangeLog
25: .getChangeSets();
26: if (visitor.getDirection().equals(
27: ChangeSetVisitor.Direction.REVERSE)) {
28: Collections.reverse(changeSetList);
29: }
30:
31: for (ChangeSet changeSet : changeSetList) {
32: boolean shouldVisit = true;
33: if (changeSetFilters != null) {
34: for (ChangeSetFilter filter : changeSetFilters) {
35: if (!filter.accepts(changeSet)) {
36: shouldVisit = false;
37: break;
38: }
39: }
40: }
41:
42: if (shouldVisit) {
43: visitor.visit(changeSet);
44: }
45: }
46: }
47: }
|