Search in sources :

Example 1 with CrudConflictException

use of com.scalar.db.exception.transaction.CrudConflictException in project scalardb by scalar-labs.

the class GrpcTransactionOnBidirectionalStream method throwIfErrorForCrud.

private void throwIfErrorForCrud(ResponseOrError responseOrError) throws CrudException {
    if (responseOrError.isError()) {
        finished.set(true);
        Throwable error = responseOrError.getError();
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new CrudException("failed to execute crud", error);
    }
    TransactionResponse response = responseOrError.getResponse();
    if (response.hasError()) {
        TransactionResponse.Error error = response.getError();
        switch(error.getErrorCode()) {
            case INVALID_ARGUMENT:
                throw new IllegalArgumentException(error.getMessage());
            case CONFLICT:
                throw new CrudConflictException(error.getMessage());
            default:
                throw new CrudException(error.getMessage());
        }
    }
}
Also used : TransactionResponse(com.scalar.db.rpc.TransactionResponse) CrudConflictException(com.scalar.db.exception.transaction.CrudConflictException) CrudException(com.scalar.db.exception.transaction.CrudException)

Example 2 with CrudConflictException

use of com.scalar.db.exception.transaction.CrudConflictException in project scalardb by scalar-labs.

the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method throwIfErrorForCrud.

private void throwIfErrorForCrud(ResponseOrError responseOrError) throws CrudException {
    if (responseOrError.isError()) {
        finished.set(true);
        Throwable error = responseOrError.getError();
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new CrudException("failed to execute crud", error);
    }
    TwoPhaseCommitTransactionResponse response = responseOrError.getResponse();
    if (response.hasError()) {
        TwoPhaseCommitTransactionResponse.Error error = response.getError();
        switch(error.getErrorCode()) {
            case INVALID_ARGUMENT:
                throw new IllegalArgumentException(error.getMessage());
            case CONFLICT:
                throw new CrudConflictException(error.getMessage());
            default:
                throw new CrudException(error.getMessage());
        }
    }
}
Also used : TwoPhaseCommitTransactionResponse(com.scalar.db.rpc.TwoPhaseCommitTransactionResponse) CrudConflictException(com.scalar.db.exception.transaction.CrudConflictException) CrudException(com.scalar.db.exception.transaction.CrudException)

Aggregations

CrudConflictException (com.scalar.db.exception.transaction.CrudConflictException)2 CrudException (com.scalar.db.exception.transaction.CrudException)2 TransactionResponse (com.scalar.db.rpc.TransactionResponse)1 TwoPhaseCommitTransactionResponse (com.scalar.db.rpc.TwoPhaseCommitTransactionResponse)1