Search in sources :

Example 16 with Liquibase

use of liquibase.Liquibase in project openmrs-core by openmrs.

the class DatabaseUpdater method releaseDatabaseLock.

/**
 * This method releases the liquibase db lock after a crashed database update. First, it
 * checks whether "liquibasechangeloglock" table exists in db. If so, it will check
 * whether the database is locked. If that is also true, this means that last attempted db
 * update crashed.<br>
 * <br>
 * This should only be called if the user is sure that no one else is currently running
 * database updates. This method should be used if there was a db crash while updates
 * were being written and the lock table was never cleaned up.
 *
 * @throws LockException
 */
public static synchronized void releaseDatabaseLock() throws LockException {
    Database database = null;
    try {
        Liquibase liquibase = getLiquibase(null, null);
        database = liquibase.getDatabase();
        if (database.hasDatabaseChangeLogLockTable() && isLocked()) {
            LockService.getInstance(database).forceReleaseLock();
        }
    } catch (Exception e) {
        throw new LockException(e);
    } finally {
        try {
            database.getConnection().close();
        } catch (Exception e) {
        // pass
        }
    }
}
Also used : Liquibase(liquibase.Liquibase) LockException(liquibase.exception.LockException) Database(liquibase.database.Database) LockException(liquibase.exception.LockException) SQLException(java.sql.SQLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 17 with Liquibase

use of liquibase.Liquibase in project traccar by traccar.

the class DataManager method initDatabaseSchema.

private void initDatabaseSchema() throws SQLException, LiquibaseException {
    if (config.hasKey("database.changelog")) {
        ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
        Database database = DatabaseFactory.getInstance().openDatabase(config.getString("database.url"), config.getString("database.user"), config.getString("database.password"), null, resourceAccessor);
        Liquibase liquibase = new Liquibase(config.getString("database.changelog"), resourceAccessor, database);
        liquibase.clearCheckSums();
        liquibase.update(new Contexts());
    }
}
Also used : Liquibase(liquibase.Liquibase) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) Database(liquibase.database.Database) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) Contexts(liquibase.Contexts)

Example 18 with Liquibase

use of liquibase.Liquibase in project microservice_framework by CJSCommonPlatform.

the class AbstractJdbcRepositoryIT method initDatabase.

private void initDatabase() throws Exception {
    Liquibase liquibase = new Liquibase(liquibaseLocation, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection()));
    liquibase.dropAll();
    liquibase.update("");
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 19 with Liquibase

use of liquibase.Liquibase in project microservice_framework by CJSCommonPlatform.

the class EventsPageIT method initEventDatabase.

private void initEventDatabase() throws Exception {
    Liquibase eventStoreLiquibase = new Liquibase(LIQUIBASE_EVENT_STORE_CHANGELOG_XML, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection()));
    eventStoreLiquibase.dropAll();
    eventStoreLiquibase.update("");
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 20 with Liquibase

use of liquibase.Liquibase in project microservice_framework by CJSCommonPlatform.

the class CakeShopPostgresIT method initDatabase.

private static DataSource initDatabase(final String dbUrlPropertyName, final String dbUserNamePropertyName, final String dbPasswordPropertyName, final String... liquibaseChangeLogXmls) throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(POSTGRES_DRIVER);
    dataSource.setUrl(TEST_PROPERTIES.value(dbUrlPropertyName));
    dataSource.setUsername(TEST_PROPERTIES.value(dbUserNamePropertyName));
    dataSource.setPassword(TEST_PROPERTIES.value(dbPasswordPropertyName));
    boolean dropped = false;
    final JdbcConnection jdbcConnection = new JdbcConnection(dataSource.getConnection());
    for (String liquibaseChangeLogXml : liquibaseChangeLogXmls) {
        Liquibase liquibase = new Liquibase(liquibaseChangeLogXml, new ClassLoaderResourceAccessor(), jdbcConnection);
        if (!dropped) {
            liquibase.dropAll();
            dropped = true;
        }
        liquibase.update("");
    }
    return dataSource;
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource)

Aggregations

Liquibase (liquibase.Liquibase)97 Test (org.junit.Test)29 LiquibaseException (liquibase.exception.LiquibaseException)25 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)25 JdbcConnection (liquibase.database.jvm.JdbcConnection)24 IOException (java.io.IOException)22 Database (liquibase.database.Database)22 SQLException (java.sql.SQLException)17 Contexts (liquibase.Contexts)17 ValidationFailedException (liquibase.exception.ValidationFailedException)11 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)10 DatabaseException (liquibase.exception.DatabaseException)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 BuildException (org.apache.tools.ant.BuildException)10 ChangeSet (liquibase.changelog.ChangeSet)9 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)9 Connection (java.sql.Connection)8 ResourceAccessor (liquibase.resource.ResourceAccessor)8 FileNotFoundException (java.io.FileNotFoundException)6 Date (java.util.Date)6