Search in sources :

Example 16 with Handle

use of jnc.platform.win32.Handle in project druid by druid-io.

the class SQLMetadataSegmentPublisher method publishSegment.

@VisibleForTesting
void publishSegment(final String identifier, final String dataSource, final String createdDate, final String start, final String end, final boolean partitioned, final String version, final boolean used, final byte[] payload) {
    try {
        final DBI dbi = connector.getDBI();
        List<Map<String, Object>> exists = dbi.withHandle(new HandleCallback<List<Map<String, Object>>>() {

            @Override
            public List<Map<String, Object>> withHandle(Handle handle) throws Exception {
                return handle.createQuery(String.format("SELECT id FROM %s WHERE id=:id", config.getSegmentsTable())).bind("id", identifier).list();
            }
        });
        if (!exists.isEmpty()) {
            log.info("Found [%s] in DB, not updating DB", identifier);
            return;
        }
        dbi.withHandle(new HandleCallback<Void>() {

            @Override
            public Void withHandle(Handle handle) throws Exception {
                handle.createStatement(statement).bind("id", identifier).bind("dataSource", dataSource).bind("created_date", createdDate).bind("start", start).bind("end", end).bind("partitioned", partitioned).bind("version", version).bind("used", used).bind("payload", payload).execute();
                return null;
            }
        });
    } catch (Exception e) {
        log.error(e, "Exception inserting into DB");
        throw new RuntimeException(e);
    }
}
Also used : DBI(org.skife.jdbi.v2.DBI) IOException(java.io.IOException) Handle(org.skife.jdbi.v2.Handle) List(java.util.List) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 17 with Handle

use of jnc.platform.win32.Handle in project dropwizard by dropwizard.

the class DbMigrateDifferentFileCommandTest method testRun.

@Test
public void testRun() throws Exception {
    migrateCommand.run(null, new Namespace(ImmutableMap.of()), conf);
    try (Handle handle = new DBI(databaseUrl, "sa", "").open()) {
        final List<Map<String, Object>> rows = handle.select("select * from persons");
        assertThat(rows).hasSize(0);
    }
}
Also used : DBI(org.skife.jdbi.v2.DBI) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Namespace(net.sourceforge.argparse4j.inf.Namespace) Handle(org.skife.jdbi.v2.Handle) Test(org.junit.Test)

Example 18 with Handle

use of jnc.platform.win32.Handle in project Singularity by HubSpot.

the class SingularityHistoryTest method createTestData.

@Before
public void createTestData() throws Exception {
    Handle handle = dbiProvider.get().open();
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection()));
    Liquibase liquibase = new Liquibase("singularity_test.sql", new FileSystemResourceAccessor(), database);
    liquibase.update((String) null);
    try {
        database.close();
    } catch (Throwable t) {
    }
    handle.close();
}
Also used : Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) JdbcConnection(liquibase.database.jvm.JdbcConnection) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) Handle(org.skife.jdbi.v2.Handle) Before(org.junit.Before)

Example 19 with Handle

use of jnc.platform.win32.Handle in project pac4j by pac4j.

the class DbProfileService method execute.

protected void execute(final String query, final Object... args) {
    Handle h = null;
    try {
        h = dbi.open();
        logger.debug("Execute query: {} and values: {}", query, args);
        h.execute(query, args);
    } finally {
        if (h != null) {
            h.close();
        }
    }
}
Also used : Handle(org.skife.jdbi.v2.Handle)

Example 20 with Handle

use of jnc.platform.win32.Handle in project pac4j by pac4j.

the class DbProfileServiceTests method getData.

private List<Map<String, Object>> getData(final int id) {
    final DBI dbi = new DBI(ds);
    Handle h = null;
    try {
        h = dbi.open();
        return h.createQuery("select id,username,linkedid,password,serializedprofile from users where id = :id").bind("id", id).list(2);
    } finally {
        if (h != null) {
            h.close();
        }
    }
}
Also used : DBI(org.skife.jdbi.v2.DBI) Handle(org.skife.jdbi.v2.Handle)

Aggregations

Handle (org.skife.jdbi.v2.Handle)103 DBI (org.skife.jdbi.v2.DBI)28 Before (org.junit.Before)21 IOException (java.io.IOException)18 List (java.util.List)17 DataSourceFactory (io.dropwizard.db.DataSourceFactory)15 DBIFactory (io.dropwizard.jdbi.DBIFactory)15 SQLException (java.sql.SQLException)15 Map (java.util.Map)14 Test (org.junit.Test)14 Test (org.testng.annotations.Test)14 DateTime (org.joda.time.DateTime)13 ArrayList (java.util.ArrayList)11 TransactionStatus (org.skife.jdbi.v2.TransactionStatus)11 ResultSet (java.sql.ResultSet)10 ImmutableList (com.google.common.collect.ImmutableList)8 UUID (java.util.UUID)8 CallbackFailedException (org.skife.jdbi.v2.exceptions.CallbackFailedException)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 Set (java.util.Set)6