Search in sources :

Example 31 with ExecutionException

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 32 with ExecutionException

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 33 with ExecutionException

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ExecutionException(com.scalar.db.exception.storage.ExecutionException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException)

Example 34 with ExecutionException

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ExecutionException(com.scalar.db.exception.storage.ExecutionException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) NoMutationException(com.scalar.db.exception.storage.NoMutationException)

Example 35 with ExecutionException

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);
    }
}
Also used : Delete(com.scalar.db.api.Delete) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Mutation(com.scalar.db.api.Mutation) ExecutionException(com.scalar.db.exception.storage.ExecutionException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) RetriableExecutionException(com.scalar.db.exception.storage.RetriableExecutionException) NoMutationException(com.scalar.db.exception.storage.NoMutationException) Put(com.scalar.db.api.Put)

Aggregations

ExecutionException (com.scalar.db.exception.storage.ExecutionException)78 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)23 RetriableExecutionException (com.scalar.db.exception.storage.RetriableExecutionException)18 ObjectNotFoundException (software.amazon.awssdk.services.applicationautoscaling.model.ObjectNotFoundException)18 ResourceNotFoundException (software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException)18 SQLException (java.sql.SQLException)14 ArrayList (java.util.ArrayList)14 Connection (java.sql.Connection)12 Test (org.junit.jupiter.api.Test)11 HashSet (java.util.HashSet)10 NoMutationException (com.scalar.db.exception.storage.NoMutationException)9 TableMetadata (com.scalar.db.api.TableMetadata)8 Value (com.scalar.db.io.Value)8 Put (com.scalar.db.api.Put)7 TransactionState (com.scalar.db.api.TransactionState)6 CrudException (com.scalar.db.exception.transaction.CrudException)6 HashMap (java.util.HashMap)6 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)5 CosmosDatabase (com.azure.cosmos.CosmosDatabase)4 Get (com.scalar.db.api.Get)4