Search in sources :

Example 36 with ClassLoaderResourceAccessor

use of liquibase.resource.ClassLoaderResourceAccessor in project microservice_framework by CJSCommonPlatform.

the class CakeShopIT 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(H2_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)

Example 37 with ClassLoaderResourceAccessor

use of liquibase.resource.ClassLoaderResourceAccessor in project jOOQ by jOOQ.

the class LiquibaseDatabase method export.

@Override
protected void export() throws Exception {
    String rootPath = getProperties().getProperty("rootPath");
    String scripts = getProperties().getProperty("scripts");
    includeLiquibaseTables = Boolean.parseBoolean(getProperties().getProperty("includeLiquibaseTables", "false"));
    if (isBlank(scripts)) {
        scripts = "";
        log.warn("No scripts defined", "It is recommended that you provide an explicit script directory to scan");
    }
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection()));
    String contexts = "";
    // Database.setXyz() configuration setter calls
    for (Entry<Object, Object> entry : getProperties().entrySet()) {
        String key = "" + entry.getKey();
        if (key.startsWith("database.")) {
            String property = key.substring("database.".length());
            Method setter = SETTERS.get("set" + Character.toUpperCase(property.charAt(0)) + property.substring(1));
            try {
                if (setter != null)
                    setter.invoke(database, Convert.convert(entry.getValue(), setter.getParameterTypes()[0]));
            } catch (Exception e) {
                log.warn("Configuration error", e.getMessage(), e);
            }
        } else // [#9872] Some changeLogParameters can also be passed along
        if (key.startsWith("changeLogParameters.")) {
            String property = key.substring("changeLogParameters.".length());
            if ("contexts".equals(property))
                contexts = "" + entry.getValue();
        }
    }
    // Retrieve changeLog table names as they might be overridden by configuration setters
    databaseChangeLogTableName = database.getDatabaseChangeLogTableName();
    databaseChangeLogLockTableName = database.getDatabaseChangeLogLockTableName();
    // [#9866] Allow for loading included files from the classpath or using absolute paths.
    // [#12872] [#13021] The decision is made based on the presence of the rootPath property
    ResourceAccessor ra = StringUtils.isBlank(rootPath) ? new CompositeResourceAccessor(new ClassLoaderResourceAccessor(), new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader())) : new FileSystemResourceAccessor(new File(rootPath));
    Liquibase liquibase = new Liquibase(scripts, ra, database);
    liquibase.update(contexts);
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) JdbcConnection(liquibase.database.jvm.JdbcConnection) Method(java.lang.reflect.Method) SQLException(java.sql.SQLException) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) AbstractInterpretingDatabase(org.jooq.meta.extensions.AbstractInterpretingDatabase) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) File(java.io.File)

Example 38 with ClassLoaderResourceAccessor

use of liquibase.resource.ClassLoaderResourceAccessor in project gocd by gocd.

the class LiquibaseMigtrationTest method migrate.

private void migrate(String migration) throws SQLException, LiquibaseException {
    Connection connection = dataSource.getConnection();
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
    Liquibase liquibase = new Liquibase("db-migration-scripts/" + migration, new ClassLoaderResourceAccessor(getClass().getClassLoader()), database);
    liquibase.update("test");
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) JdbcConnection(liquibase.database.jvm.JdbcConnection) Database(liquibase.database.Database) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Aggregations

ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)38 Liquibase (liquibase.Liquibase)25 JdbcConnection (liquibase.database.jvm.JdbcConnection)20 SQLException (java.sql.SQLException)11 CompositeResourceAccessor (liquibase.resource.CompositeResourceAccessor)9 Database (liquibase.database.Database)8 LiquibaseException (liquibase.exception.LiquibaseException)8 Connection (java.sql.Connection)7 DatabaseException (liquibase.exception.DatabaseException)7 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)7 ResourceAccessor (liquibase.resource.ResourceAccessor)7 File (java.io.File)6 ArrayList (java.util.ArrayList)3 Contexts (liquibase.Contexts)3 FileOutputStream (java.io.FileOutputStream)2 DataSource (javax.sql.DataSource)2 ChangeLogParameters (liquibase.changelog.ChangeLogParameters)2 ChangeSet (liquibase.changelog.ChangeSet)2 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)2 DatabaseConnection (liquibase.database.DatabaseConnection)2