use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class JdbcAdmin method createIndex.
@Override
public void createIndex(String namespace, String table, String columnName, Map<String, String> options) throws ExecutionException {
try (Connection connection = dataSource.getConnection()) {
createIndex(connection, namespace, table, columnName);
updateTableMetadata(connection, namespace, table, columnName, true);
} catch (SQLException e) {
throw new ExecutionException("creating the secondary index failed", e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class JdbcAdmin method dropTable.
@Override
public void dropTable(String namespace, String table) throws ExecutionException {
try (Connection connection = dataSource.getConnection()) {
dropTableInternal(connection, namespace, table);
deleteTableMetadata(connection, namespace, table);
} catch (SQLException e) {
throw new ExecutionException("dropping the table failed: " + getFullTableName(namespace, table), e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class JdbcDatabase method scan.
@Override
public Scanner scan(Scan scan) throws ExecutionException {
scan = copyAndSetTargetToIfNot(scan);
Connection connection = null;
try {
connection = dataSource.getConnection();
return jdbcService.getScanner(scan, connection);
} catch (SQLException e) {
close(connection);
throw new ExecutionException("scan operation failed", e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class JdbcDatabase method put.
@Override
public void put(Put put) throws ExecutionException {
put = copyAndSetTargetToIfNot(put);
Connection connection = null;
try {
connection = dataSource.getConnection();
if (!jdbcService.put(put, connection)) {
throw new NoMutationException("no mutation was applied");
}
} catch (SQLException e) {
throw new ExecutionException("put operation failed", e);
} finally {
close(connection);
}
}
use of com.scalar.db.exception.storage.ExecutionException 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);
}
}
Aggregations