use of org.jooq.impl.DefaultDSLContext in project kork by spinnaker.
the class SqlTestUtil method initDatabase.
public static TestDatabase initDatabase(String jdbcUrl, SQLDialect dialect, String dbName) {
HikariConfig cpConfig = new HikariConfig();
cpConfig.setJdbcUrl(jdbcUrl);
cpConfig.setMaximumPoolSize(5);
HikariDataSource dataSource = new HikariDataSource(cpConfig);
DefaultConfiguration config = new DefaultConfiguration();
config.set(new DataSourceConnectionProvider(dataSource));
config.setSQLDialect(dialect);
if (dialect == H2) {
config.settings().withRenderNameStyle(AS_IS);
}
DSLContext context = new DefaultDSLContext(config);
Liquibase migrate;
try {
DatabaseChangeLog changeLog = new DatabaseChangeLog();
changeLog.setChangeLogParameters(new ChangeLogParameters(DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection()))));
changeLog.includeAll("db/changelog/", false, null, false, Comparator.comparing(String::toString), new ClassLoaderResourceAccessor(), new ContextExpression(), new LabelExpression(), false);
migrate = new Liquibase(changeLog, new ClassLoaderResourceAccessor(), DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection())));
} catch (DatabaseException | SQLException | SetupException e) {
throw new DatabaseInitializationFailed(e);
}
try {
migrate.update(dbName);
} catch (LiquibaseException e) {
throw new DatabaseInitializationFailed(e);
}
return new TestDatabase(dataSource, context, migrate);
}
Aggregations