Tabnine Logo
DBI.withHandle
Code IndexAdd Tabnine to your IDE (free)

How to use
withHandle
method
in
org.skife.jdbi.v2.DBI

Best Java code snippets using org.skife.jdbi.v2.DBI.withHandle (Showing top 20 results out of 315)

origin: apache/incubator-druid

@Override
public byte[] lookup(
  final String tableName,
  final String keyColumn,
  final String valueColumn,
  final String key
)
{
 return getDBI().withHandle(
   new HandleCallback<byte[]>()
   {
    @Override
    public byte[] withHandle(Handle handle)
    {
     return lookupWithHandle(handle, tableName, keyColumn, valueColumn, key);
    }
   }
 );
}
origin: apache/incubator-druid

public <T> T retryWithHandle(
  HandleCallback<T> callback,
  Predicate<Throwable> myShouldRetry
)
{
 try {
  return RetryUtils.retry(() -> getDBI().withHandle(callback), myShouldRetry, MAX_RETRIES);
 }
 catch (Exception e) {
  throw new RuntimeException(e);
 }
}
origin: apache/incubator-druid

public <T> T retryWithHandle(
  final HandleCallback<T> callback,
  final Predicate<Throwable> myShouldRetry
)
{
 try {
  return RetryUtils.retry(() -> getDBI().withHandle(callback), myShouldRetry, DEFAULT_MAX_TRIES);
 }
 catch (Exception e) {
  throw Throwables.propagate(e);
 }
}
origin: apache/incubator-druid

protected final <T> T inReadOnlyTransaction(
  final TransactionCallback<T> callback
)
{
 return getDBI().withHandle(
   new HandleCallback<T>()
   {
    @Override
    public T withHandle(Handle handle) throws Exception
    {
     final Connection connection = handle.getConnection();
     final boolean readOnly = connection.isReadOnly();
     connection.setReadOnly(true);
     try {
      return handle.inTransaction(callback);
     }
     finally {
      try {
       connection.setReadOnly(readOnly);
      }
      catch (SQLException e) {
       // at least try to log it so we don't swallow exceptions
       log.error(e, "Unable to reset connection read-only state");
      }
     }
    }
   }
 );
}
origin: apache/incubator-druid

private <T> T inReadOnlyTransaction(final TransactionCallback<T> callback)
{
 return getDbi().withHandle(
   new HandleCallback<T>()
   {
    @Override
    public T withHandle(Handle handle) throws Exception
    {
     final Connection connection = handle.getConnection();
     final boolean readOnly = connection.isReadOnly();
     connection.setReadOnly(true);
     try {
      return handle.inTransaction(callback);
     }
     finally {
      try {
       connection.setReadOnly(readOnly);
      }
      catch (SQLException e) {
       // at least try to log it so we don't swallow exceptions
       LOGGER.error(e, "Unable to reset connection read-only state");
      }
     }
    }
   }
 );
}
origin: apache/incubator-druid

return getDBI().withHandle(
  new HandleCallback<Void>()
origin: apache/incubator-druid

@Override
public boolean enableSegment(final String segmentId)
{
 try {
  connector.getDBI().withHandle(
    new HandleCallback<Void>()
    {
     @Override
     public Void withHandle(Handle handle)
     {
      handle.createStatement(StringUtils.format("UPDATE %s SET used=true WHERE id = :id", getSegmentsTable()))
         .bind("id", segmentId)
         .execute();
      return null;
     }
    }
  );
 }
 catch (Exception e) {
  log.error(e, "Exception enabling segment %s", segmentId);
  return false;
 }
 return true;
}
origin: apache/incubator-druid

private void dropTable(final String tableName)
{
 connector.getDBI().withHandle(
   new HandleCallback<Void>()
   {
    @Override
    public Void withHandle(Handle handle)
    {
     handle.createStatement(StringUtils.format("DROP TABLE %s", tableName))
        .execute();
     return null;
    }
   }
 );
}
origin: apache/incubator-druid

private void dropTable(final String tableName)
{
 derbyConnector.getDBI().withHandle(
   new HandleCallback<Void>()
   {
    @Override
    public Void withHandle(Handle handle)
    {
     handle.createStatement(StringUtils.format("DROP TABLE %s", tableName))
        .execute();
     return null;
    }
   }
 );
}
origin: apache/incubator-druid

private void dropTable(final String tableName)
{
 connector.getDBI().withHandle(
   new HandleCallback<Void>()
   {
    @Override
    public Void withHandle(Handle handle)
    {
     handle.createStatement(StringUtils.format("DROP TABLE %s", tableName))
        .execute();
     return null;
    }
   }
 );
}
origin: apache/incubator-druid

 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)
     {
      final String query = StringUtils.format(
        "SELECT MAX(%s) FROM %s",
        tsColumn, table
      );
      return handle
        .createQuery(query)
        .map(TimestampMapper.FIRST)
        .first();
     }
    }
  );
  return update.getTime();

 }
}
origin: apache/hive

/**
 * @param connector                   SQL metadata connector to the metadata storage
 * @param metadataStorageTablesConfig Table config
 *
 * @return all the active data sources in the metadata storage
 */
static Collection<String> getAllDataSourceNames(SQLMetadataConnector connector,
  final MetadataStorageTablesConfig metadataStorageTablesConfig) {
 return connector.getDBI()
   .withHandle((HandleCallback<List<String>>) handle -> handle.createQuery(String.format(
     "SELECT DISTINCT(datasource) FROM %s WHERE used = true",
     metadataStorageTablesConfig.getSegmentsTable()))
     .fold(Lists.<String>newArrayList(),
       (druidDataSources, stringObjectMap, foldController, statementContext) -> {
        druidDataSources.add(MapUtils.getString(stringObjectMap, "datasource"));
        return druidDataSources;
       }));
}
origin: apache/incubator-druid

@Override
public Collection<String> getAllDataSourceNames()
{
 return connector.getDBI().withHandle(
   handle -> handle.createQuery(
     StringUtils.format("SELECT DISTINCT(datasource) FROM %s", getSegmentsTable())
   )
           .fold(
             new ArrayList<>(),
             new Folder3<List<String>, Map<String, Object>>()
             {
              @Override
              public List<String> fold(
                List<String> druidDataSources,
                Map<String, Object> stringObjectMap,
                FoldController foldController,
                StatementContext statementContext
              )
              {
               druidDataSources.add(
                 MapUtils.getString(stringObjectMap, "datasource")
               );
               return druidDataSources;
              }
             }
           )
 );
}
origin: apache/incubator-druid

 private void dropTable(final String tableName)
 {
  Assert.assertNull(connector.getDBI().withHandle(
    new HandleCallback<Void>()
    {
     @Override
     public Void withHandle(Handle handle)
     {
      handle.createStatement(StringUtils.format("DROP TABLE %s", tableName))
         .execute();
      return null;
     }
    }
  ));
 }
}
origin: apache/incubator-druid

private boolean removeSegmentFromTable(String segmentId)
{
 final int removed = connector.getDBI().withHandle(
   handle -> handle
     .createStatement(StringUtils.format("UPDATE %s SET used=false WHERE id = :segmentID", getSegmentsTable()))
     .bind("segmentID", segmentId)
     .execute()
 );
 return removed > 0;
}
origin: apache/incubator-druid

 @After
 public void cleanup()
 {
  connector.getDBI().withHandle(
    new HandleCallback<Void>()
    {
     @Override
     public Void withHandle(Handle handle)
     {
      handle.createStatement(StringUtils.format("DROP TABLE %s", tablesConfig.getSupervisorTable()))
         .execute();
      return null;
     }
    }
  );
 }
}
origin: apache/incubator-druid

@Override
public boolean removeDataSource(final String dataSource)
{
 try {
  final int removed = connector.getDBI().withHandle(
    handle -> handle.createStatement(
      StringUtils.format("UPDATE %s SET used=false WHERE dataSource = :dataSource", getSegmentsTable())
    ).bind("dataSource", dataSource).execute()
  );
  dataSources.remove(dataSource);
  if (removed == 0) {
   return false;
  }
 }
 catch (Exception e) {
  log.error(e, "Error removing datasource %s", dataSource);
  return false;
 }
 return true;
}
origin: apache/incubator-druid

private void unUseSegment()
{
 for (final DataSegment segment : SEGMENTS) {
  Assert.assertEquals(
    1,
    (int) derbyConnector.getDBI().<Integer>withHandle(
      new HandleCallback<Integer>()
      {
       @Override
       public Integer withHandle(Handle handle)
       {
        String request = StringUtils.format(
          "UPDATE %s SET used = false WHERE id = :id",
          derbyConnectorRule.metadataTablesConfigSupplier().get().getSegmentsTable()
        );
        return handle.createStatement(request).bind("id", segment.getId().toString()).execute();
       }
      }
    )
  );
 }
}
origin: apache/hive

private List<DataSegment> getUsedSegmentsList(DerbyConnectorTestUtility connector,
  final MetadataStorageTablesConfig metadataStorageTablesConfig) {
 return connector.getDBI()
   .withHandle(handle -> handle.createQuery(String.format(
     "SELECT payload FROM %s WHERE used=true ORDER BY created_date ASC",
     metadataStorageTablesConfig.getSegmentsTable()))
     .map((i, resultSet, statementContext) -> {
      try {
       return DruidStorageHandlerUtils.JSON_MAPPER.readValue(resultSet.getBytes("payload"), DataSegment.class);
      } catch (IOException e) {
       throw Throwables.propagate(e);
      }
     }).list());
}
origin: apache/incubator-druid

derbyConnector.getDBI().withHandle(
  (handle) -> {
   Batch batch = handle.createBatch();
org.skife.jdbi.v2DBIwithHandle

Javadoc

A convenience function which manages the lifecycle of a handle and yields it to a callback for use by clients.

Popular methods of DBI

  • <init>
    Constructor used to allow for obtaining a Connection in a customized manner. The org.skife.jdbi.v2.t
  • open
  • onDemand
    Create a new sql object which will obtain and release connections from this dbi instance, as it need
  • registerMapper
    Register a result set mapper which will have its parameterized type inspected to determine what it m
  • registerArgumentFactory
  • inTransaction
  • setSQLLog
    Specify the class used to log sql statements. Will be passed to all handles created from this instan
  • registerContainerFactory
  • setStatementLocator
    Use a non-standard StatementLocator to look up named statements for all handles created from this DB
  • setStatementRewriter
    Use a non-standard StatementRewriter to transform SQL for all Handle instances created by this DBI.
  • setTransactionHandler
    Specify the TransactionHandler instance to use. This allows overriding transaction semantics, or map
  • setTimingCollector
    Add a callback to accumulate timing information about the queries running from this data source.
  • setTransactionHandler,
  • setTimingCollector,
  • useHandle,
  • define,
  • close,
  • getStatementLocator,
  • getTransactionHandler,
  • registerColumnMapper

Popular in Java

  • Making http post requests using okhttp
  • onCreateOptionsMenu (Activity)
  • scheduleAtFixedRate (Timer)
  • getApplicationContext (Context)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now