Search in sources :

Example 1 with ScalarHandler

use of org.apache.commons.dbutils.handlers.ScalarHandler in project metacat by Netflix.

the class HiveConnectorFastTableService method exists.

/**
     * {@inheritDoc}.
     */
@Override
public boolean exists(@Nonnull final ConnectorContext requestContext, @Nonnull final QualifiedName name) {
    final long start = registry.clock().monotonicTime();
    final Map<String, String> tags = new HashMap<String, String>();
    tags.put("request", HiveMetrics.exists.name());
    boolean result = false;
    // Get data source
    final DataSource dataSource = DataSourceManager.get().get(catalogName);
    try (Connection conn = dataSource.getConnection()) {
        final Object qResult = new QueryRunner().query(conn, SQL_EXIST_TABLE_BY_NAME, new ScalarHandler(1), name.getDatabaseName(), name.getTableName());
        if (qResult != null) {
            result = true;
        }
    } catch (SQLException e) {
        throw Throwables.propagate(e);
    } finally {
        final long duration = registry.clock().monotonicTime() - start;
        log.debug("### Time taken to complete exists is {} ms", duration);
        this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ScalarHandler(org.apache.commons.dbutils.handlers.ScalarHandler) Connection(java.sql.Connection) QueryRunner(org.apache.commons.dbutils.QueryRunner) DataSource(javax.sql.DataSource)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 DataSource (javax.sql.DataSource)1 QueryRunner (org.apache.commons.dbutils.QueryRunner)1 ScalarHandler (org.apache.commons.dbutils.handlers.ScalarHandler)1