Search in sources :

Example 1 with SQL

use of com.palantir.nexus.db.sql.SQL in project atlasdb by palantir.

the class ConnectionManagerAwareDbKvs method getSimpleTimedSqlConnectionSupplier.

private static SqlConnectionSupplier getSimpleTimedSqlConnectionSupplier(ReentrantManagedConnectionSupplier connectionSupplier) {
    Supplier<Connection> supplier = () -> connectionSupplier.get();
    SQL sql = new SQL() {

        @Override
        protected SqlConfig getSqlConfig() {
            return new SqlConfig() {

                @Override
                public boolean isSqlCancellationDisabled() {
                    return false;
                }

                protected Iterable<SqlTimer> getSqlTimers() {
                    return ImmutableList.of(SqlTimers.createDurationSqlTimer(), SqlTimers.createSqlStatsSqlTimer());
                }

                @Override
                public SqlTimer getSqlTimer() {
                    return SqlTimers.createCombinedSqlTimer(getSqlTimers());
                }
            };
        }
    };
    return new SqlConnectionSupplier() {

        @Override
        public SqlConnection get() {
            return new ConnectionBackedSqlConnectionImpl(supplier.get(), () -> {
                throw new UnsupportedOperationException("This SQL connection does not provide reliable timestamp.");
            }, new SqlConnectionHelper(sql));
        }

        @Override
        public void close() {
            connectionSupplier.close();
        }
    };
}
Also used : Connection(java.sql.Connection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) SqlTimer(com.palantir.nexus.db.monitoring.timer.SqlTimer) ConnectionBackedSqlConnectionImpl(com.palantir.nexus.db.sql.ConnectionBackedSqlConnectionImpl) SqlConnectionHelper(com.palantir.nexus.db.sql.SqlConnectionHelper) SQL(com.palantir.nexus.db.sql.SQL)

Aggregations

SqlTimer (com.palantir.nexus.db.monitoring.timer.SqlTimer)1 ConnectionBackedSqlConnectionImpl (com.palantir.nexus.db.sql.ConnectionBackedSqlConnectionImpl)1 SQL (com.palantir.nexus.db.sql.SQL)1 SqlConnection (com.palantir.nexus.db.sql.SqlConnection)1 SqlConnectionHelper (com.palantir.nexus.db.sql.SqlConnectionHelper)1 Connection (java.sql.Connection)1