Skip to content

Commit b0805ad

Browse files
committed
Remove unnecessary methods From ReactiveCouchbaseClientFactory.
Also rationalized naming of methods and other changes.
1 parent 1e71f1c commit b0805ad

22 files changed

+143
-344
lines changed

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

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
package org.springframework.data.couchbase;
1717

1818
import com.couchbase.client.core.transaction.CoreTransactionAttemptContext;
19-
import com.couchbase.client.java.Bucket;
2019
import com.couchbase.client.java.Cluster;
2120
import com.couchbase.client.java.ClusterInterface;
2221
import com.couchbase.client.java.Collection;
2322
import com.couchbase.client.java.Scope;
24-
import com.couchbase.client.java.transactions.ReactiveTransactionAttemptContext;
2523
import com.couchbase.client.java.transactions.config.TransactionOptions;
2624
import org.springframework.data.couchbase.transaction.CouchbaseTransactionalOperator;
2725
import org.springframework.data.couchbase.transaction.ReactiveCouchbaseResourceHolder;
@@ -44,46 +42,31 @@ public interface ReactiveCouchbaseClientFactory /*extends CodecRegistryProvider*
4442
/**
4543
* Provides access to the managed SDK {@link Cluster} reference.
4644
*/
47-
Mono<ClusterInterface> getCluster();
45+
ClusterInterface getCluster();
4846

4947
/**
50-
* Provides access to the managed SDK {@link Cluster} reference.
51-
*/
52-
ClusterInterface getBlockingCluster();
53-
54-
/**
55-
* Provides access to the managed SDK {@link Bucket} reference.
56-
*/
57-
Mono<Bucket> getBucket();
58-
59-
/**
60-
* Provides access to the managed SDK {@link Scope} reference.
48+
* Provides access to the managed SDK {@link Scope} reference
6149
*/
62-
Mono<Scope> getScope();
50+
Scope getScope(String scopeName);
6351

6452
/**
65-
* Provides access to the managed SDK {@link Scope} reference without block()
53+
* Provides access to the managed SDK {@link Scope} reference
6654
*/
67-
Scope getBlockingScope(String scopeName);
55+
Scope getScope();
6856

6957
/**
7058
* Provides access to a collection (identified by its name) in managed SDK {@link Scope} reference.
7159
*
7260
* @param name the name of the collection. If null is passed in, the default collection is assumed.
7361
*/
74-
Mono<Collection> getCollection(String name);
62+
Mono<Collection> getCollectionMono(String name);
7563

7664
/**
7765
* Provides access to a collection (identified by its name) without block()
7866
*
7967
* @param name the name of the collection. If null is passed in, the default collection is assumed.
8068
*/
81-
Collection getBlockingCollection(String collectionName);
82-
83-
/**
84-
* Provides access to the default collection.
85-
*/
86-
Mono<Collection> getDefaultCollection();
69+
Collection getCollection(String collectionName);
8770

8871
/**
8972
* Returns a new {@link CouchbaseClientFactory} set to the scope given as an argument.
@@ -98,15 +81,15 @@ public interface ReactiveCouchbaseClientFactory /*extends CodecRegistryProvider*
9881
*/
9982
PersistenceExceptionTranslator getExceptionTranslator();
10083

101-
Mono<ReactiveCouchbaseResourceHolder> getTransactionResources(TransactionOptions options);
84+
Mono<ReactiveCouchbaseResourceHolder> getResourceHolderMono();
10285

10386
String getBucketName();
10487

10588
String getScopeName();
10689

10790
void close() throws IOException;
10891

109-
ReactiveCouchbaseResourceHolder getTransactionResources(TransactionOptions options, CoreTransactionAttemptContext ctx);
92+
ReactiveCouchbaseResourceHolder getResourceHolder(TransactionOptions options, CoreTransactionAttemptContext ctx);
11093

11194
/*
11295
* (non-Javadoc)

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

Lines changed: 38 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
import org.springframework.data.couchbase.transaction.SessionAwareMethodInterceptor;
2323
import org.springframework.util.ObjectUtils;
2424

25-
import com.couchbase.client.java.Bucket;
2625
import com.couchbase.client.java.Cluster;
2726
import com.couchbase.client.java.Collection;
2827
import com.couchbase.client.java.Scope;
2928

3029
public class SimpleReactiveCouchbaseClientFactory implements ReactiveCouchbaseClientFactory {
31-
final Mono<ClusterInterface> cluster;
32-
final ClusterInterface theCluster;
30+
final ClusterInterface cluster;
3331
final String bucketName;
3432
final String scopeName;
3533
final PersistenceExceptionTranslator exceptionTranslator;
@@ -38,9 +36,8 @@ public class SimpleReactiveCouchbaseClientFactory implements ReactiveCouchbaseCl
3836
CouchbaseTransactionalOperator transactionalOperator;
3937

4038
public SimpleReactiveCouchbaseClientFactory(Cluster cluster, String bucketName, String scopeName,
41-
CouchbaseTransactionalOperator transactionalOperator) {
42-
this.cluster = Mono.just(cluster);
43-
this.theCluster = cluster;
39+
CouchbaseTransactionalOperator transactionalOperator) {
40+
this.cluster = cluster;
4441
this.bucketName = bucketName;
4542
this.scopeName = scopeName;
4643
this.exceptionTranslator = new CouchbaseExceptionTranslator();
@@ -53,20 +50,10 @@ public SimpleReactiveCouchbaseClientFactory(Cluster cluster, String bucketName,
5350
this(cluster, bucketName, scopeName, null);
5451
}
5552

56-
@Override
57-
public Mono<ClusterInterface> getCluster() {
58-
return cluster;
59-
}
60-
61-
62-
@Override
63-
public ClusterInterface getBlockingCluster() {
64-
return theCluster;
65-
}
6653

6754
@Override
68-
public Mono<Bucket> getBucket() {
69-
return cluster.map((c) -> c.bucket(bucketName));
55+
public ClusterInterface getCluster() {
56+
return cluster;
7057
}
7158

7259
@Override
@@ -75,13 +62,13 @@ public String getBucketName() {
7562
}
7663

7764
@Override
78-
public Mono<Scope> getScope() {
79-
return cluster.map((c) -> c.bucket(bucketName).scope(scopeName != null ? scopeName : DEFAULT_SCOPE));
65+
public Scope getScope(String scopeName) {
66+
return cluster.bucket(bucketName)
67+
.scope(scopeName != null ? scopeName : (this.scopeName != null ? this.scopeName : DEFAULT_SCOPE));
8068
}
8169

82-
@Override
83-
public Scope getBlockingScope(String scopeName) {
84-
return theCluster.bucket(bucketName).scope(scopeName != null ? scopeName : (this.scopeName != null ? this.scopeName : DEFAULT_SCOPE));
70+
@Override public Scope getScope(){
71+
return getScope(null);
8572
}
8673

8774
@Override
@@ -90,7 +77,7 @@ public String getScopeName() {
9077
}
9178

9279
@Override
93-
public Mono<Collection> getCollection(String collectionName) {
80+
public Mono<Collection> getCollectionMono(String collectionName) {
9481
if (getScopeName() != null && !DEFAULT_SCOPE.equals(getScopeName())) {
9582
if (collectionName == null || DEFAULT_COLLECTION.equals(collectionName)) {
9683
throw new IllegalStateException("A collectionName must be provided if a non-default scope is used.");
@@ -102,11 +89,11 @@ public Mono<Collection> getCollection(String collectionName) {
10289
"A collectionName must be null or " + DEFAULT_COLLECTION + " if scope is null or " + DEFAULT_SCOPE);
10390
}
10491
}
105-
return getScope().map((s) -> s.collection(collectionName != null ? collectionName : DEFAULT_COLLECTION));
92+
return Mono.just(getScope()).map((s) -> s.collection(collectionName != null ? collectionName : DEFAULT_COLLECTION));
10693
}
10794

10895
@Override
109-
public Collection getBlockingCollection(String collectionName) {
96+
public Collection getCollection(String collectionName) {
11097
if (getScopeName() != null && !DEFAULT_SCOPE.equals(getScopeName())) {
11198
if (collectionName == null || DEFAULT_COLLECTION.equals(collectionName)) {
11299
throw new IllegalStateException("A collectionName must be provided if a non-default scope is used.");
@@ -118,20 +105,13 @@ public Collection getBlockingCollection(String collectionName) {
118105
"A collectionName must be null or " + DEFAULT_COLLECTION + " if scope is null or " + DEFAULT_SCOPE);
119106
}
120107
}
121-
return theCluster.bucket(bucketName).scope(scopeName != null ? scopeName : DEFAULT_SCOPE).collection(collectionName != null ? collectionName : DEFAULT_COLLECTION);
122-
}
123-
124-
@Override
125-
public Mono<Collection> getDefaultCollection() {
126-
if (getScopeName() != null && DEFAULT_SCOPE.equals(getScopeName())) {
127-
throw new IllegalStateException("A collectionName must be provided if a non-default scope is used.");
128-
}
129-
return cluster.map((c) -> c.bucket(bucketName).defaultCollection());
108+
return cluster.bucket(bucketName).scope(scopeName != null ? scopeName : DEFAULT_SCOPE)
109+
.collection(collectionName != null ? collectionName : DEFAULT_COLLECTION);
130110
}
131111

132112
@Override
133113
public ReactiveCouchbaseClientFactory withScope(String scopeName) {
134-
return new SimpleReactiveCouchbaseClientFactory((Cluster) cluster.block(), bucketName,
114+
return new SimpleReactiveCouchbaseClientFactory((Cluster) cluster, bucketName,
135115
scopeName != null ? scopeName : this.scopeName);
136116
}
137117

@@ -142,17 +122,17 @@ public PersistenceExceptionTranslator getExceptionTranslator() {
142122

143123
@Override
144124
public void close() {
145-
cluster.block().disconnect();
125+
cluster.disconnect();
146126
}
147127

148128
@Override
149-
public Mono<ReactiveCouchbaseResourceHolder> getTransactionResources(TransactionOptions options) {
150-
return Mono.just(new ReactiveCouchbaseResourceHolder(null));
129+
public Mono<ReactiveCouchbaseResourceHolder> getResourceHolderMono() {
130+
return Mono.just(new ReactiveCouchbaseResourceHolder(null));
151131
}
152132

153133
@Override
154-
public ReactiveCouchbaseResourceHolder getTransactionResources(TransactionOptions options,
155-
CoreTransactionAttemptContext atr) {
134+
public ReactiveCouchbaseResourceHolder getResourceHolder(TransactionOptions options,
135+
CoreTransactionAttemptContext atr) {
156136
if (atr == null) {
157137
atr = AttemptContextReactiveAccessor
158138
.newCoreTranactionAttemptContext(AttemptContextReactiveAccessor.reactive(transactions));
@@ -177,7 +157,7 @@ public CouchbaseTransactionalOperator getTransactionalOperator() {
177157

178158
@Override
179159
public ReactiveCouchbaseClientFactory with(CouchbaseTransactionalOperator txOp) {
180-
return new SimpleReactiveCouchbaseClientFactory((Cluster) getCluster().block(), bucketName, scopeName, txOp);
160+
return new SimpleReactiveCouchbaseClientFactory((Cluster) getCluster(), bucketName, scopeName, txOp);
181161
}
182162

183163
private <T> T createProxyInstance(ReactiveCouchbaseResourceHolder session, T target, Class<T> targetType) {
@@ -213,56 +193,37 @@ static final class CoreTransactionAttemptContextBoundCouchbaseClientFactory
213193

214194
private final ReactiveCouchbaseResourceHolder transactionResources;
215195
private final ReactiveCouchbaseClientFactory delegate;
216-
// private final Transactions transactions;
217196

218197
CoreTransactionAttemptContextBoundCouchbaseClientFactory(ReactiveCouchbaseResourceHolder transactionResources,
219-
ReactiveCouchbaseClientFactory delegate, Transactions transactions) {
198+
ReactiveCouchbaseClientFactory delegate, Transactions transactions) {
220199
this.transactionResources = transactionResources;
221200
this.delegate = delegate;
222-
// this.transactions = transactions;
223201
}
224202

225-
/*
226-
* (non-Javadoc)
227-
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#getMongoDatabase()
228-
*/
229-
@Override
230-
public Mono<ClusterInterface> getCluster() throws DataAccessException {
231-
return delegate.getCluster().map(this::decorateDatabase);
232-
}
233203

234204
@Override
235-
public ClusterInterface getBlockingCluster() throws DataAccessException {
236-
return decorateDatabase(delegate.getBlockingCluster());
205+
public ClusterInterface getCluster() throws DataAccessException {
206+
return decorateDatabase(delegate.getCluster());
237207
}
238208

239209
@Override
240-
public Mono<Bucket> getBucket() {
241-
return delegate.getBucket();
210+
public Mono<Collection> getCollectionMono(String name) {
211+
return Mono.just(delegate.getCollection(name));
242212
}
243213

244214
@Override
245-
public Mono<Scope> getScope() {
246-
return delegate.getScope();
215+
public Collection getCollection(String collectionName) {
216+
return delegate.getCollection(collectionName);
247217
}
248218

249219
@Override
250-
public Mono<Collection> getCollection(String name) {
251-
return delegate.getCollection(name);
220+
public Scope getScope(String scopeName) {
221+
return delegate.getScope(scopeName);
252222
}
253223

254224
@Override
255-
public Collection getBlockingCollection(String collectionName) {
256-
return delegate.getBlockingCollection(collectionName);
257-
}
258-
259-
@Override
260-
public Scope getBlockingScope(String scopeName) {
261-
return delegate.getBlockingScope(scopeName);
262-
}
263-
@Override
264-
public Mono<Collection> getDefaultCollection() {
265-
return delegate.getDefaultCollection();
225+
public Scope getScope() {
226+
return delegate.getScope();
266227
}
267228

268229
@Override
@@ -300,14 +261,14 @@ public void close() throws IOException {
300261
*/
301262

302263
@Override
303-
public Mono<ReactiveCouchbaseResourceHolder> getTransactionResources(TransactionOptions options) {
264+
public Mono<ReactiveCouchbaseResourceHolder> getResourceHolderMono() {
304265
return Mono.just(transactionResources);
305266
}
306267

307268
@Override
308-
public ReactiveCouchbaseResourceHolder getTransactionResources(TransactionOptions options,
309-
CoreTransactionAttemptContext atr) {
310-
ReactiveCouchbaseResourceHolder holder = delegate.getTransactionResources(options, atr);
269+
public ReactiveCouchbaseResourceHolder getResourceHolder(TransactionOptions options,
270+
CoreTransactionAttemptContext atr) {
271+
ReactiveCouchbaseResourceHolder holder = delegate.getResourceHolder(options, atr);
311272
return holder;
312273
}
313274

@@ -364,10 +325,6 @@ private <T> T createProxyInstance(ReactiveCouchbaseResourceHolder session, T tar
364325
return targetType.cast(factory.getProxy(target.getClass().getClassLoader()));
365326
}
366327

367-
public ReactiveCouchbaseResourceHolder getTransactionResources() {
368-
return this.transactionResources;
369-
}
370-
371328
public ReactiveCouchbaseClientFactory getDelegate() {
372329
return this.delegate;
373330
}
@@ -396,7 +353,7 @@ public int hashCode() {
396353

397354
public String toString() {
398355
return "SimpleReactiveCouchbaseDatabaseFactory.CoreTransactionAttemptContextBoundCouchDbFactory(session="
399-
+ this.getTransactionResources() + ", delegate=" + this.getDelegate() + ")";
356+
+ this.getResourceHolderMono() + ", delegate=" + this.getDelegate() + ")";
400357
}
401358
}
402359
}

0 commit comments

Comments
 (0)