Search in sources :

Example 1 with TwoPhaseCommitTransactionResponse

use of com.scalar.db.rpc.TwoPhaseCommitTransactionResponse in project scalardb by scalar-labs.

the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method throwIfErrorForPreparation.

private void throwIfErrorForPreparation(ResponseOrError responseOrError) throws PreparationException {
    if (responseOrError.isError()) {
        finished.set(true);
        Throwable error = responseOrError.getError();
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new PreparationException("failed to prepare", error);
    }
    TwoPhaseCommitTransactionResponse response = responseOrError.getResponse();
    if (response.hasError()) {
        TwoPhaseCommitTransactionResponse.Error error = response.getError();
        if (error.getErrorCode() == ErrorCode.CONFLICT) {
            throw new PreparationConflictException(error.getMessage());
        }
        throw new PreparationException(error.getMessage());
    }
}
Also used : PreparationException(com.scalar.db.exception.transaction.PreparationException) TwoPhaseCommitTransactionResponse(com.scalar.db.rpc.TwoPhaseCommitTransactionResponse) PreparationConflictException(com.scalar.db.exception.transaction.PreparationConflictException)

Example 2 with TwoPhaseCommitTransactionResponse

use of com.scalar.db.rpc.TwoPhaseCommitTransactionResponse in project scalardb by scalar-labs.

the class GrpcTwoPhaseCommitTransactionOnBidirectionalStream method throwIfErrorForValidation.

private void throwIfErrorForValidation(ResponseOrError responseOrError) throws ValidationException {
    if (responseOrError.isError()) {
        finished.set(true);
        Throwable error = responseOrError.getError();
        if (error instanceof Error) {
            throw (Error) error;
        }
        throw new ValidationException("failed to validate", error);
    }
    TwoPhaseCommitTransactionResponse response = responseOrError.getResponse();
    if (response.hasError()) {
        TwoPhaseCommitTransactionResponse.Error error = response.getError();
        if (error.getErrorCode() == ErrorCode.CONFLICT) {
            throw new ValidationConflictException(error.getMessage());
        }
        throw new ValidationException(error.getMessage());
    }
}
Also used : ValidationException(com.scalar.db.exception.transaction.ValidationException) TwoPhaseCommitTransactionResponse(com.scalar.db.rpc.TwoPhaseCommitTransactionResponse) ValidationConflictException(com.scalar.db.exception.transaction.ValidationConflictException)

Example 3 with TwoPhaseCommitTransactionResponse

use of com.scalar.db.rpc.TwoPhaseCommitTransactionResponse 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

TwoPhaseCommitTransactionResponse (com.scalar.db.rpc.TwoPhaseCommitTransactionResponse)3 CrudConflictException (com.scalar.db.exception.transaction.CrudConflictException)1 CrudException (com.scalar.db.exception.transaction.CrudException)1 PreparationConflictException (com.scalar.db.exception.transaction.PreparationConflictException)1 PreparationException (com.scalar.db.exception.transaction.PreparationException)1 ValidationConflictException (com.scalar.db.exception.transaction.ValidationConflictException)1 ValidationException (com.scalar.db.exception.transaction.ValidationException)1