use of com.palantir.nexus.db.sql.AgnosticResultRow in project atlasdb by palantir.
the class DbKvs method getAllTableNames.
@Override
public Set<TableReference> getAllTableNames() {
return run(conn -> {
AgnosticResultSet results = conn.selectResultSetUnregisteredQuery("SELECT table_name FROM " + config.metadataTable().getQualifiedName());
Set<TableReference> ret = Sets.newHashSetWithExpectedSize(results.size());
for (AgnosticResultRow row : results.rows()) {
ret.add(TableReference.createUnsafe(row.getString("table_name")));
}
return ret;
});
}
use of com.palantir.nexus.db.sql.AgnosticResultRow in project atlasdb by palantir.
the class PostgresDdlTable method getMillisSinceLastCompact.
/**
* Returns the number of milliseconds since the last compaction, or Long.MAX_VALUE if
* compaction has never run.
*/
private long getMillisSinceLastCompact() {
AgnosticResultSet rs = conns.get().selectResultSetUnregisteredQuery("SELECT FLOOR(EXTRACT(EPOCH FROM GREATEST( " + " last_vacuum, last_autovacuum, last_analyze, last_autoanalyze" + "))*1000) AS last, " + "FLOOR(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP)*1000) AS current " + "FROM pg_stat_user_tables WHERE relname = ?", prefixedTableName());
AgnosticResultRow row = Iterables.getOnlyElement(rs.rows());
// last could be null if vacuum has never run
long last = row.getLong("last", -1);
if (last == -1) {
return Long.MAX_VALUE;
}
long current = row.getLong("current");
return current - last;
}
use of com.palantir.nexus.db.sql.AgnosticResultRow in project atlasdb by palantir.
the class OracleTableNameMapperTest method shouldThrowIfTable9999Exists.
@Test
public void shouldThrowIfTable9999Exists() {
when(resultSet.size()).thenReturn(1);
AgnosticResultRow row = mock(AgnosticResultRow.class);
when(row.getString(eq("short_table_name"))).thenReturn(getTableNameWithNumber(9999));
when(resultSet.get(eq(0))).thenReturn(row);
TableReference tableRef = TableReference.create(TEST_NAMESPACE, LONG_TABLE_NAME);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Cannot create any more tables with name starting with a_te__ThisIsAVeryLongT");
oracleTableNameMapper.getShortPrefixedTableName(connectionSupplier, TEST_PREFIX, tableRef);
}
use of com.palantir.nexus.db.sql.AgnosticResultRow in project atlasdb by palantir.
the class DbKvs method getMetadataForTables.
@Override
public Map<TableReference, byte[]> getMetadataForTables() {
return run(conn -> {
AgnosticResultSet results = conn.selectResultSetUnregisteredQuery("SELECT table_name, value FROM " + config.metadataTable().getQualifiedName());
Map<TableReference, byte[]> ret = Maps.newHashMapWithExpectedSize(results.size());
for (AgnosticResultRow row : results.rows()) {
ret.put(TableReference.createUnsafe(row.getString("table_name")), row.getBytes("value"));
}
return ret;
});
}
use of com.palantir.nexus.db.sql.AgnosticResultRow in project atlasdb by palantir.
the class OracleTableNameUnmapperTest method shouldReturnIfTableMappingExists.
@Test
public void shouldReturnIfTableMappingExists() throws TableMappingNotFoundException {
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);
assertThat(shortName, is(SHORT_TABLE_NAME));
}
Aggregations