01: package liquibase.preconditions;
02:
03: import liquibase.DatabaseChangeLog;
04: import liquibase.database.Database;
05: import liquibase.exception.PreconditionFailedException;
06:
07: import java.util.ArrayList;
08: import java.util.List;
09:
10: /**
11: * Class for controling "or" logic in preconditions.
12: */
13: public class OrPrecondition extends PreconditionLogic {
14:
15: public void check(Database database, DatabaseChangeLog changeLog)
16: throws PreconditionFailedException {
17: boolean onePassed = false;
18: List<FailedPrecondition> failures = new ArrayList<FailedPrecondition>();
19: for (Precondition precondition : getNestedPreconditions()) {
20: try {
21: precondition.check(database, changeLog);
22: onePassed = true;
23: } catch (PreconditionFailedException e) {
24: failures.addAll(e.getFailedPreconditions());
25: }
26: }
27: if (!onePassed) {
28: throw new PreconditionFailedException(failures);
29: }
30: }
31:
32: public String getTagName() {
33: return "or";
34: }
35: }
|