Search in sources :

Example 6 with Executor

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

the class Liquibase method futureRollbackSQL.

protected void futureRollbackSQL(Integer count, String tag, Contexts contexts, LabelExpression labelExpression, Writer output, boolean checkLiquibaseTables) 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 roll back currently unexecuted changes");
    LockService lockService = LockServiceFactory.getInstance().getLockService(database);
    lockService.waitForLock();
    try {
        DatabaseChangeLog changeLog = getDatabaseChangeLog();
        if (checkLiquibaseTables) {
            checkLiquibaseTables(false, changeLog, contexts, labelExpression);
        }
        ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).generateDeploymentId();
        changeLog.validate(database, contexts, labelExpression);
        ChangeLogIterator logIterator;
        if (count == null && tag == null) {
            logIterator = new ChangeLogIterator(changeLog, new NotRanChangeSetFilter(database.getRanChangeSetList()), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database));
        } else if (count != null) {
            ChangeLogIterator forwardIterator = new ChangeLogIterator(changeLog, new NotRanChangeSetFilter(database.getRanChangeSetList()), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database), new CountChangeSetFilter(count));
            final ListVisitor listVisitor = new ListVisitor();
            forwardIterator.run(listVisitor, new RuntimeEnvironment(database, contexts, labelExpression));
            logIterator = new ChangeLogIterator(changeLog, new NotRanChangeSetFilter(database.getRanChangeSetList()), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database), new ChangeSetFilter() {

                @Override
                public ChangeSetFilterResult accepts(ChangeSet changeSet) {
                    return new ChangeSetFilterResult(listVisitor.getSeenChangeSets().contains(changeSet), null, null);
                }
            });
        } else {
            List<RanChangeSet> ranChangeSetList = database.getRanChangeSetList();
            ChangeLogIterator forwardIterator = new ChangeLogIterator(changeLog, new NotRanChangeSetFilter(ranChangeSetList), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database), new UpToTagChangeSetFilter(tag, ranChangeSetList));
            final ListVisitor listVisitor = new ListVisitor();
            forwardIterator.run(listVisitor, new RuntimeEnvironment(database, contexts, labelExpression));
            logIterator = new ChangeLogIterator(changeLog, new NotRanChangeSetFilter(ranChangeSetList), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database), new ChangeSetFilter() {

                @Override
                public ChangeSetFilterResult accepts(ChangeSet changeSet) {
                    return new ChangeSetFilterResult(listVisitor.getSeenChangeSets().contains(changeSet), null, null);
                }
            });
        }
        logIterator.run(new RollbackVisitor(database, changeExecListener), new RuntimeEnvironment(database, contexts, labelExpression));
    } finally {
        try {
            lockService.releaseLock();
        } catch (LockException e) {
            log.severe("Could not release lock", e);
        }
        ExecutorService.getInstance().setExecutor(database, oldTemplate);
        resetServices();
    }
    try {
        output.flush();
    } catch (IOException e) {
        throw new LiquibaseException(e);
    }
}
Also used : LockService(liquibase.lockservice.LockService) Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) LockException(liquibase.exception.LockException) LoggingExecutor(liquibase.executor.LoggingExecutor) List(java.util.List) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 7 with Executor

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

the class Liquibase method update.

public void update(String tag, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
    if (tag == null) {
        update(contexts, labelExpression, output);
        return;
    }
    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 to '" + tag + "' Database Script");
    update(tag, 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 8 with Executor

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

the class Liquibase method outputHeader.

private void outputHeader(String message) throws DatabaseException {
    Executor executor = ExecutorService.getInstance().getExecutor(database);
    executor.comment("*********************************************************************");
    executor.comment(message);
    executor.comment("*********************************************************************");
    executor.comment("Change Log: " + changeLogFile);
    executor.comment("Ran at: " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()));
    DatabaseConnection connection = getDatabase().getConnection();
    if (connection != null) {
        executor.comment("Against: " + connection.getConnectionUserName() + "@" + connection.getURL());
    }
    executor.comment("Liquibase version: " + LiquibaseUtil.getBuildVersion());
    executor.comment("*********************************************************************" + StreamUtil.getLineSeparator());
    if (database instanceof OracleDatabase) {
        executor.execute(new RawSqlStatement("SET DEFINE OFF;"));
    }
    if (database instanceof MSSQLDatabase && database.getDefaultCatalogName() != null) {
        executor.execute(new RawSqlStatement("USE " + database.escapeObjectName(database.getDefaultCatalogName(), Catalog.class) + ";"));
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) RawSqlStatement(liquibase.statement.core.RawSqlStatement) Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) DatabaseConnection(liquibase.database.DatabaseConnection) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Date(java.util.Date)

Example 9 with Executor

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

the class Liquibase method markNextChangeSetRan.

public void markNextChangeSetRan(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");
    markNextChangeSetRan(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 10 with Executor

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

the class Liquibase method rollback.

public void rollback(String tagToRollBackTo, 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 '" + tagToRollBackTo + "' Script");
    rollback(tagToRollBackTo, 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)27 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)16 LiquibaseException (liquibase.exception.LiquibaseException)15 LoggingExecutor (liquibase.executor.LoggingExecutor)13 DatabaseException (liquibase.exception.DatabaseException)9 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)6 RawSqlStatement (liquibase.statement.core.RawSqlStatement)4 Map (java.util.Map)3 Change (liquibase.change.Change)3 RawSQLChange (liquibase.change.core.RawSQLChange)3 Database (liquibase.database.Database)3 DB2Database (liquibase.database.core.DB2Database)3 LockException (liquibase.exception.LockException)3 LockService (liquibase.lockservice.LockService)3 ParsedNodeException (liquibase.parser.core.ParsedNodeException)3 InvalidExampleException (liquibase.snapshot.InvalidExampleException)3 Sql (liquibase.sql.Sql)3 SqlStatement (liquibase.statement.SqlStatement)3 List (java.util.List)2 ColumnConfig (liquibase.change.ColumnConfig)2