use of org.skife.jdbi.v2.DBI in project dropwizard by dropwizard.
the class OptionalLocalDateTest method setupTests.
@Before
public void setupTests() throws IOException {
final DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.setUrl("jdbc:h2:mem:optional-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);
}
use of org.skife.jdbi.v2.DBI in project dropwizard by dropwizard.
the class OptionalLocalDateTimeTest method setupTests.
@Before
public void setupTests() throws IOException {
final DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.setUrl("jdbc:h2:mem:optional-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);
}
use of org.skife.jdbi.v2.DBI in project druid by druid-io.
the class JDBCExtractionNamespaceCacheFactory method lastUpdates.
private Long lastUpdates(CacheScheduler.EntryImpl<JDBCExtractionNamespace> id, JDBCExtractionNamespace namespace) {
final DBI dbi = ensureDBI(id, namespace);
final String table = namespace.getTable();
final String tsColumn = namespace.getTsColumn();
if (tsColumn == null) {
return null;
}
final Timestamp update = dbi.withHandle(new HandleCallback<Timestamp>() {
@Override
public Timestamp withHandle(Handle handle) throws Exception {
final String query = String.format("SELECT MAX(%s) FROM %s", tsColumn, table);
return handle.createQuery(query).map(TimestampMapper.FIRST).first();
}
});
return update.getTime();
}
use of org.skife.jdbi.v2.DBI in project killbill by killbill.
the class TestCatalogOverridePhaseDefinitionSqlDao method beforeClass.
@BeforeClass(groups = "slow")
public void beforeClass() throws Exception {
super.beforeClass();
((DBI) dbi).registerMapper(new LowerToCamelBeanMapperFactory(CatalogOverridePhaseDefinitionModelDao.class));
}
use of org.skife.jdbi.v2.DBI in project OpenAttestation by OpenAttestation.
the class CreateDatabase method createTables.
/*
private <T extends GenericDAO> void createTable(String name, Class<T> daoClass, DBI dbi) {
T dao = dbi.open(daoClass);
if( !Derby.tableExists(name) ) { dao.create(); }
dao.close();
}
*/
public void createTables() throws SQLException {
DataSource ds = Derby.getDataSource();
DBI dbi = new DBI(ds);
// tag
KvAttributeDAO tagDao = dbi.open(KvAttributeDAO.class);
if (!Derby.tableExists("mw_tag_kvattribute")) {
tagDao.create();
}
tagDao.close();
// tag value
//SelectionKvAttributeDAO tagValueDao = dbi.open(SelectionKvAttributeDAO.class);
//if( !Derby.tableExists("mw_tag_selection_kvattribute") ) { tagValueDao.create(); }
//tagValueDao.close();
// certificate request
CertificateRequestDAO certificateRequestDao = dbi.open(CertificateRequestDAO.class);
if (!Derby.tableExists("mw_tag_certificate_request")) {
certificateRequestDao.create();
}
certificateRequestDao.close();
// certificate
CertificateDAO certificateDao = dbi.open(CertificateDAO.class);
if (!Derby.tableExists("mw_tag_certificate")) {
certificateDao.create();
}
certificateDao.close();
// certificate request
SelectionDAO selectionDao = dbi.open(SelectionDAO.class);
if (!Derby.tableExists("mw_tag_selection")) {
selectionDao.create();
}
selectionDao.close();
// configuration
ConfigurationDAO configurationDao = dbi.open(ConfigurationDAO.class);
if (!Derby.tableExists("mw_configuration")) {
configurationDao.create();
}
configurationDao.close();
// file
FileDAO fileDao = dbi.open(FileDAO.class);
if (!Derby.tableExists("mw_file")) {
fileDao.create();
}
fileDao.close();
//TpmPasswordDAO tpmPasswordDao = dbi.open(TpmPasswordDAO.class);
//if( !Derby.tableExists("mw_host_tpm_password")) { tpmPasswordDao.create();}
//tpmPasswordDao.close();
}
Aggregations