use of io.dropwizard.db.DataSourceFactory 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);
}
use of io.dropwizard.db.DataSourceFactory in project cals-api by ca-cwds.
the class BaseCalsApiApplication method upgardeCalsNsDB.
private void upgardeCalsNsDB(CalsApiConfiguration configuration) {
LOG.info("Upgrading CALS_NS DB...");
DataSourceFactory calsnsDataSourceFactory = configuration.getCalsnsDataSourceFactory();
DatabaseHelper databaseHelper = new DatabaseHelper(calsnsDataSourceFactory.getUrl(), calsnsDataSourceFactory.getUser(), calsnsDataSourceFactory.getPassword());
try {
databaseHelper.runScript(LIQUIBASE_CALSNS_DATABASE_CREATE_SCHEMA_XML);
databaseHelper.runScript(LIQUIBASE_CALSNS_DATABASE_MASTER_XML, calsnsDataSourceFactory.getProperties().get(HIBERNATE_DEFAULT_SCHEMA_PROPERTY_NAME));
} catch (Exception e) {
LOG.error("Upgarding of CALS_NS DB is failed. ", e);
}
LOG.info("Finish Upgrading CALS_NS DB");
}
use of io.dropwizard.db.DataSourceFactory in project dropwizard by dropwizard.
the class AbstractMigrationTest method createConfiguration.
protected static TestMigrationConfiguration createConfiguration(String databaseUrl) {
final DataSourceFactory dataSource = new DataSourceFactory();
dataSource.setDriverClass("org.h2.Driver");
dataSource.setUser("sa");
dataSource.setUrl(databaseUrl);
return new TestMigrationConfiguration(dataSource);
}
use of io.dropwizard.db.DataSourceFactory in project dropwizard by dropwizard.
the class JerseyIntegrationTest method configure.
@Override
protected Application configure() {
final MetricRegistry metricRegistry = new MetricRegistry();
final SessionFactoryFactory factory = new SessionFactoryFactory();
final DataSourceFactory dbConfig = new DataSourceFactory();
dbConfig.setProperties(Collections.singletonMap("hibernate.jdbc.time_zone", "UTC"));
final HibernateBundle<?> bundle = mock(HibernateBundle.class);
final Environment environment = mock(Environment.class);
final LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class);
when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
when(environment.metrics()).thenReturn(metricRegistry);
dbConfig.setUrl("jdbc:h2:mem:DbTest-" + System.nanoTime());
dbConfig.setUser("sa");
dbConfig.setDriverClass("org.h2.Driver");
dbConfig.setValidationQuery("SELECT 1");
this.sessionFactory = factory.build(bundle, environment, dbConfig, Collections.singletonList(Person.class));
try (Session session = sessionFactory.openSession()) {
Transaction transaction = session.beginTransaction();
session.createNativeQuery("DROP TABLE people IF EXISTS").executeUpdate();
session.createNativeQuery("CREATE TABLE people (name varchar(100) primary key, email varchar(16), birthday timestamp with time zone)").executeUpdate();
session.createNativeQuery("INSERT INTO people VALUES ('Coda', 'coda@example.com', '1979-01-02 00:22:00+0:00')").executeUpdate();
transaction.commit();
}
final DropwizardResourceConfig config = DropwizardResourceConfig.forTesting();
config.register(new UnitOfWorkApplicationListener("hr-db", sessionFactory));
config.register(new PersonResource(new PersonDAO(sessionFactory)));
config.register(new PersistenceExceptionMapper());
config.register(new JacksonFeature(Jackson.newObjectMapper()));
config.register(new DataExceptionMapper());
config.register(new EmptyOptionalExceptionMapper());
return config;
}
use of io.dropwizard.db.DataSourceFactory in project keywhiz by square.
the class ServiceDataSourceModule 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;
}
Aggregations