Search in sources :

Example 31 with LiquibaseException

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();
}
Also used : Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) LoggingExecutor(liquibase.executor.LoggingExecutor) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 32 with LiquibaseException

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();
}
Also used : RawSQLChange(liquibase.change.core.RawSQLChange) Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException) DatabaseException(liquibase.exception.DatabaseException)

Example 33 with LiquibaseException

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);
}
Also used : PreconditionContainer(liquibase.precondition.core.PreconditionContainer) DBMSPrecondition(liquibase.precondition.core.DBMSPrecondition) ArrayList(java.util.ArrayList) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) LiquibaseException(liquibase.exception.LiquibaseException) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 34 with LiquibaseException

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();
}
Also used : Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) LoggingExecutor(liquibase.executor.LoggingExecutor) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 35 with LiquibaseException

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();
}
Also used : ResourceAccessor(liquibase.resource.ResourceAccessor) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Aggregations

LiquibaseException (liquibase.exception.LiquibaseException)38 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)23 Executor (liquibase.executor.Executor)12 Liquibase (liquibase.Liquibase)10 LoggingExecutor (liquibase.executor.LoggingExecutor)10 BuildException (org.apache.tools.ant.BuildException)8 IOException (java.io.IOException)7 Database (liquibase.database.Database)7 Contexts (liquibase.Contexts)6 DatabaseException (liquibase.exception.DatabaseException)5 ArrayList (java.util.ArrayList)4 ResourceAccessor (liquibase.resource.ResourceAccessor)4 FileResource (org.apache.tools.ant.types.resources.FileResource)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Writer (java.io.Writer)3 CatalogAndSchema (liquibase.CatalogAndSchema)3 OracleDatabase (liquibase.database.core.OracleDatabase)3 DiffOutputControl (liquibase.diff.output.DiffOutputControl)3 Test (org.junit.Test)3 File (java.io.File)2