| 1 |  |  package liquibase.precondition.core; | 
  | 2 |  |   | 
  | 3 |  |  import liquibase.changelog.ChangeSet; | 
  | 4 |  |  import liquibase.changelog.DatabaseChangeLog; | 
  | 5 |  |  import liquibase.changelog.RanChangeSet; | 
  | 6 |  |  import liquibase.database.Database; | 
  | 7 |  |  import liquibase.exception.PreconditionErrorException; | 
  | 8 |  |  import liquibase.exception.PreconditionFailedException; | 
  | 9 |  |  import liquibase.exception.ValidationErrors; | 
  | 10 |  |  import liquibase.exception.Warnings; | 
  | 11 |  |  import liquibase.precondition.Precondition; | 
  | 12 |  |   | 
  | 13 | 8 |  public class ChangeSetExecutedPrecondition implements Precondition { | 
  | 14 |  |   | 
  | 15 |  |      private String changeLogFile; | 
  | 16 |  |      private String id; | 
  | 17 |  |      private String author; | 
  | 18 |  |   | 
  | 19 |  |      public String getChangeLogFile() { | 
  | 20 | 0 |          return changeLogFile; | 
  | 21 |  |      } | 
  | 22 |  |   | 
  | 23 |  |      public void setChangeLogFile(String changeLogFile) { | 
  | 24 | 0 |          this.changeLogFile = changeLogFile; | 
  | 25 | 0 |      } | 
  | 26 |  |   | 
  | 27 |  |      public String getId() { | 
  | 28 | 0 |          return id; | 
  | 29 |  |      } | 
  | 30 |  |   | 
  | 31 |  |      public void setId(String id) { | 
  | 32 | 0 |          this.id = id; | 
  | 33 | 0 |      } | 
  | 34 |  |   | 
  | 35 |  |      public String getAuthor() { | 
  | 36 | 0 |          return author; | 
  | 37 |  |      } | 
  | 38 |  |   | 
  | 39 |  |      public void setAuthor(String author) { | 
  | 40 | 0 |          this.author = author; | 
  | 41 | 0 |      } | 
  | 42 |  |   | 
  | 43 |  |      public Warnings warn(Database database) { | 
  | 44 | 0 |          return new Warnings(); | 
  | 45 |  |      } | 
  | 46 |  |   | 
  | 47 |  |      public ValidationErrors validate(Database database) { | 
  | 48 | 0 |          return new ValidationErrors(); | 
  | 49 |  |      } | 
  | 50 |  |   | 
  | 51 |  |      public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) | 
  | 52 |  |              throws PreconditionFailedException, PreconditionErrorException { | 
  | 53 | 0 |          ChangeSet interestedChangeSet = new ChangeSet(getId(), getAuthor(), false, false, getChangeLogFile(), null, | 
  | 54 |  |                  null, false); | 
  | 55 |  |          RanChangeSet ranChangeSet; | 
  | 56 |  |          try { | 
  | 57 | 0 |              ranChangeSet = database.getRanChangeSet(interestedChangeSet); | 
  | 58 | 0 |          } catch (Exception e) { | 
  | 59 | 0 |              throw new PreconditionErrorException(e, changeLog, this); | 
  | 60 | 0 |          } | 
  | 61 | 0 |          if (ranChangeSet == null || ranChangeSet.getExecType() == null || !ranChangeSet.getExecType().ran) { | 
  | 62 | 0 |              throw new PreconditionFailedException("Change Set '" + interestedChangeSet.toString(false) | 
  | 63 |  |                      + "' has not been run", changeLog, this); | 
  | 64 |  |          } | 
  | 65 | 0 |      } | 
  | 66 |  |   | 
  | 67 |  |      public String getName() { | 
  | 68 | 8 |          return "changeSetExecuted"; | 
  | 69 |  |      } | 
  | 70 |  |  } |