Search in sources :

Example 1 with Readonly

use of keywhiz.service.config.Readonly in project keywhiz by square.

the class ServiceModule method readonlyDataSource.

@Provides
@Singleton
@Readonly
ManagedDataSource readonlyDataSource(Environment environment, KeywhizConfig config) {
    DataSourceFactory dataSourceFactory = config.getReadonlyDataSourceFactory();
    ManagedDataSource dataSource = dataSourceFactory.build(environment.metrics(), "db-readonly");
    environment.lifecycle().manage(dataSource);
    environment.healthChecks().register("db-readonly-health", new JooqHealthCheck(dataSource, RETURN_UNHEALTHY));
    return dataSource;
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Readonly(keywhiz.service.config.Readonly) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 2 with Readonly

use of keywhiz.service.config.Readonly in project keywhiz by square.

the class ServiceModule method readonlyJooqContext.

@Provides
@Singleton
@Readonly
DSLContext readonlyJooqContext(@Readonly ManagedDataSource dataSource) throws SQLException {
    DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
    org.jooq.Configuration configuration = dslContext.configuration();
    // Disable support for nested transactions via savepoints (required for MySQL)
    // See: https://groups.google.com/forum/#!topic/jooq-user/zG0U6CkxI5o
    configuration.set(new DefaultTransactionProvider(configuration.connectionProvider(), false));
    return dslContext;
}
Also used : DefaultTransactionProvider(org.jooq.impl.DefaultTransactionProvider) DSLContext(org.jooq.DSLContext) Readonly(keywhiz.service.config.Readonly) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Provides (com.google.inject.Provides)2 Singleton (com.google.inject.Singleton)2 Readonly (keywhiz.service.config.Readonly)2 DataSourceFactory (io.dropwizard.db.DataSourceFactory)1 ManagedDataSource (io.dropwizard.db.ManagedDataSource)1 DSLContext (org.jooq.DSLContext)1 DefaultTransactionProvider (org.jooq.impl.DefaultTransactionProvider)1