Skip to content

Commit 1087b2d

Browse files
authored
Was not using QueryContext in tx when scope=_default, but collection!=_default. (#1746)
Closes #1745.
1 parent 591dc5a commit 1087b2d

6 files changed

+1113
-2
lines changed

src/main/java/org/springframework/data/couchbase/core/ReactiveFindByQueryOperationSupport.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.couchbase.core;
1717

18+
import com.couchbase.client.core.api.query.CoreQueryContext;
1819
import reactor.core.publisher.Flux;
1920
import reactor.core.publisher.Mono;
2021

@@ -194,7 +195,7 @@ public Flux<T> all() {
194195
TransactionQueryOptions opts = buildTransactionOptions(pArgs.getOptions());
195196
JsonSerializer jSer = clientFactory.getCluster().environment().jsonSerializer();
196197
return AttemptContextReactiveAccessor.createReactiveTransactionAttemptContext(s.get().getCore(), jSer)
197-
.query(rs.name().equals(CollectionIdentifier.DEFAULT_SCOPE) ? null : rs, statement, opts);
198+
.query(OptionsBuilder.queryContext(pArgs.getScope(), pArgs.getCollection(), rs.bucketName()) == null ? null : rs, statement, opts);
198199
}
199200
});
200201

src/main/java/org/springframework/data/couchbase/core/ReactiveRemoveByQueryOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public Flux<RemoveResult> all() {
101101
} else {
102102
TransactionQueryOptions opts = OptionsBuilder
103103
.buildTransactionQueryOptions(buildQueryOptions(pArgs.getOptions()));
104-
CoreQueryContext queryContext = CollectionIdentifier.DEFAULT_SCOPE.equals(rs.name()) ? null : CoreQueryContext.of(rs.bucketName(), rs.name());
104+
CoreQueryContext queryContext = OptionsBuilder.queryContext(pArgs.getScope(), pArgs.getCollection(), rs.bucketName());
105105
return transactionContext.get().getCore()
106106
.queryBlocking(statement, queryContext, opts.builder().build(), false)
107107
.flatMapIterable(result -> result.collectRows()).map(row -> {

src/main/java/org/springframework/data/couchbase/core/query/OptionsBuilder.java

+7
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,11 @@ public static ScanOptions buildScanOptions(ScanOptions options, Object sort, Boo
565565
}
566566
return options;
567567
}
568+
569+
public static CoreQueryContext queryContext(String scope, String collection, String bucketName) {
570+
return (scope == null || CollectionIdentifier.DEFAULT_SCOPE.equals(scope))
571+
&& (collection == null || CollectionIdentifier.DEFAULT_COLLECTION.equals(collection)) ? null
572+
: CoreQueryContext.of(bucketName, scope);
573+
}
574+
}
568575
}

0 commit comments

Comments
 (0)