use of com.palantir.exception.PalantirSqlException 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.exception.PalantirSqlException in project atlasdb by palantir.
the class AbstractDbWriteTable method put.
private void put(List<Object[]> args) {
try {
String prefixedTableName = prefixedTableNames.get(tableRef, conns);
conns.get().insertManyUnregisteredQuery("/* INSERT_ONE (" + prefixedTableName + ") */" + " INSERT INTO " + prefixedTableName + " (row_name, col_name, ts, val) " + " VALUES (?, ?, ?, ?) ", args);
} catch (PalantirSqlException e) {
if (ExceptionCheck.isUniqueConstraintViolation(e)) {
throw new KeyAlreadyExistsException("primary key violation", e);
}
throw e;
}
}
use of com.palantir.exception.PalantirSqlException 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();
}
}
use of com.palantir.exception.PalantirSqlException in project atlasdb by palantir.
the class OracleOverflowWriteTable method putSentinels.
@Override
public void putSentinels(Iterable<Cell> cells) {
byte[] value = new byte[0];
long ts = Value.INVALID_VALUE_TIMESTAMP;
for (List<Cell> batch : Iterables.partition(Ordering.natural().immutableSortedCopy(cells), 1000)) {
List<Object[]> args = Lists.newArrayListWithCapacity(batch.size());
for (Cell cell : batch) {
args.add(new Object[] { cell.getRowName(), cell.getColumnName(), ts, value, null, cell.getRowName(), cell.getColumnName(), ts });
}
while (true) {
try {
String shortTableName = oraclePrefixedTableNames.get(tableRef, conns);
conns.get().insertManyUnregisteredQuery("/* INSERT_WHERE_NOT_EXISTS (" + shortTableName + ") */" + " INSERT INTO " + shortTableName + " (row_name, col_name, ts, val, overflow)" + " SELECT ?, ?, ?, ?, ? FROM DUAL" + " WHERE NOT EXISTS (" + " SELECT * FROM " + shortTableName + " WHERE row_name = ?" + " AND col_name = ?" + " AND ts = ?)", args);
break;
} catch (PalantirSqlException e) {
// we can't do atomic put if not exists, so retry if we get constraint violations
if (!ExceptionCheck.isUniqueConstraintViolation(e)) {
throw e;
}
}
}
}
}
use of com.palantir.exception.PalantirSqlException in project atlasdb by palantir.
the class BasicSQL method createPreparedStatement.
/**
* Encapsulates the logic for creating a prepared statement with the arguments set
*/
private PreparedStatement createPreparedStatement(Connection c, String sql, Object[] vs) throws PalantirSqlException {
PreparedStatement ps;
ps = Connections.prepareStatement(c, sql);
List<BlobHandler> toClean = Lists.newArrayList();
if (vs != null) {
try {
for (int i = 0; i < vs.length; i++) {
BlobHandler cleanup = setObject(c, ps, i + 1, vs[i]);
if (cleanup != null) {
toClean.add(cleanup);
}
}
} catch (Exception e) {
// if we throw, we need to clean up any blobs we have already made
for (BlobHandler cleanupBlob : toClean) {
try {
cleanupBlob.freeTemporary();
} catch (Exception e1) {
// $NON-NLS-1$
SqlLoggers.LOGGER.error("failed to free temp blob", e1);
}
}
BasicSQLUtils.throwUncheckedIfSQLException(e);
throw Throwables.throwUncheckedException(e);
}
}
return BlobCleanupPreparedStatement.create(ps, toClean);
}
Aggregations