liquibase.changelog.visitor.RollbackVisitor Maven / Gradle / Ivy
package liquibase.changelog.visitor;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.DatabaseChangeLog;
import liquibase.changelog.filter.ChangeSetFilterResult;
import liquibase.database.Database;
import liquibase.exception.LiquibaseException;
import liquibase.logging.LogService;
import liquibase.logging.LogType;
import java.util.Set;
public class RollbackVisitor implements ChangeSetVisitor {
private Database database;
private ChangeExecListener execListener;
/**
* @deprecated - please use the constructor with ChangeExecListener, which can be null.
*/
@Deprecated
public RollbackVisitor(Database database) {
this.database = database;
}
public RollbackVisitor(Database database, ChangeExecListener listener) {
this(database);
this.execListener = listener;
}
@Override
public Direction getDirection() {
return ChangeSetVisitor.Direction.REVERSE;
}
@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set filterResults) throws LiquibaseException {
LogService.getLog(getClass()).info(LogType.USER_MESSAGE, "Rolling Back Changeset:" + changeSet);
changeSet.rollback(this.database, this.execListener);
this.database.removeRanStatus(changeSet);
sendRollbackEvent(changeSet, databaseChangeLog, database);
this.database.commit();
}
private void sendRollbackEvent(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database2) {
if (execListener != null) {
execListener.rolledBack(changeSet, databaseChangeLog, database);
}
}
}