View Javadoc

1   package liquibase.precondition.core;
2   
3   import liquibase.changelog.DatabaseChangeLog;
4   import liquibase.changelog.ChangeSet;
5   import liquibase.database.Database;
6   import liquibase.exception.PreconditionErrorException;
7   import liquibase.exception.PreconditionFailedException;
8   import liquibase.exception.ValidationErrors;
9   import liquibase.exception.Warnings;
10  import liquibase.precondition.Precondition;
11  import liquibase.precondition.PreconditionLogic;
12  
13  import java.util.ArrayList;
14  import java.util.List;
15  
16  /**
17   * Class for controling "or" logic in preconditions.
18   */
19  public class OrPrecondition extends PreconditionLogic {
20  
21      public Warnings warn(Database database) {
22          return new Warnings();
23      }
24  
25      public ValidationErrors validate(Database database) {
26          return new ValidationErrors();
27      }
28  
29      public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet)
30              throws PreconditionFailedException, PreconditionErrorException {
31          boolean onePassed = false;
32          List<FailedPrecondition> failures = new ArrayList<FailedPrecondition>();
33          for (Precondition precondition : getNestedPreconditions()) {
34              try {
35                  precondition.check(database, changeLog, changeSet);
36                  onePassed = true;
37                  break;
38              } catch (PreconditionFailedException e) {
39                  failures.addAll(e.getFailedPreconditions());
40              }
41          }
42          if (!onePassed) {
43              throw new PreconditionFailedException(failures);
44          }
45      }
46  
47      public String getName() {
48          return "or";
49      }
50  }