use of com.scalar.db.exception.storage.NoMutationException in project scalardb by scalar-labs.
the class JdbcDatabase method mutate.
@Override
public void mutate(List<? extends Mutation> mutations) throws ExecutionException {
if (mutations.size() == 1) {
Mutation mutation = mutations.get(0);
if (mutation instanceof Put) {
put((Put) mutation);
} else if (mutation instanceof Delete) {
delete((Delete) mutation);
}
return;
}
mutations = copyAndSetTargetToIfNot(mutations);
Connection connection = null;
try {
connection = dataSource.getConnection();
connection.setAutoCommit(false);
} catch (SQLException e) {
close(connection);
throw new ExecutionException("mutate operation failed", e);
}
try {
if (!jdbcService.mutate(mutations, connection)) {
try {
connection.rollback();
} catch (SQLException e) {
throw new ExecutionException("failed to rollback", e);
}
throw new NoMutationException("no mutation was applied");
} else {
connection.commit();
}
} catch (SQLException e) {
try {
connection.rollback();
} catch (SQLException sqlException) {
throw new ExecutionException("failed to rollback", sqlException);
}
if (JdbcUtils.isConflictError(e, rdbEngine)) {
// conflicts can happen. Throw RetriableExecutionException in that case.
throw new RetriableExecutionException("conflict happened in a mutate operation", e);
}
throw new ExecutionException("mutate operation failed", e);
} finally {
close(connection);
}
}
use of com.scalar.db.exception.storage.NoMutationException in project scalardb by scalar-labs.
the class MutateStatementHandler method throwException.
private void throwException(CosmosException exception) throws ExecutionException {
LOGGER.error(exception.getMessage());
int statusCode = exception.getSubStatusCode();
if (statusCode == CosmosErrorCode.PRECONDITION_FAILED.get()) {
throw new NoMutationException("no mutation was applied.");
} else if (statusCode == CosmosErrorCode.RETRY_WITH.get()) {
throw new RetriableExecutionException(exception.getMessage(), exception);
}
throw new ExecutionException(exception.getMessage(), exception);
}
use of com.scalar.db.exception.storage.NoMutationException in project scalardb by scalar-labs.
the class JdbcDatabase method delete.
@Override
public void delete(Delete delete) throws ExecutionException {
delete = copyAndSetTargetToIfNot(delete);
Connection connection = null;
try {
connection = dataSource.getConnection();
if (!jdbcService.delete(delete, connection)) {
throw new NoMutationException("no mutation was applied");
}
} catch (SQLException e) {
throw new ExecutionException("delete operation failed", e);
} finally {
close(connection);
}
}
use of com.scalar.db.exception.storage.NoMutationException in project scalardb by scalar-labs.
the class DeleteStatementHandler method handle.
@Nonnull
@Override
public List<Map<String, AttributeValue>> handle(Operation operation) throws ExecutionException {
checkArgument(operation, Delete.class);
Delete delete = (Delete) operation;
TableMetadata tableMetadata = metadataManager.getTableMetadata(operation);
try {
delete(delete, tableMetadata);
} catch (ConditionalCheckFailedException e) {
throw new NoMutationException("no mutation was applied.", e);
} catch (TransactionConflictException e) {
throw new RetriableExecutionException(e.getMessage(), e);
} catch (DynamoDbException e) {
throw new ExecutionException(e.getMessage(), e);
}
return Collections.emptyList();
}
Aggregations