database = liquibase.getDatabase(); if (database.hasDatabaseChangeLogLockTable() && isLocked()) { LockService.getInstance(database).forceReleaseLock();
/** * This method currently checks the liquibasechangeloglock table to see if there is a row * with a lock in it. This uses the liquibase API to do this * * @return true if database is currently locked */ public static boolean isLocked() { Database database = null; try { Liquibase liquibase = getLiquibase(null, null); database = liquibase.getDatabase(); return LockService.getInstance(database).listLocks().length > 0; } catch (Exception e) { return false; } finally { try { database.getConnection().close(); } catch (Exception e) { // pass } } } }
/** * Interface used for callbacks when updating the database. Implement this interface and pass it * to {@link DatabaseUpdater#executeChangelog(String, Map, ChangeSetExecutorCallback)} */ public interface ChangeSetExecutorCallback { /** * This method is called after each changeset is executed. * * @param changeSet the liquibase changeset that was just run * @param numChangeSetsToRun the total number of changesets in the current file */ public void executing(ChangeSet changeSet, int numChangeSetsToRun); }
public void releaseLocks() throws Exception { LockService lockService = LockServiceFactory.getInstance().getLockService(database); lockService.forceReleaseLock(); System.out.println("successfully released the database"); }