use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.
the class OracleOverflowWriteTable method delete.
@Override
public void delete(List<Entry<Cell, Long>> entries) {
List<Object[]> args = Lists.newArrayListWithCapacity(entries.size());
for (Map.Entry<Cell, Long> entry : entries) {
Cell cell = entry.getKey();
args.add(new Object[] { cell.getRowName(), cell.getColumnName(), entry.getValue() });
}
switch(config.overflowMigrationState()) {
case UNSTARTED:
deleteOverflow(config.singleOverflowTable(), args);
break;
case IN_PROGRESS:
deleteOverflow(config.singleOverflowTable(), args);
deleteOverflow(getShortOverflowTableName(), args);
break;
// fall through
case FINISHING:
case FINISHED:
deleteOverflow(getShortOverflowTableName(), args);
break;
default:
throw new EnumConstantNotPresentException(OverflowMigrationState.class, config.overflowMigrationState().name());
}
String shortTableName = oraclePrefixedTableNames.get(tableRef, conns);
SqlConnection conn = conns.get();
try {
log.info("Got connection for delete on table {}: {}, autocommit={}", shortTableName, conn.getUnderlyingConnection(), conn.getUnderlyingConnection().getAutoCommit());
} catch (PalantirSqlException | SQLException e) {
//
}
conn.updateManyUnregisteredQuery(" /* DELETE_ONE (" + shortTableName + ") */ " + " DELETE /*+ INDEX(m " + PrimaryKeyConstraintNames.get(shortTableName) + ") */ " + " FROM " + shortTableName + " m " + " WHERE m.row_name = ? " + " AND m.col_name = ? " + " AND m.ts = ?", args);
}
use of com.palantir.nexus.db.sql.SqlConnection 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.SqlConnection 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.SqlConnection in project atlasdb by palantir.
the class ConnectionManagerAwareDbKvs method getSimpleTimedSqlConnectionSupplier.
private static SqlConnectionSupplier getSimpleTimedSqlConnectionSupplier(ReentrantManagedConnectionSupplier connectionSupplier) {
Supplier<Connection> supplier = () -> connectionSupplier.get();
SQL sql = new SQL() {
@Override
protected SqlConfig getSqlConfig() {
return new SqlConfig() {
@Override
public boolean isSqlCancellationDisabled() {
return false;
}
protected Iterable<SqlTimer> getSqlTimers() {
return ImmutableList.of(SqlTimers.createDurationSqlTimer(), SqlTimers.createSqlStatsSqlTimer());
}
@Override
public SqlTimer getSqlTimer() {
return SqlTimers.createCombinedSqlTimer(getSqlTimers());
}
};
}
};
return new SqlConnectionSupplier() {
@Override
public SqlConnection get() {
return new ConnectionBackedSqlConnectionImpl(supplier.get(), () -> {
throw new UnsupportedOperationException("This SQL connection does not provide reliable timestamp.");
}, new SqlConnectionHelper(sql));
}
@Override
public void close() {
connectionSupplier.close();
}
};
}
use of com.palantir.nexus.db.sql.SqlConnection in project atlasdb by palantir.
the class DbKvs method runWriteForceAutocommit.
private <T> T runWriteForceAutocommit(TableReference tableRef, Function<DbWriteTable, T> runner) {
ConnectionSupplier conns = new ConnectionSupplier(connections);
try {
SqlConnection conn = conns.get();
boolean autocommit;
try {
autocommit = conn.getUnderlyingConnection().getAutoCommit();
} catch (PalantirSqlException e1) {
throw Throwables.rewrapAndThrowUncheckedException(e1);
} catch (SQLException e1) {
throw Throwables.rewrapAndThrowUncheckedException(e1);
}
if (!autocommit) {
return runWriteFreshConnection(conns, tableRef, runner);
} else {
return runner.apply(dbTables.createWrite(tableRef, conns));
}
} finally {
conns.close();
}
}
Aggregations