Skip to content

Commit

Permalink
JVMCBC-1208: Add query support
Browse files Browse the repository at this point in the history
Fixing an unreleased regression to single query transactions.
Core errors weren't being converted into the SDK errors as
the error mapper wasn't being applied.

Change-Id: I9f1602206aaf670f270ac5bf7529f9ed34885e75
Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/186233
Tested-by: Build Bot <[email protected]>
Reviewed-by: David Nault <[email protected]>
  • Loading branch information
programmatix committed Feb 8, 2023
1 parent 8a0439d commit 26daa61
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public CoreAsyncResponse<CoreQueryResult> queryAsync(String statement,
@Nullable NodeIdentifier target,
@Nullable Function<Throwable, RuntimeException> errorConverter) {
if (options.asTransaction()) {
CompletableFuture<CoreQueryResult> out = singleQueryTransactionBuffered(core, statement, options, queryContext).toFuture();
CompletableFuture<CoreQueryResult> out = singleQueryTransactionBuffered(core, statement, options, queryContext, errorConverter).toFuture();
return new CoreAsyncResponse(out, () -> {
});
} else {
Expand Down Expand Up @@ -212,7 +212,8 @@ private QueryRequest queryRequest(String statement,
private static Mono<CoreQueryResult> singleQueryTransactionBuffered(Core core,
String statement,
CoreQueryOptions opts,
@Nullable CoreQueryContext queryContext) {
@Nullable CoreQueryContext queryContext,
@Nullable Function<Throwable, RuntimeException> errorConverter) {
if (opts.commonOptions().retryStrategy().isPresent()) {
// Transactions require control of the retry strategy
throw new IllegalArgumentException("Cannot specify retryStrategy() if using asTransaction() on QueryOptions");
Expand All @@ -230,10 +231,13 @@ private static Mono<CoreQueryResult> singleQueryTransactionBuffered(Core core,

return tri.queryBlocking(statement, queryContext, shadowed, Optional.of(span.span()))
.onErrorResume(ex -> {
// From a cluster.query() transaction the user will be expecting the traditional SDK errors
// From a cluster.query() transaction the user will be expecting the traditional SDK errors.
if (ex instanceof CoreTransactionExpiredException) {
return Mono.error(new UnambiguousTimeoutException(ex.getMessage(), null));
}
if (errorConverter != null) {
ex = errorConverter.apply(ex);
}
return Mono.error(ex);
})
.doOnError(err -> span.finish(err))
Expand Down

0 comments on commit 26daa61

Please sign in to comment.