liquibase.precondition.core.NotPrecondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
package liquibase.precondition.core;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.visitor.ChangeExecListener;
import liquibase.changelog.DatabaseChangeLog;
import liquibase.database.Database;
import liquibase.exception.PreconditionErrorException;
import liquibase.exception.PreconditionFailedException;
import liquibase.exception.ValidationErrors;
import liquibase.exception.Warnings;
import liquibase.precondition.Precondition;
import liquibase.precondition.PreconditionLogic;
/**
* Class for controling "not" logic in preconditions.
*/
public class NotPrecondition extends PreconditionLogic {
@Override
public Warnings warn(Database database) {
return new Warnings();
}
@Override
public ValidationErrors validate(Database database) {
return new ValidationErrors();
}
@Override
public String getSerializedObjectNamespace() {
return STANDARD_CHANGELOG_NAMESPACE;
}
@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet, ChangeExecListener changeExecListener)
throws PreconditionFailedException, PreconditionErrorException {
for (Precondition precondition : getNestedPreconditions()) {
boolean threwException = false;
try {
precondition.check(database, changeLog, changeSet, changeExecListener);
} catch (PreconditionFailedException e) {
//that's what we want with a Not precondition
threwException = true;
}
if (!threwException) {
throw new PreconditionFailedException("Not precondition failed", changeLog, this);
}
}
}
@Override
public String getName() {
return "not";
}
}