Search in sources :

Example 1 with PreparedStatementBuilder

use of com.hortonworks.registries.storage.impl.jdbc.provider.sql.statement.PreparedStatementBuilder in project registry by hortonworks.

the class AbstractQueryExecutor method buildCache.

private Cache<SqlQuery, PreparedStatementBuilder> buildCache(CacheBuilder<SqlQuery, PreparedStatementBuilder> cacheBuilder) {
    return cacheBuilder.removalListener(new RemovalListener<SqlQuery, PreparedStatementBuilder>() {

        /**
         * Cleanup operation for when the entry is removed from cache
         */
        @Override
        public void onRemoval(RemovalNotification<SqlQuery, PreparedStatementBuilder> notification) {
            final PreparedStatementBuilder preparedStatementBuilder = notification.getValue();
            log.debug("Removed entry from cache [key:{}, val: {}]", notification.getKey(), preparedStatementBuilder);
            log.debug("Cache size: {}", cache.size());
            if (preparedStatementBuilder != null && !transactionBookKeeper.hasActiveTransaction(Thread.currentThread().getId())) {
                closeConnection(preparedStatementBuilder.getConnection());
            }
        }
    }).build();
}
Also used : RemovalNotification(com.google.common.cache.RemovalNotification) RemovalListener(com.google.common.cache.RemovalListener) PreparedStatementBuilder(com.hortonworks.registries.storage.impl.jdbc.provider.sql.statement.PreparedStatementBuilder)

Aggregations

RemovalListener (com.google.common.cache.RemovalListener)1 RemovalNotification (com.google.common.cache.RemovalNotification)1 PreparedStatementBuilder (com.hortonworks.registries.storage.impl.jdbc.provider.sql.statement.PreparedStatementBuilder)1