use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.
the class GrpcTransactionOnBidirectionalStream method scan.
public List<Result> scan(Scan scan) throws CrudException {
throwIfTransactionFinished();
ResponseOrError responseOrError = sendRequest(TransactionRequest.newBuilder().setScanRequest(ScanRequest.newBuilder().setScan(ProtoUtils.toScan(scan))).build());
throwIfErrorForCrud(responseOrError);
TableMetadata tableMetadata = getTableMetadata(scan);
return responseOrError.getResponse().getScanResponse().getResultList().stream().map(r -> ProtoUtils.toResult(r, tableMetadata)).collect(Collectors.toList());
}
use of com.scalar.db.exception.transaction.CrudException 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());
}
}
}
use of com.scalar.db.exception.transaction.CrudException 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());
}
}
}
use of com.scalar.db.exception.transaction.CrudException in project scalardb by scalar-labs.
the class CrudHandler method getFromStorage.
private Optional<TransactionResult> getFromStorage(Get get) throws CrudException {
try {
// get only after image columns
get.clearProjections();
LinkedHashSet<String> afterImageColumnNames = tableMetadataManager.getTransactionalTableMetadata(get).getAfterImageColumnNames();
get.withProjections(afterImageColumnNames);
get.withConsistency(Consistency.LINEARIZABLE);
return storage.get(get).map(TransactionResult::new);
} catch (ExecutionException e) {
throw new CrudException("get failed.", e);
}
}
use of com.scalar.db.exception.transaction.CrudException 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);
}
}
Aggregations