Search in sources :

Example 21 with SqlConnection

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

the class DbKvsGetRanges method getRowsForBatches.

private static SortedSetMultimap<Integer, byte[]> getRowsForBatches(Supplier<SqlConnection> connectionSupplier, String query, Object[] args) {
    SqlConnection connection = connectionSupplier.get();
    try {
        AgnosticResultSet results = connection.selectResultSetUnregisteredQuery(query, args);
        SortedSetMultimap<Integer, byte[]> ret = TreeMultimap.create(Ordering.natural(), UnsignedBytes.lexicographicalComparator());
        for (AgnosticResultRow row : results.rows()) {
            @SuppressWarnings("deprecation") byte[] rowName = row.getBytes("row_name");
            int batchNum = row.getInteger("batch_num");
            if (rowName != null) {
                ret.put(batchNum, rowName);
            }
        }
        return ret;
    } finally {
        closeSql(connection);
    }
}
Also used : AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) AgnosticResultRow(com.palantir.nexus.db.sql.AgnosticResultRow)

Example 22 with SqlConnection

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

the class OracleTableNameMapperTest method setup.

@Before
public void setup() {
    connectionSupplier = mock(ConnectionSupplier.class);
    oracleTableNameMapper = new OracleTableNameMapper();
    SqlConnection sqlConnection = mock(SqlConnection.class);
    when(connectionSupplier.get()).thenReturn(sqlConnection);
    resultSet = mock(AgnosticResultSet.class);
    when(sqlConnection.selectResultSetUnregisteredQuery(startsWith("SELECT short_table_name FROM atlasdb_table_names WHERE LOWER(short_table_name)"), anyObject())).thenReturn(resultSet);
}
Also used : ConnectionSupplier(com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier) AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) Before(org.junit.Before)

Example 23 with SqlConnection

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

the class OracleDdlTable method getCompactionConnection.

private SqlConnection getCompactionConnection() {
    SqlConnection sqlConnection = conns.get();
    try {
        int originalNetworkTimeout = sqlConnection.getUnderlyingConnection().getNetworkTimeout();
        int newNetworkMillis = Ints.saturatedCast(config.compactionConnectionTimeout());
        log.info("Increased sql socket read timeout from {} to {}", SafeArg.of("originalNetworkTimeoutMillis", originalNetworkTimeout), SafeArg.of("newNetworkTimeoutMillis", newNetworkMillis));
        sqlConnection.getUnderlyingConnection().setNetworkTimeout(compactionTimeoutExecutor, newNetworkMillis);
    } catch (SQLException e) {
        log.warn("Failed to increase socket read timeout for the connection. Encountered an exception:", e);
    }
    return sqlConnection;
}
Also used : SQLException(java.sql.SQLException) SqlConnection(com.palantir.nexus.db.sql.SqlConnection)

Aggregations

SqlConnection (com.palantir.nexus.db.sql.SqlConnection)23 Test (org.junit.Test)11 AgnosticResultSet (com.palantir.nexus.db.sql.AgnosticResultSet)6 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 Before (org.junit.Before)3 ConnectionSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier)2 OverflowSequenceSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.oracle.OverflowSequenceSupplier)2 PalantirSqlException (com.palantir.exception.PalantirSqlException)2 AgnosticResultRow (com.palantir.nexus.db.sql.AgnosticResultRow)2 ExecutionException (java.util.concurrent.ExecutionException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 TableMappingNotFoundException (com.palantir.atlasdb.keyvalue.impl.TableMappingNotFoundException)1 SqlTimer (com.palantir.nexus.db.monitoring.timer.SqlTimer)1 AgnosticResultSetImpl (com.palantir.nexus.db.sql.AgnosticResultSetImpl)1 ConnectionBackedSqlConnectionImpl (com.palantir.nexus.db.sql.ConnectionBackedSqlConnectionImpl)1 SQL (com.palantir.nexus.db.sql.SQL)1 SqlConnectionHelper (com.palantir.nexus.db.sql.SqlConnectionHelper)1 ArrayList (java.util.ArrayList)1