Skip to content

Commit 7935a9f

Browse files
authored
Removing core transaction attempt context bound couchbase client factory rebased (#1449)
* Move ReactiveTransactionsWrapper tests into a new file * (Temporarily?) disabling tests using CouchbaseTransactionOperation or TransactionalOperator As I feel we should be removing/not-supporting these, and on this branch I've broken them. * Make all transaction tests call assertNotInTransaction * Removing unused code * Instead of binding the transaction AttemptContext to a CouchbaseClientFactory, fetch it from ThreadLocalStorage (or the reactive context) instead. This allows a lot of simplifying: * The non-trivial ReactiveCouchbaseClientUtils can be removed * As can CoreTransactionAttemptContextBoundCouchbaseClientFactory Also removing TransactionalSupport.one as it wasn't providing as much DRY utility as I thought it would - only used in two places. This change won't compile on its own. To reduce the complexity of this patchset, the Reactive*OperationSupport changes will go into a separate commit. * Reactive*OperationSupport changes to support the previous commit. * Fixing ReactiveRemoveByQuerySupport. Both to support the changes to TransactionalSupport. And to fix the TODO where the query resuls were not being handled. * Disabling a test * Adding CouchbaseTransactionsWrapperTemplateIntegrationTests * Another advantage of removing CoreTransactionAttemptContextBoundCouchbaseClientFactory is we can remove Cluster and ClusterInterface. * Adding CouchbaseReactiveTransactionsWrapperTemplateIntegrationTests Some of these tests are currently failing - tracking down where the issue is.
1 parent 5633181 commit 7935a9f

File tree

37 files changed

+1388
-1558
lines changed

37 files changed

+1388
-1558
lines changed

src/main/java/com/couchbase/client/java/Cluster.java

-589
This file was deleted.

src/main/java/com/couchbase/client/java/ClusterInterface.java

-111
This file was deleted.

src/main/java/com/couchbase/client/java/transactions/AttemptContextReactiveAccessor.java

+27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package com.couchbase.client.java.transactions;
1818

19+
import java.io.IOException;
1920
import java.lang.reflect.Field;
2021
import java.lang.reflect.Method;
2122
import java.time.Duration;
@@ -26,14 +27,20 @@
2627
import java.util.logging.Logger;
2728

2829
import com.couchbase.client.core.annotation.Stability;
30+
import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode;
31+
import com.couchbase.client.core.error.EncodingFailureException;
32+
import com.couchbase.client.core.json.Mapper;
33+
import com.couchbase.client.core.msg.query.QueryRequest;
2934
import com.couchbase.client.core.transaction.CoreTransactionAttemptContext;
3035
import com.couchbase.client.core.transaction.CoreTransactionContext;
3136
import com.couchbase.client.core.transaction.CoreTransactionsReactive;
3237
import com.couchbase.client.core.transaction.config.CoreMergedTransactionConfig;
3338
import com.couchbase.client.core.transaction.config.CoreTransactionOptions;
3439
import com.couchbase.client.core.transaction.log.CoreTransactionLogger;
3540
import com.couchbase.client.core.transaction.support.AttemptState;
41+
import com.couchbase.client.java.ReactiveScope;
3642
import com.couchbase.client.java.codec.JsonSerializer;
43+
import com.couchbase.client.java.json.JsonObject;
3744
import reactor.core.publisher.Mono;
3845
import reactor.util.annotation.Nullable;
3946

@@ -131,4 +138,24 @@ public static TransactionResult run(Transactions transactions, Consumer<Transact
131138
return reactive(transactions).runBlocking(transactionLogic, coreTransactionOptions);
132139
}
133140

141+
// todo gp have C&Ped this from SDK, needs to be exposed properly in SDK
142+
public static ObjectNode createTransactionOptions(final ReactiveScope scope,
143+
final String statement,
144+
final TransactionQueryOptions options) {
145+
JsonObject json = JsonObject.create()
146+
.put("statement", statement);
147+
if (scope != null) {
148+
json.put("query_context", QueryRequest.queryContext(scope.bucketName(), scope.name()));
149+
}
150+
if (options != null) {
151+
options.builder().build().injectParams(json);
152+
}
153+
try {
154+
ObjectNode opts = Mapper.reader().readValue(json.toBytes(), ObjectNode.class);
155+
return opts;
156+
} catch (IOException e) {
157+
throw new EncodingFailureException(e);
158+
}
159+
}
160+
134161
}

src/main/java/org/springframework/data/couchbase/ReactiveCouchbaseClientFactory.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.couchbase.client.core.transaction.CoreTransactionAttemptContext;
1919
import com.couchbase.client.java.Cluster;
20-
import com.couchbase.client.java.ClusterInterface;
2120
import com.couchbase.client.java.Collection;
2221
import com.couchbase.client.java.Scope;
2322
import com.couchbase.client.java.transactions.config.TransactionOptions;
@@ -42,7 +41,7 @@ public interface ReactiveCouchbaseClientFactory /*extends CodecRegistryProvider*
4241
/**
4342
* Provides access to the managed SDK {@link Cluster} reference.
4443
*/
45-
ClusterInterface getCluster();
44+
Cluster getCluster();
4645

4746
/**
4847
* Provides access to the managed SDK {@link Scope} reference
@@ -91,12 +90,6 @@ public interface ReactiveCouchbaseClientFactory /*extends CodecRegistryProvider*
9190

9291
ReactiveCouchbaseResourceHolder getResourceHolder(TransactionOptions options, CoreTransactionAttemptContext ctx);
9392

94-
/*
95-
* (non-Javadoc)
96-
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#withSession(com.mongodb.session.ClientSession)
97-
*/
98-
ReactiveCouchbaseClientFactory withCore(ReactiveCouchbaseResourceHolder core);
99-
10093
/*
10194
* (non-Javadoc)
10295
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#with(com.mongodb.session.ClientSession)

0 commit comments

Comments
 (0)