use of com.palantir.nexus.db.sql.AgnosticResultSet 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.AgnosticResultSet 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.AgnosticResultSet in project atlasdb by palantir.
the class TableValueStyleCache method getTableType.
public TableValueStyle getTableType(final ConnectionSupplier connectionSupplier, final TableReference tableRef, TableReference metadataTable) {
try {
return valueStyleByTableRef.get(tableRef, () -> {
SqlConnection conn = connectionSupplier.get();
AgnosticResultSet results = conn.selectResultSetUnregisteredQuery(String.format("SELECT table_size FROM %s WHERE table_name = ?", metadataTable.getQualifiedName()), tableRef.getQualifiedName());
Preconditions.checkArgument(!results.rows().isEmpty(), "table %s not found", tableRef.getQualifiedName());
return TableValueStyle.byId(Iterables.getOnlyElement(results.rows()).getInteger("table_size"));
});
} catch (ExecutionException e) {
log.error("TableValueStyle for the table {} could not be retrieved.", tableRef.getQualifiedName());
throw Throwables.propagate(e);
}
}
use of com.palantir.nexus.db.sql.AgnosticResultSet in project atlasdb by palantir.
the class OracleTableNameUnmapper method getShortTableNameFromMappingTable.
@SuppressWarnings("checkstyle:NestedTryDepth")
public String getShortTableNameFromMappingTable(ConnectionSupplier connectionSupplier, String tablePrefix, TableReference tableRef) throws TableMappingNotFoundException {
String fullTableName = tablePrefix + DbKvs.internalTableName(tableRef);
try {
return unmappingCache.get(fullTableName, () -> {
SqlConnection conn = connectionSupplier.get();
AgnosticResultSet results = conn.selectResultSetUnregisteredQuery("SELECT short_table_name " + "FROM " + AtlasDbConstants.ORACLE_NAME_MAPPING_TABLE + " WHERE table_name = ?", fullTableName);
if (results.size() == 0) {
throw new TableMappingNotFoundException("The table " + fullTableName + " does not have a mapping." + "This might be because the table does not exist.");
}
return Iterables.getOnlyElement(results.rows()).getString("short_table_name");
});
} catch (ExecutionException e) {
throw new TableMappingNotFoundException(e.getCause());
}
}
use of com.palantir.nexus.db.sql.AgnosticResultSet 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;
});
}
Aggregations