Search in sources :

Example 6 with LoggingExecutor

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

the class PendingSQLWriter method writeBody.

@Override
protected void writeBody(Writer fileWriter, Object object, List<Change> ranChanges, List<Change> changesToRun) throws IOException, DatabaseHistoryException, DatabaseException {
    Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
    LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), fileWriter, database);
    ExecutorService.getInstance().setExecutor(database, loggingExecutor);
    try {
        if (changesToRun.size() == 0) {
            fileWriter.append("<b>NONE</b>");
        }
        fileWriter.append("<code><pre>");
        ChangeSet lastRunChangeSet = null;
        for (Change change : changesToRun) {
            ChangeSet thisChangeSet = change.getChangeSet();
            if (thisChangeSet.equals(lastRunChangeSet)) {
                continue;
            }
            lastRunChangeSet = thisChangeSet;
            String anchor = thisChangeSet.toString(false).replaceAll("\\W", "_");
            fileWriter.append("<a name='").append(anchor).append("'/>");
            try {
                thisChangeSet.execute(databaseChangeLog, null, this.database);
            } catch (MigrationFailedException e) {
                fileWriter.append("EXECUTION ERROR: ").append(ChangeFactory.getInstance().getChangeMetaData(change).getDescription()).append(": ").append(e.getMessage()).append("\n\n");
            }
        }
        fileWriter.append("</pre></code>");
    } finally {
        ExecutorService.getInstance().setExecutor(database, oldTemplate);
    }
}
Also used : LoggingExecutor(liquibase.executor.LoggingExecutor) Executor(liquibase.executor.Executor) MigrationFailedException(liquibase.exception.MigrationFailedException) LoggingExecutor(liquibase.executor.LoggingExecutor) Change(liquibase.change.Change) ChangeSet(liquibase.changelog.ChangeSet)

Example 7 with LoggingExecutor

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

the class OfflineChangeLogHistoryServiceTest method createService.

/**
     * Create OfflineChangeLogHistoryService and register LoggingExecutor
     */
private OfflineChangeLogHistoryService createService(Writer writer, String outputLiquibaseSql) {
    HsqlDatabase database = new HsqlDatabase();
    File changeLogCsvFile = new File(temporaryFolder.getRoot(), "changeLog.csv");
    OfflineConnection connection = new OfflineConnection("offline:hsqldb?changeLogFile=" + changeLogCsvFile.getAbsolutePath() + "&outputLiquibaseSql=" + outputLiquibaseSql, new ClassLoaderResourceAccessor());
    database.setConnection(connection);
    connection.attached(database);
    OfflineChangeLogHistoryService changeLogHistoryService = (OfflineChangeLogHistoryService) ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database);
    LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), writer, database);
    ExecutorService.getInstance().setExecutor(database, loggingExecutor);
    return changeLogHistoryService;
}
Also used : HsqlDatabase(liquibase.database.core.HsqlDatabase) LoggingExecutor(liquibase.executor.LoggingExecutor) OfflineConnection(liquibase.database.OfflineConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) File(java.io.File)

Example 8 with LoggingExecutor

use of liquibase.executor.LoggingExecutor 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 9 with LoggingExecutor

use of liquibase.executor.LoggingExecutor 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 10 with LoggingExecutor

use of liquibase.executor.LoggingExecutor 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)

Aggregations

LoggingExecutor (liquibase.executor.LoggingExecutor)12 Executor (liquibase.executor.Executor)11 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)10 LiquibaseException (liquibase.exception.LiquibaseException)9 LockService (liquibase.lockservice.LockService)2 File (java.io.File)1 List (java.util.List)1 Change (liquibase.change.Change)1 ChangeSet (liquibase.changelog.ChangeSet)1 Database (liquibase.database.Database)1 OfflineConnection (liquibase.database.OfflineConnection)1 HsqlDatabase (liquibase.database.core.HsqlDatabase)1 LockException (liquibase.exception.LockException)1 MigrationFailedException (liquibase.exception.MigrationFailedException)1 ParsedNodeException (liquibase.parser.core.ParsedNodeException)1 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)1 Sql (liquibase.sql.Sql)1 SqlStatement (liquibase.statement.SqlStatement)1 CommentStatement (liquibase.statement.core.CommentStatement)1 RuntimeStatement (liquibase.statement.core.RuntimeStatement)1