Search in sources :

Example 1 with DataSourceFactory

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

the class SessionFactoryFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    when(environment.metrics()).thenReturn(metricRegistry);
    when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
    config = new DataSourceFactory();
    config.setUrl("jdbc:hsqldb:mem:DbTest-" + System.currentTimeMillis());
    config.setUser("sa");
    config.setDriverClass("org.hsqldb.jdbcDriver");
    config.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
    final ImmutableMap<String, String> properties = ImmutableMap.of("hibernate.show_sql", "true", "hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    config.setProperties(properties);
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) Before(org.junit.Before)

Example 2 with DataSourceFactory

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

the class OptionalDoubleTest method setupTests.

@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:optional-double-" + System.currentTimeMillis() + "?user=sa");
    dataSourceFactory.setInitialSize(1);
    final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test");
    try (Handle h = dbi.open()) {
        h.execute("CREATE TABLE test (id INT PRIMARY KEY, optional DOUBLE)");
    }
    dao = dbi.onDemand(TestDao.class);
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) DBI(org.skife.jdbi.v2.DBI) DBIFactory(io.dropwizard.jdbi.DBIFactory) Handle(org.skife.jdbi.v2.Handle) Before(org.junit.Before)

Example 3 with DataSourceFactory

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

the class OptionalIntTest method setupTests.

@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:optional-int-" + System.currentTimeMillis() + "?user=sa");
    dataSourceFactory.setInitialSize(1);
    final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test");
    try (Handle h = dbi.open()) {
        h.execute("CREATE TABLE test (id INT PRIMARY KEY, optional INT)");
    }
    dao = dbi.onDemand(TestDao.class);
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) DBI(org.skife.jdbi.v2.DBI) DBIFactory(io.dropwizard.jdbi.DBIFactory) Handle(org.skife.jdbi.v2.Handle) Before(org.junit.Before)

Example 4 with DataSourceFactory

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

the class GuavaOptionalLocalDateTest method setupTests.

@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:guava-local-date-" + System.currentTimeMillis() + "?user=sa");
    dataSourceFactory.setInitialSize(1);
    final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test");
    try (Handle h = dbi.open()) {
        h.execute("CREATE TABLE IF NOT EXISTS tasks (" + "id INT PRIMARY KEY, " + "assignee VARCHAR(255) NOT NULL, " + "start_date TIMESTAMP, " + "end_date TIMESTAMP, " + "comments VARCHAR(1024) " + ")");
    }
    dao = dbi.onDemand(TaskDao.class);
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) DBI(org.skife.jdbi.v2.DBI) DBIFactory(io.dropwizard.jdbi.DBIFactory) Handle(org.skife.jdbi.v2.Handle) Before(org.junit.Before)

Example 5 with DataSourceFactory

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

the class GuavaOptionalZonedDateTimeTest method setupTests.

@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:guava-zoned-date-time-" + System.currentTimeMillis() + "?user=sa");
    dataSourceFactory.setInitialSize(1);
    final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test");
    try (Handle h = dbi.open()) {
        h.execute("CREATE TABLE IF NOT EXISTS tasks (" + "id INT PRIMARY KEY, " + "assignee VARCHAR(255) NOT NULL, " + "start_date TIMESTAMP, " + "end_date TIMESTAMP, " + "comments VARCHAR(1024) " + ")");
    }
    dao = dbi.onDemand(TaskDao.class);
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) DBI(org.skife.jdbi.v2.DBI) DBIFactory(io.dropwizard.jdbi.DBIFactory) Handle(org.skife.jdbi.v2.Handle) Before(org.junit.Before)

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