Search in sources :

Example 16 with DefaultConfiguration

use of org.jooq.impl.DefaultConfiguration in project SimpleFlatMapper by arnaudroger.

the class JooqMapperTest method testMapperDbExtendedType.

@Test
public void testMapperDbExtendedType() throws Exception {
    Connection conn = DbHelper.objectDb();
    DSLContext dsl = DSL.using(new DefaultConfiguration().set(conn).set(SQLDialect.HSQLDB).set(SfmRecordMapperProviderFactory.newInstance().newProvider()));
    List<DbExtendedType> list = dsl.select().from("db_extended_type").fetchInto(DbExtendedType.class);
    assertEquals(1, list.size());
    DbExtendedType o = list.get(0);
    DbExtendedType.assertDbExtended(o);
}
Also used : DbExtendedType(org.simpleflatmapper.test.beans.DbExtendedType) Connection(java.sql.Connection) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Test(org.junit.Test)

Example 17 with DefaultConfiguration

use of org.jooq.impl.DefaultConfiguration in project steve by RWTH-i5-IDSG.

the class BeanConfiguration method dslContext.

/**
 * Can we re-use DSLContext as a Spring bean (singleton)? Yes, the Spring tutorial of
 * Jooq also does it that way, but only if we do not change anything about the
 * config after the init (which we don't do anyways) and if the ConnectionProvider
 * does not store any shared state (we use DataSourceConnectionProvider of Jooq, so no problem).
 *
 * Some sources and discussion:
 * - http://www.jooq.org/doc/3.6/manual/getting-started/tutorials/jooq-with-spring/
 * - http://jooq-user.narkive.com/2fvuLodn/dslcontext-and-threads
 * - https://groups.google.com/forum/#!topic/jooq-user/VK7KQcjj3Co
 * - http://stackoverflow.com/questions/32848865/jooq-dslcontext-correct-autowiring-with-spring
 */
@Bean
public DSLContext dslContext() {
    initDataSource();
    Settings settings = new Settings().withAttachRecords(false).withExecuteLogging(CONFIG.getDb().isSqlLogging());
    // Configuration for JOOQ
    org.jooq.Configuration conf = new DefaultConfiguration().set(SQLDialect.MYSQL).set(new DataSourceConnectionProvider(dataSource)).set(settings);
    return DSL.using(conf);
}
Also used : DataSourceConnectionProvider(org.jooq.impl.DataSourceConnectionProvider) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Settings(org.jooq.conf.Settings) LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 18 with DefaultConfiguration

use of org.jooq.impl.DefaultConfiguration in project mapping-benchmark by arnaudroger.

the class JooqSfmRecordMapperBenchmark method init.

@Setup
public void init() throws Exception {
    ConnectionParam cp = new ConnectionParam();
    cp.db = db;
    cp.init();
    dsl = DSL.using(new DefaultConfiguration().set(cp.dataSource).set(JooqMapperBenchmark.getSqlDialect(db)).set(new SfmRecordMapperProvider()));
    select4 = dsl.selectFrom(TestSmallBenchmarkObject.TEST_SMALL_BENCHMARK_OBJECT);
    select16 = dsl.selectFrom(TestBenchmarkObject_16.TEST_BENCHMARK_OBJECT_16);
}
Also used : SfmRecordMapperProvider(org.simpleflatmapper.jooq.SfmRecordMapperProvider) ConnectionParam(org.simpleflatmapper.db.ConnectionParam) DefaultConfiguration(org.jooq.impl.DefaultConfiguration)

Example 19 with DefaultConfiguration

use of org.jooq.impl.DefaultConfiguration in project mapping-benchmark by arnaudroger.

the class JooqSfmRecordMapperBenchmark method main.

public static void main(String[] args) throws SQLException, NamingException {
    ConnectionParam cp = new ConnectionParam();
    cp.db = DbTarget.H2;
    cp.init();
    DSLContext dsl = DSL.using(new DefaultConfiguration().set(cp.dataSource).set(JooqMapperBenchmark.getSqlDialect(cp.db)).set(new SfmRecordMapperProvider()));
    SelectOffsetStep<TestSmallBenchmarkObjectRecord> query = dsl.selectFrom(TestSmallBenchmarkObject.TEST_SMALL_BENCHMARK_OBJECT).limit(1);
    for (MappedObject4 o : query.fetchInto(MappedObject4.class)) {
        System.out.println("o = " + o);
    }
    for (MappedObject4 o : query.fetchInto(MappedObject4.class)) {
        System.out.println("o = " + o);
    }
}
Also used : SfmRecordMapperProvider(org.simpleflatmapper.jooq.SfmRecordMapperProvider) TestSmallBenchmarkObjectRecord(org.simpleflatmapper.beans.tables.records.TestSmallBenchmarkObjectRecord) ConnectionParam(org.simpleflatmapper.db.ConnectionParam) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) MappedObject4(org.simpleflatmapper.beans.MappedObject4)

Example 20 with DefaultConfiguration

use of org.jooq.impl.DefaultConfiguration in project vertx-zero by silentbalanceyh.

the class JooqInfix method initInternal.

private static void initInternal(final Vertx vertx, final String name) {
    vertxRef = vertx;
    Fn.pool(CONFIGS, name, () -> Infix.init(Plugins.Infix.JOOQ, (config) -> {
        // Initialized client
        final Configuration configuration = new DefaultConfiguration();
        configuration.set(SQLDialect.MYSQL_8_0);
        final ConnectionProvider provider = new DefaultConnectionProvider(HikariCpPool.getConnection(config.getJsonObject("provider")));
        // Initialized default configuration
        configuration.set(provider);
        return configuration;
    }, JooqInfix.class));
}
Also used : Fn(io.vertx.up.func.Fn) HikariCpPool(io.vertx.tp.hikari.HikariCpPool) ConnectionProvider(org.jooq.ConnectionProvider) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Infix(io.vertx.up.plugin.Infix) Vertx(io.vertx.core.Vertx) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DefaultConnectionProvider(org.jooq.impl.DefaultConnectionProvider) Plugin(io.vertx.up.annotations.Plugin) Instance(io.vertx.up.tool.mirror.Instance) ConcurrentMap(java.util.concurrent.ConcurrentMap) Configuration(org.jooq.Configuration) DSLContext(org.jooq.DSLContext) Plugins(io.vertx.up.eon.Plugins) SQLDialect(org.jooq.SQLDialect) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Configuration(org.jooq.Configuration) DefaultConnectionProvider(org.jooq.impl.DefaultConnectionProvider) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) ConnectionProvider(org.jooq.ConnectionProvider) DefaultConnectionProvider(org.jooq.impl.DefaultConnectionProvider)

Aggregations

DefaultConfiguration (org.jooq.impl.DefaultConfiguration)27 Settings (org.jooq.conf.Settings)7 Connection (java.sql.Connection)6 Configuration (org.jooq.Configuration)6 DSLContext (org.jooq.DSLContext)6 ConnectionParam (org.simpleflatmapper.db.ConnectionParam)6 Test (org.junit.Test)5 DefaultExecuteListenerProvider (org.jooq.impl.DefaultExecuteListenerProvider)4 SfmRecordMapperProvider (org.simpleflatmapper.jooq.SfmRecordMapperProvider)4 Bean (org.springframework.context.annotation.Bean)4 Properties (java.util.Properties)3 SQLDialect (org.jooq.SQLDialect)3 DataSourceConnectionProvider (org.jooq.impl.DataSourceConnectionProvider)3 DefaultConnectionProvider (org.jooq.impl.DefaultConnectionProvider)3 Provides (dagger.Provides)2 List (java.util.List)2 Singleton (javax.inject.Singleton)2 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)2 ConnectionProvider (org.jooq.ConnectionProvider)2 DbObject (org.simpleflatmapper.test.beans.DbObject)2