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");
}
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));
}
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);
}
}
Aggregations