Search in sources :

Example 6 with AgnosticResultRow

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

the class OracleTableNameUnmapperTest method cacheIsActuallyUsed.

@Test
public void cacheIsActuallyUsed() throws TableMappingNotFoundException {
    // do a normal read
    when(resultSet.size()).thenReturn(1);
    AgnosticResultRow row = mock(AgnosticResultRow.class);
    when(row.getString(eq("short_table_name"))).thenReturn(SHORT_TABLE_NAME);
    doReturn(ImmutableList.of(row)).when(resultSet).rows();
    String shortName = oracleTableNameUnmapper.getShortTableNameFromMappingTable(connectionSupplier, TEST_PREFIX, TABLE_REF_2);
    assertThat(shortName, is(SHORT_TABLE_NAME));
    // verify that underlying datastore was called once instead of hitting the cache
    verify(row, times(1)).getString("short_table_name");
    // read again looking for the same table
    oracleTableNameUnmapper.getShortTableNameFromMappingTable(connectionSupplier, TEST_PREFIX, TABLE_REF_2);
    // verify that cache was hit and underlying datastore was _still_ only called once
    verify(row, times(1)).getString("short_table_name");
}
Also used : AgnosticResultRow(com.palantir.nexus.db.sql.AgnosticResultRow) Test(org.junit.Test)

Example 7 with AgnosticResultRow

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

the class TableValueStyleCacheTest method setup.

@Before
public void setup() {
    SqlConnection mockConnection = mock(SqlConnection.class);
    when(connectionSupplier.get()).thenReturn(mockConnection);
    AgnosticResultSet resultSet = mock(AgnosticResultSet.class);
    when(mockConnection.selectResultSetUnregisteredQuery(startsWith("SELECT table_size FROM"), anyObject())).thenReturn(resultSet);
    AgnosticResultRow row = mock(AgnosticResultRow.class);
    when(row.getInteger(eq("table_size"))).thenReturn(TableValueStyle.OVERFLOW.getId());
    doReturn(ImmutableList.of(row)).when(resultSet).rows();
    when(mockConnection.getUnderlyingConnection()).thenReturn(mock(Connection.class));
}
Also used : AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) Connection(java.sql.Connection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) AgnosticResultRow(com.palantir.nexus.db.sql.AgnosticResultRow) Before(org.junit.Before)

Example 8 with AgnosticResultRow

use of com.palantir.nexus.db.sql.AgnosticResultRow 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)

Aggregations

AgnosticResultRow (com.palantir.nexus.db.sql.AgnosticResultRow)8 AgnosticResultSet (com.palantir.nexus.db.sql.AgnosticResultSet)5 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)3 Test (org.junit.Test)3 SqlConnection (com.palantir.nexus.db.sql.SqlConnection)2 Connection (java.sql.Connection)1 Before (org.junit.Before)1