Search in sources :

Example 1 with DefaultDSLContext

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);
}
Also used : DefaultDSLContext(org.jooq.impl.DefaultDSLContext) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSourceConnectionProvider(org.jooq.impl.DataSourceConnectionProvider) SQLException(java.sql.SQLException) ContextExpression(liquibase.ContextExpression) DefaultDSLContext(org.jooq.impl.DefaultDSLContext) DSLContext(org.jooq.DSLContext) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) JdbcConnection(liquibase.database.jvm.JdbcConnection) HikariConfig(com.zaxxer.hikari.HikariConfig) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) Liquibase(liquibase.Liquibase) SetupException(liquibase.exception.SetupException) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) LabelExpression(liquibase.LabelExpression) LiquibaseException(liquibase.exception.LiquibaseException) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) DatabaseException(liquibase.exception.DatabaseException)

Aggregations

HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 SQLException (java.sql.SQLException)1 ContextExpression (liquibase.ContextExpression)1 LabelExpression (liquibase.LabelExpression)1 Liquibase (liquibase.Liquibase)1 ChangeLogParameters (liquibase.changelog.ChangeLogParameters)1 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)1 JdbcConnection (liquibase.database.jvm.JdbcConnection)1 DatabaseException (liquibase.exception.DatabaseException)1 LiquibaseException (liquibase.exception.LiquibaseException)1 SetupException (liquibase.exception.SetupException)1 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)1 DSLContext (org.jooq.DSLContext)1 DataSourceConnectionProvider (org.jooq.impl.DataSourceConnectionProvider)1 DefaultConfiguration (org.jooq.impl.DefaultConfiguration)1 DefaultDSLContext (org.jooq.impl.DefaultDSLContext)1