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;
}
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);
}
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");
}
Aggregations