Search in sources :

Example 51 with Handle

use of jnc.platform.win32.Handle in project airpal by airbnb.

the class JobHistoryStoreDAO method getJobs.

private List<Job> getJobs(long limit, int dayInterval, String outerWhereClauseArg, String innerWhereClauseArg) {
    String outerWhereClause = Strings.isNullOrEmpty(outerWhereClauseArg) ? "true" : outerWhereClauseArg;
    String innerWhereClause = Strings.isNullOrEmpty(innerWhereClauseArg) ? "true" : innerWhereClauseArg;
    try (Handle handle = dbi.open()) {
        Query<Map<String, Object>> query = handle.createQuery("SELECT " + "j.id AS id, " + "j.query AS query, " + "j.user AS user, " + "j.uuid AS uuid, " + "j.queryStats as queryStats, " + "j.state AS state, " + "j.columns AS columns, " + "j.query_finished AS queryFinished, " + "j.query_started AS queryStarted, " + "j.error AS error, " + "t.connector_id AS connectorId, " + "t.schema_ AS \"schema\", " + "t.table_ AS \"table\", " + "t.columns, " + "jo.type, " + "jo.description, " + "jo.location " + "FROM (SELECT * FROM jobs " + "WHERE " + Util.getQueryFinishedCondition(dbType) + " " + "AND " + innerWhereClause + " " + "ORDER BY query_finished DESC LIMIT :limit) j " + "LEFT OUTER JOIN job_tables jt ON j.id = jt.job_id " + "LEFT OUTER JOIN tables t ON jt.table_id = t.id " + "LEFT OUTER JOIN job_outputs jo ON j.id = jo.job_id " + "WHERE " + outerWhereClause + " " + "ORDER BY query_finished DESC").bind("limit", limit).bind("day_interval", dayInterval);
        Map<Long, Job> idToJobMap = query.map(RosettaResultSetMapperFactory.mapperFor(JobTableOutputJoinRow.class)).fold(new HashMap<Long, Job>(), new JobTableOutputJoinRow.JobFolder());
        return new ArrayList<>(idToJobMap.values());
    }
}
Also used : ArrayList(java.util.ArrayList) Job(com.airbnb.airpal.api.Job) HashMap(java.util.HashMap) Map(java.util.Map) JobTableOutputJoinRow(com.airbnb.airpal.sql.beans.JobTableOutputJoinRow) Handle(org.skife.jdbi.v2.Handle)

Example 52 with Handle

use of jnc.platform.win32.Handle in project hive by apache.

the class TestDruidStorageHandler method testPreCreateTableWillCreateSegmentsTable.

@Test
public void testPreCreateTableWillCreateSegmentsTable() throws MetaException {
    try (Handle handle = derbyConnectorRule.getConnector().getDBI().open()) {
        Assert.assertFalse(derbyConnectorRule.getConnector().tableExists(handle, segmentsTable));
        druidStorageHandler.preCreateTable(tableMock);
        Assert.assertTrue(derbyConnectorRule.getConnector().tableExists(handle, segmentsTable));
    }
}
Also used : Handle(org.skife.jdbi.v2.Handle) Test(org.junit.Test)

Example 53 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 54 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 var 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)

Example 55 with Handle

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

the class BaseIdCacheLoader method load.

@Override
public Object load(final Object key, final Object argument) {
    checkCacheLoaderStatus();
    if (!(key instanceof String)) {
        throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
    }
    if (!(argument instanceof CacheLoaderArgument)) {
        throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName());
    }
    final String rawKey;
    if (getCacheType().isKeyPrefixedWithTableName()) {
        final String[] parts = ((String) key).split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
        rawKey = parts[1];
    } else {
        rawKey = (String) key;
    }
    final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType();
    final Handle handle = ((CacheLoaderArgument) argument).getHandle();
    return doRetrieveOperation(rawKey, objectType, handle);
}
Also used : ObjectType(org.killbill.billing.ObjectType) 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