Search in sources :

Example 31 with DataSourceFactory

use of io.dropwizard.db.DataSourceFactory in project keywhiz by square.

the class ServiceDataSourceModule method dataSource.

@Provides
@Singleton
ManagedDataSource dataSource(Environment environment, KeywhizConfig config) {
    DataSourceFactory dataSourceFactory = config.getDataSourceFactory();
    ManagedDataSource dataSource = dataSourceFactory.build(environment.metrics(), "db-writable");
    environment.lifecycle().manage(dataSource);
    environment.healthChecks().register("db-read-write-health", new JooqHealthCheck(dataSource, LOG_ONLY));
    return dataSource;
}
Also used : JooqHealthCheck(keywhiz.JooqHealthCheck) DataSourceFactory(io.dropwizard.db.DataSourceFactory) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

DataSourceFactory (io.dropwizard.db.DataSourceFactory)31 DBIFactory (io.dropwizard.jdbi.DBIFactory)16 Before (org.junit.Before)16 DBI (org.skife.jdbi.v2.DBI)15 Handle (org.skife.jdbi.v2.Handle)15 MetricRegistry (com.codahale.metrics.MetricRegistry)4 Provides (com.google.inject.Provides)4 Singleton (com.google.inject.Singleton)4 ManagedDataSource (io.dropwizard.db.ManagedDataSource)4 Environment (io.dropwizard.setup.Environment)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 AssetsBundle (io.dropwizard.assets.AssetsBundle)2 LifecycleEnvironment (io.dropwizard.lifecycle.setup.LifecycleEnvironment)2 JooqHealthCheck (keywhiz.JooqHealthCheck)2 Readonly (keywhiz.service.config.Readonly)2 LifeCycle (org.eclipse.jetty.util.component.LifeCycle)2 Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 TimedAnnotationNameStrategy (com.codahale.metrics.jdbi3.strategies.TimedAnnotationNameStrategy)1 RenderCommand (com.example.helloworld.cli.RenderCommand)1