01: package liquibase.parser.filter;
02:
03: import liquibase.ChangeSet;
04: import liquibase.RanChangeSet;
05: import liquibase.exception.RollbackFailedException;
06:
07: import java.util.HashSet;
08: import java.util.List;
09: import java.util.Set;
10:
11: public class AfterTagChangeSetFilter implements ChangeSetFilter {
12:
13: private Set<String> changeLogsAfterTag = new HashSet<String>();
14:
15: public AfterTagChangeSetFilter(String tag,
16: List<RanChangeSet> ranChangeSets)
17: throws RollbackFailedException {
18: boolean seenTag = false;
19: for (RanChangeSet ranChangeSet : ranChangeSets) {
20: if (seenTag && !tag.equalsIgnoreCase(ranChangeSet.getTag())) {
21: changeLogsAfterTag.add(changeLogToString(ranChangeSet
22: .getId(), ranChangeSet.getAuthor(),
23: ranChangeSet.getChangeLog()));
24: }
25:
26: if (!seenTag && tag.equalsIgnoreCase(ranChangeSet.getTag())) {
27: seenTag = true;
28: }
29: }
30:
31: if (!seenTag) {
32: throw new RollbackFailedException("Could not find tag '"
33: + tag + "' in the database");
34: }
35: }
36:
37: private String changeLogToString(String id, String author,
38: String changeLog) {
39: return id + ":" + author + ":" + changeLog;
40: }
41:
42: public boolean accepts(ChangeSet changeSet) {
43: return changeLogsAfterTag.contains(changeLogToString(changeSet
44: .getId(), changeSet.getAuthor(), changeSet
45: .getFilePath()));
46: }
47: }
|