Search in sources :

Example 16 with DBIFactory

use of io.dropwizard.jdbi.DBIFactory in project dropwizard by dropwizard.

the class GuavaOptionalLocalDateTimeTest 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-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)

Example 17 with DBIFactory

use of io.dropwizard.jdbi.DBIFactory in project dropwizard by dropwizard.

the class GuavaOptionalOffsetDateTimeTest method setupTests.

@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:guava-offset-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)

Example 18 with DBIFactory

use of io.dropwizard.jdbi.DBIFactory in project dropwizard by dropwizard.

the class OptionalLongTest method setupTests.

@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:optional-long-" + 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 BIGINT)");
    }
    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 19 with DBIFactory

use of io.dropwizard.jdbi.DBIFactory in project airpal by airbnb.

the class AirpalModule method provideDBI.

@Singleton
@Provides
public DBI provideDBI(ObjectMapper objectMapper) throws ClassNotFoundException {
    final DBIFactory factory = new DBIFactory();
    final DBI dbi = factory.build(environment, config.getDataSourceFactory(), provideDbType().name());
    dbi.registerMapper(new TableRow.TableRowMapper(objectMapper));
    dbi.registerMapper(new QueryStoreMapper(objectMapper));
    dbi.registerArgumentFactory(new UUIDArgumentFactory());
    dbi.registerArgumentFactory(new URIArgumentFactory());
    return dbi;
}
Also used : URIArgumentFactory(com.airbnb.airpal.sql.jdbi.URIArgumentFactory) UUIDArgumentFactory(com.airbnb.airpal.sql.jdbi.UUIDArgumentFactory) TableRow(com.airbnb.airpal.sql.beans.TableRow) DBI(org.skife.jdbi.v2.DBI) QueryStoreMapper(com.airbnb.airpal.sql.jdbi.QueryStoreMapper) DBIFactory(io.dropwizard.jdbi.DBIFactory) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

DBIFactory (io.dropwizard.jdbi.DBIFactory)19 DBI (org.skife.jdbi.v2.DBI)18 DataSourceFactory (io.dropwizard.db.DataSourceFactory)16 Before (org.junit.Before)15 Handle (org.skife.jdbi.v2.Handle)15 TableRow (com.airbnb.airpal.sql.beans.TableRow)1 QueryStoreMapper (com.airbnb.airpal.sql.jdbi.QueryStoreMapper)1 URIArgumentFactory (com.airbnb.airpal.sql.jdbi.URIArgumentFactory)1 UUIDArgumentFactory (com.airbnb.airpal.sql.jdbi.UUIDArgumentFactory)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 EndpointBuilder (com.roskart.dropwizard.jaxws.EndpointBuilder)1 AuthDynamicFeature (io.dropwizard.auth.AuthDynamicFeature)1 BasicCredentialAuthFilter (io.dropwizard.auth.basic.BasicCredentialAuthFilter)1 ConnectorFactory (io.dropwizard.jetty.ConnectorFactory)1 HttpConnectorFactory (io.dropwizard.jetty.HttpConnectorFactory)1 DefaultLoggingFactory (io.dropwizard.logging.DefaultLoggingFactory)1 DefaultServerFactory (io.dropwizard.server.DefaultServerFactory)1 Environment (io.dropwizard.setup.Environment)1