Search in sources :

Example 16 with LockException

use of liquibase.exception.LockException in project liquibase by liquibase.

the class Liquibase method rollback.

public void rollback(int changesToRollback, String rollbackScript, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    LockService lockService = LockServiceFactory.getInstance().getLockService(database);
    lockService.waitForLock();
    try {
        DatabaseChangeLog changeLog = getDatabaseChangeLog();
        checkLiquibaseTables(false, changeLog, contexts, labelExpression);
        changeLog.validate(database, contexts, labelExpression);
        changeLog.setIgnoreClasspathPrefix(ignoreClasspathPrefix);
        ChangeLogIterator logIterator = new ChangeLogIterator(database.getRanChangeSetList(), changeLog, new AlreadyRanChangeSetFilter(database.getRanChangeSetList(), ignoreClasspathPrefix), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database), new CountChangeSetFilter(changesToRollback));
        if (rollbackScript == null) {
            logIterator.run(new RollbackVisitor(database, changeExecListener), new RuntimeEnvironment(database, contexts, labelExpression));
        } else {
            executeRollbackScript(rollbackScript, contexts, labelExpression);
            removeRunStatus(logIterator, contexts, labelExpression);
        }
    } finally {
        try {
            lockService.releaseLock();
        } catch (LockException e) {
            log.severe("Error releasing lock", e);
        }
        resetServices();
    }
}
Also used : LockService(liquibase.lockservice.LockService) LockException(liquibase.exception.LockException)

Example 17 with LockException

use of liquibase.exception.LockException in project liquibase by liquibase.

the class Liquibase method clearCheckSums.

/**
     * Sets checksums to null so they will be repopulated next run
     */
public void clearCheckSums() throws LiquibaseException {
    log.info("Clearing database change log checksums");
    LockService lockService = LockServiceFactory.getInstance().getLockService(database);
    lockService.waitForLock();
    try {
        checkLiquibaseTables(false, null, new Contexts(), new LabelExpression());
        UpdateStatement updateStatement = new UpdateStatement(getDatabase().getLiquibaseCatalogName(), getDatabase().getLiquibaseSchemaName(), getDatabase().getDatabaseChangeLogTableName());
        updateStatement.addNewColumnValue("MD5SUM", null);
        ExecutorService.getInstance().getExecutor(database).execute(updateStatement);
        getDatabase().commit();
    } finally {
        try {
            lockService.releaseLock();
        } catch (LockException e) {
            log.severe("Could not release lock", e);
        }
    }
    resetServices();
}
Also used : UpdateStatement(liquibase.statement.core.UpdateStatement) LockService(liquibase.lockservice.LockService) LockException(liquibase.exception.LockException)

Example 18 with LockException

use of liquibase.exception.LockException in project liquibase by liquibase.

the class Liquibase method markNextChangeSetRan.

public void markNextChangeSetRan(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    LockService lockService = LockServiceFactory.getInstance().getLockService(database);
    lockService.waitForLock();
    try {
        DatabaseChangeLog changeLog = getDatabaseChangeLog();
        ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).generateDeploymentId();
        checkLiquibaseTables(false, changeLog, contexts, labelExpression);
        changeLog.validate(database, contexts, labelExpression);
        ChangeLogIterator logIterator = new ChangeLogIterator(changeLog, new NotRanChangeSetFilter(database.getRanChangeSetList()), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database), new CountChangeSetFilter(1));
        logIterator.run(new ChangeLogSyncVisitor(database), new RuntimeEnvironment(database, contexts, labelExpression));
    } finally {
        try {
            lockService.releaseLock();
        } catch (LockException e) {
            log.severe("Could not release lock", e);
        }
        resetServices();
    }
}
Also used : LockService(liquibase.lockservice.LockService) LockException(liquibase.exception.LockException)

Aggregations

LockException (liquibase.exception.LockException)18 LockService (liquibase.lockservice.LockService)13 LiquibaseException (liquibase.exception.LiquibaseException)5 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)5 DatabaseException (liquibase.exception.DatabaseException)4 Executor (liquibase.executor.Executor)3 InvalidExampleException (liquibase.snapshot.InvalidExampleException)3 Date (java.util.Date)2 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)2 Sql (liquibase.sql.Sql)2 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Database (liquibase.database.Database)1 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)1 JdbcConnection (liquibase.database.jvm.JdbcConnection)1 LoggingExecutor (liquibase.executor.LoggingExecutor)1 SqlStatement (liquibase.statement.SqlStatement)1