View Javadoc

1   package liquibase.changelog;
2   
3   import liquibase.change.CheckSum;
4   
5   import java.util.Date;
6   
7   /**
8    * Encapsulates information about a previously-ran change set. Used to build rollback statements.
9    */
10  public class RanChangeSet {
11      private final String changeLog;
12      private final String id;
13      private final String author;
14      private final CheckSum lastCheckSum;
15      private final Date dateExecuted;
16      private String tag;
17      private ChangeSet.ExecType execType;
18  
19      public RanChangeSet(ChangeSet changeSet) {
20          this(changeSet, null);
21      }
22  
23      public RanChangeSet(ChangeSet changeSet, ChangeSet.ExecType execType) {
24          this(changeSet.getFilePath(), changeSet.getId(), changeSet.getAuthor(), changeSet.generateCheckSum(),
25                  new Date(), null, execType);
26      }
27  
28      public RanChangeSet(String changeLog, String id, String author, CheckSum lastCheckSum, Date dateExecuted,
29              String tag, ChangeSet.ExecType execType) {
30          this.changeLog = changeLog;
31          this.id = id;
32          this.author = author;
33          this.lastCheckSum = lastCheckSum;
34          if (dateExecuted == null) {
35              this.dateExecuted = null;
36          } else {
37              this.dateExecuted = new Date(dateExecuted.getTime());
38          }
39          this.tag = tag;
40          this.execType = execType;
41      }
42  
43      public String getChangeLog() {
44          return changeLog;
45      }
46  
47      public String getId() {
48          return id;
49      }
50  
51      public String getAuthor() {
52          return author;
53      }
54  
55      public CheckSum getLastCheckSum() {
56          return lastCheckSum;
57      }
58  
59      public Date getDateExecuted() {
60          if (dateExecuted == null) {
61              return null;
62          }
63          return (Date) dateExecuted.clone();
64      }
65  
66      public String getTag() {
67          return tag;
68      }
69  
70      public void setTag(String tag) {
71          this.tag = tag;
72      }
73  
74      public ChangeSet.ExecType getExecType() {
75          return execType;
76      }
77  
78      @Override
79      public boolean equals(Object o) {
80          if (this == o) {
81              return true;
82          }
83          if (o == null || getClass() != o.getClass()) {
84              return false;
85          }
86  
87          final RanChangeSet that = (RanChangeSet) o;
88  
89          return author.equals(that.author) && changeLog.equals(that.changeLog) && id.equals(that.id);
90  
91      }
92  
93      @Override
94      public int hashCode() {
95          int result;
96          result = changeLog.hashCode();
97          result = 29 * result + id.hashCode();
98          result = 29 * result + author.hashCode();
99          return result;
100     }
101 
102     public boolean isSameAs(ChangeSet changeSet) {
103         return this.getChangeLog().replace('\\', '/').equalsIgnoreCase(changeSet.getFilePath().replace('\\', '/'))
104                 && this.getId().equalsIgnoreCase(changeSet.getId())
105                 && this.getAuthor().equalsIgnoreCase(changeSet.getAuthor());
106     }
107 }