use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class Liquibase method rollback.
public void rollback(int changesToRollback, String rollbackScript, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
ExecutorService.getInstance().setExecutor(database, new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database));
outputHeader("Rollback " + changesToRollback + " Change(s) Script");
rollback(changesToRollback, rollbackScript, contexts, labelExpression);
try {
output.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
ExecutorService.getInstance().setExecutor(database, oldTemplate);
resetServices();
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class Liquibase method executeRollbackScript.
protected void executeRollbackScript(String rollbackScript, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
final Executor executor = ExecutorService.getInstance().getExecutor(database);
String rollbackScriptContents;
try {
Set<InputStream> streams = resourceAccessor.getResourcesAsStream(rollbackScript);
if (streams == null || streams.size() == 0) {
throw new LiquibaseException("Cannot find rollbackScript " + rollbackScript);
} else if (streams.size() > 1) {
throw new LiquibaseException("Found multiple rollbackScripts named " + rollbackScript);
}
rollbackScriptContents = StreamUtil.getStreamContents(streams.iterator().next());
} catch (IOException e) {
throw new LiquibaseException("Error reading rollbackScript " + executor + ": " + e.getMessage());
}
RawSQLChange rollbackChange = new RawSQLChange(rollbackScriptContents);
rollbackChange.setSplitStatements(true);
rollbackChange.setStripComments(true);
try {
executor.execute(rollbackChange);
} catch (DatabaseException e) {
e = new DatabaseException("Error executing rollback script. ChangeSets will still be marked as rolled back: " + e.getMessage(), e);
System.err.println(e.getMessage());
log.severe("Error executing rollback script", e);
if (changeExecListener != null) {
changeExecListener.runFailed(null, databaseChangeLog, database, e);
}
}
database.commit();
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class ValidatingVisitorPreConditionsTest method testPreConditionsForOracleOnMSSQLWithChangeLog.
/**
* Test the same precondition from a changelog with mssql database, this
* should not fail on the validation but just mark is as handled.
*/
@Test
public void testPreConditionsForOracleOnMSSQLWithChangeLog() {
// create the pre condition
PreconditionContainer preCondition = new PreconditionContainer();
preCondition.setOnFail(PreconditionContainer.FailOption.MARK_RAN.toString());
DBMSPrecondition dbmsPrecondition = new DBMSPrecondition();
dbmsPrecondition.setType("oracle");
preCondition.addNestedPrecondition(dbmsPrecondition);
changeSet1.setPreconditions(preCondition);
MSSQLDatabase mssqlDb = new MSSQLDatabase() {
@Override
public List<RanChangeSet> getRanChangeSetList() throws DatabaseException {
return new ArrayList<RanChangeSet>();
}
@Override
public void rollback() throws DatabaseException {
//super.rollback();
}
};
String[] empty = {};
boolean exceptionThrown = false;
try {
// call the validate which gives the error
changeLog.validate(mssqlDb, empty);
} catch (LiquibaseException ex) {
System.out.println(ex.getMessage());
exceptionThrown = true;
}
assertFalse(exceptionThrown);
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class Liquibase method rollback.
public void rollback(Date dateToRollBackTo, String rollbackScript, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
ExecutorService.getInstance().setExecutor(database, new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database));
outputHeader("Rollback to " + dateToRollBackTo + " Script");
rollback(dateToRollBackTo, contexts, labelExpression);
try {
output.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
ExecutorService.getInstance().setExecutor(database, oldTemplate);
resetServices();
}
use of liquibase.exception.LiquibaseException in project liquibase by liquibase.
the class Liquibase method calculateCheckSum.
public CheckSum calculateCheckSum(final String filename, final String id, final String author) throws LiquibaseException {
log.info(String.format("Calculating checksum for changeset %s::%s::%s", filename, id, author));
final ChangeLogParameters changeLogParameters = this.getChangeLogParameters();
final ResourceAccessor resourceAccessor = this.getResourceAccessor();
final DatabaseChangeLog changeLog = ChangeLogParserFactory.getInstance().getParser(this.changeLogFile, resourceAccessor).parse(this.changeLogFile, changeLogParameters, resourceAccessor);
// TODO: validate?
final ChangeSet changeSet = changeLog.getChangeSet(filename, author, id);
if (changeSet == null) {
throw new LiquibaseException(new IllegalArgumentException("No such changeSet: " + filename + "::" + id + "::" + author));
}
return changeSet.generateCheckSum();
}
Aggregations