Search in sources :

Example 56 with ExecutionException

use of com.scalar.db.exception.storage.ExecutionException 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);
    }
}
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 57 with ExecutionException

use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.

the class JdbcDatabase method get.

@Override
public Optional<Result> get(Get get) throws ExecutionException {
    get = copyAndSetTargetToIfNot(get);
    Connection connection = null;
    try {
        connection = dataSource.getConnection();
        return jdbcService.get(get, connection);
    } catch (SQLException e) {
        throw new ExecutionException("get 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)

Example 58 with ExecutionException

use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.

the class GrpcScanOnBidirectionalStream method throwIfErrorForNext.

private void throwIfErrorForNext(ResponseOrError responseOrError) throws ExecutionException {
    if (responseOrError.isError()) {
        hasMoreResults.set(false);
        Throwable error = responseOrError.getError();
        if (error instanceof StatusRuntimeException) {
            StatusRuntimeException e = (StatusRuntimeException) error;
            if (e.getStatus().getCode() == Code.INVALID_ARGUMENT) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }
        }
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new ExecutionException("failed to next", error);
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 59 with ExecutionException

use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.

the class GrpcScanOnBidirectionalStream method throwIfErrorForOpenScanner.

private void throwIfErrorForOpenScanner(ResponseOrError responseOrError) throws ExecutionException {
    if (responseOrError.isError()) {
        hasMoreResults.set(false);
        Throwable error = responseOrError.getError();
        if (error instanceof StatusRuntimeException) {
            StatusRuntimeException e = (StatusRuntimeException) error;
            if (e.getStatus().getCode() == Code.INVALID_ARGUMENT) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }
            if (e.getStatus().getCode() == Code.UNAVAILABLE) {
                throw new ServiceTemporaryUnavailableException(e.getMessage(), e);
            }
        }
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new ExecutionException("failed to open scanner", error);
    }
}
Also used : ServiceTemporaryUnavailableException(com.scalar.db.util.retry.ServiceTemporaryUnavailableException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(com.scalar.db.exception.storage.ExecutionException)

Example 60 with ExecutionException

use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.

the class CrudHandler method getFromStorage.

private Scanner getFromStorage(Scan scan) throws CrudException {
    try {
        // get only after image columns
        scan.clearProjections();
        LinkedHashSet<String> afterImageColumnNames = tableMetadataManager.getTransactionalTableMetadata(scan).getAfterImageColumnNames();
        scan.withProjections(afterImageColumnNames);
        scan.withConsistency(Consistency.LINEARIZABLE);
        return storage.scan(scan);
    } catch (ExecutionException e) {
        throw new CrudException("scan failed.", e);
    }
}
Also used : ExecutionException(com.scalar.db.exception.storage.ExecutionException) CrudException(com.scalar.db.exception.transaction.CrudException)

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