Search in sources :

Example 31 with Executor

use of liquibase.executor.Executor in project liquibase by liquibase.

the class Liquibase method update.

public void update(int changesToApply, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
    LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database);
    ExecutorService.getInstance().setExecutor(database, loggingExecutor);
    outputHeader("Update " + changesToApply + " Change Sets Database Script");
    update(changesToApply, contexts, labelExpression);
    try {
        output.flush();
    } catch (IOException e) {
        throw new LiquibaseException(e);
    }
    resetServices();
    ExecutorService.getInstance().setExecutor(database, oldTemplate);
}
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 Executor

use of liquibase.executor.Executor 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 33 with Executor

use of liquibase.executor.Executor 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 34 with Executor

use of liquibase.executor.Executor in project liquibase by liquibase.

the class Liquibase method update.

public void update(Contexts contexts, LabelExpression labelExpression, Writer output, boolean checkLiquibaseTables) throws LiquibaseException {
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
    LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database);
    ExecutorService.getInstance().setExecutor(database, loggingExecutor);
    outputHeader("Update Database Script");
    LockService lockService = LockServiceFactory.getInstance().getLockService(database);
    lockService.waitForLock();
    try {
        update(contexts, labelExpression, checkLiquibaseTables);
        output.flush();
    } catch (IOException e) {
        throw new LiquibaseException(e);
    }
    ExecutorService.getInstance().setExecutor(database, oldTemplate);
}
Also used : Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) LockService(liquibase.lockservice.LockService) LoggingExecutor(liquibase.executor.LoggingExecutor) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 35 with Executor

use of liquibase.executor.Executor in project liquibase by liquibase.

the class Liquibase method changeLogSync.

public void changeLogSync(Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    LoggingExecutor outputTemplate = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database);
    Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
    ExecutorService.getInstance().setExecutor(database, outputTemplate);
    outputHeader("SQL to add all changesets to database history table");
    changeLogSync(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)

Aggregations

Executor (liquibase.executor.Executor)52 ExecutorService (liquibase.executor.ExecutorService)40 LoggingExecutor (liquibase.executor.LoggingExecutor)32 LiquibaseException (liquibase.exception.LiquibaseException)18 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)14 DatabaseException (liquibase.exception.DatabaseException)11 RawSqlStatement (liquibase.statement.core.RawSqlStatement)11 Database (liquibase.database.Database)8 SqlStatement (liquibase.statement.SqlStatement)7 RawSQLChange (liquibase.change.core.RawSQLChange)6 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)6 Map (java.util.Map)4 EmptyChange (liquibase.change.core.EmptyChange)4 ChangeSet (liquibase.changelog.ChangeSet)4 SnapshotControl (liquibase.snapshot.SnapshotControl)4 SQLException (java.sql.SQLException)3 DB2Database (liquibase.database.core.DB2Database)3 ParsedNodeException (liquibase.parser.core.ParsedNodeException)3 ErrorPrecondition (liquibase.precondition.ErrorPrecondition)3 FailedPrecondition (liquibase.precondition.FailedPrecondition)3