Search in sources :

Example 16 with DBI

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);
}
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 DBI

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);
}
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 DBI

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();
}
Also used : DBI(org.skife.jdbi.v2.DBI) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) Handle(org.skife.jdbi.v2.Handle)

Example 19 with DBI

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));
}
Also used : LowerToCamelBeanMapperFactory(org.killbill.commons.jdbi.mapper.LowerToCamelBeanMapperFactory) DBI(org.skife.jdbi.v2.DBI) BeforeClass(org.testng.annotations.BeforeClass)

Example 20 with DBI

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();
}
Also used : DBI(org.skife.jdbi.v2.DBI) DataSource(javax.sql.DataSource)

Aggregations

DBI (org.skife.jdbi.v2.DBI)55 Handle (org.skife.jdbi.v2.Handle)27 DBIFactory (io.dropwizard.jdbi.DBIFactory)18 Before (org.junit.Before)17 DataSourceFactory (io.dropwizard.db.DataSourceFactory)15 IDBI (org.skife.jdbi.v2.IDBI)15 BeforeMethod (org.testng.annotations.BeforeMethod)15 Test (org.junit.Test)7 MetadataDao (com.facebook.presto.raptor.metadata.MetadataDao)6 SQLException (java.sql.SQLException)6 Namespace (net.sourceforge.argparse4j.inf.Namespace)6 TypeRegistry (com.facebook.presto.type.TypeRegistry)5 Duration (io.airlift.units.Duration)5 List (java.util.List)5 Map (java.util.Map)5 RaptorMetadata (com.facebook.presto.raptor.RaptorMetadata)4 ShardManager (com.facebook.presto.raptor.metadata.ShardManager)4 ImmutableList (com.google.common.collect.ImmutableList)4 NodeSupplier (com.facebook.presto.raptor.NodeSupplier)3 ForMetadata (com.facebook.presto.raptor.metadata.ForMetadata)3