Search in sources :

Example 6 with LockException

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

the class Liquibase method changeLogSync.

public void changeLogSync(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(true, changeLog, contexts, labelExpression);
        ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).generateDeploymentId();
        changeLog.validate(database, contexts, labelExpression);
        ChangeLogIterator logIterator = new ChangeLogIterator(changeLog, new NotRanChangeSetFilter(database.getRanChangeSetList()), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database));
        logIterator.run(new ChangeLogSyncVisitor(database, changeLogSyncListener), 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)

Example 7 with LockException

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

the class Liquibase method rollback.

public void rollback(Date dateToRollBackTo, 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);
        List<RanChangeSet> ranChangeSetList = database.getRanChangeSetList();
        ChangeLogIterator logIterator = new ChangeLogIterator(ranChangeSetList, changeLog, new ExecutedAfterChangeSetFilter(dateToRollBackTo, ranChangeSetList), new AlreadyRanChangeSetFilter(ranChangeSetList, ignoreClasspathPrefix), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database));
        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("Could not release lock", e);
        }
    }
    resetServices();
}
Also used : LockService(liquibase.lockservice.LockService) LockException(liquibase.exception.LockException)

Example 8 with LockException

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

the class Liquibase method rollback.

public void rollback(String tagToRollBackTo, 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);
        List<RanChangeSet> ranChangeSetList = database.getRanChangeSetList();
        ChangeLogIterator logIterator = new ChangeLogIterator(ranChangeSetList, changeLog, new AfterTagChangeSetFilter(tagToRollBackTo, ranChangeSetList), new AlreadyRanChangeSetFilter(ranChangeSetList, ignoreClasspathPrefix), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database));
        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("Could not release lock", e);
        }
    }
    resetServices();
}
Also used : LockService(liquibase.lockservice.LockService) LockException(liquibase.exception.LockException)

Example 9 with LockException

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

the class Liquibase method generateDocumentation.

public void generateDocumentation(String outputDirectory, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
    log.info("Generating Database Documentation");
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    LockService lockService = LockServiceFactory.getInstance().getLockService(database);
    lockService.waitForLock();
    try {
        DatabaseChangeLog changeLog = getDatabaseChangeLog();
        checkLiquibaseTables(false, changeLog, new Contexts(), new LabelExpression());
        changeLog.validate(database, contexts, labelExpression);
        ChangeLogIterator logIterator = new ChangeLogIterator(changeLog, new DbmsChangeSetFilter(database));
        DBDocVisitor visitor = new DBDocVisitor(database);
        logIterator.run(visitor, new RuntimeEnvironment(database, contexts, labelExpression));
        visitor.writeHTML(new File(outputDirectory), resourceAccessor);
    } catch (IOException e) {
        throw new LiquibaseException(e);
    } finally {
        try {
            lockService.releaseLock();
        } catch (LockException e) {
            log.severe("Could not release lock", e);
        }
    }
//        try {
//            if (!LockService.getExecutor(database).waitForLock()) {
//                return;
//            }
//
//            DBDocChangeLogHandler changeLogHandler = new DBDocChangeLogHandler(outputDirectory, this, changeLogFile,resourceAccessor);
//            runChangeLogs(changeLogHandler);
//
//            changeLogHandler.writeHTML(this);
//        } finally {
//            releaseLock();
//        }
}
Also used : LockService(liquibase.lockservice.LockService) LockException(liquibase.exception.LockException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 10 with LockException

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

the class Liquibase method update.

public void update(Contexts contexts, LabelExpression labelExpression, boolean checkLiquibaseTables) throws LiquibaseException {
    LockService lockService = LockServiceFactory.getInstance().getLockService(database);
    lockService.waitForLock();
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    try {
        DatabaseChangeLog changeLog = getDatabaseChangeLog();
        if (checkLiquibaseTables) {
            checkLiquibaseTables(true, changeLog, contexts, labelExpression);
        }
        ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).generateDeploymentId();
        changeLog.validate(database, contexts, labelExpression);
        ChangeLogIterator changeLogIterator = getStandardChangelogIterator(contexts, labelExpression, changeLog);
        changeLogIterator.run(createUpdateVisitor(), new RuntimeEnvironment(database, contexts, labelExpression));
    } finally {
        database.setObjectQuotingStrategy(ObjectQuotingStrategy.LEGACY);
        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