22
22
import org .springframework .data .couchbase .transaction .SessionAwareMethodInterceptor ;
23
23
import org .springframework .util .ObjectUtils ;
24
24
25
- import com .couchbase .client .java .Bucket ;
26
25
import com .couchbase .client .java .Cluster ;
27
26
import com .couchbase .client .java .Collection ;
28
27
import com .couchbase .client .java .Scope ;
29
28
30
29
public class SimpleReactiveCouchbaseClientFactory implements ReactiveCouchbaseClientFactory {
31
- final Mono <ClusterInterface > cluster ;
32
- final ClusterInterface theCluster ;
30
+ final ClusterInterface cluster ;
33
31
final String bucketName ;
34
32
final String scopeName ;
35
33
final PersistenceExceptionTranslator exceptionTranslator ;
@@ -38,9 +36,8 @@ public class SimpleReactiveCouchbaseClientFactory implements ReactiveCouchbaseCl
38
36
CouchbaseTransactionalOperator transactionalOperator ;
39
37
40
38
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 ;
44
41
this .bucketName = bucketName ;
45
42
this .scopeName = scopeName ;
46
43
this .exceptionTranslator = new CouchbaseExceptionTranslator ();
@@ -53,20 +50,10 @@ public SimpleReactiveCouchbaseClientFactory(Cluster cluster, String bucketName,
53
50
this (cluster , bucketName , scopeName , null );
54
51
}
55
52
56
- @ Override
57
- public Mono <ClusterInterface > getCluster () {
58
- return cluster ;
59
- }
60
-
61
-
62
- @ Override
63
- public ClusterInterface getBlockingCluster () {
64
- return theCluster ;
65
- }
66
53
67
54
@ Override
68
- public Mono < Bucket > getBucket () {
69
- return cluster . map (( c ) -> c . bucket ( bucketName )) ;
55
+ public ClusterInterface getCluster () {
56
+ return cluster ;
70
57
}
71
58
72
59
@ Override
@@ -75,13 +62,13 @@ public String getBucketName() {
75
62
}
76
63
77
64
@ 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 ));
80
68
}
81
69
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 );
85
72
}
86
73
87
74
@ Override
@@ -90,7 +77,7 @@ public String getScopeName() {
90
77
}
91
78
92
79
@ Override
93
- public Mono <Collection > getCollection (String collectionName ) {
80
+ public Mono <Collection > getCollectionMono (String collectionName ) {
94
81
if (getScopeName () != null && !DEFAULT_SCOPE .equals (getScopeName ())) {
95
82
if (collectionName == null || DEFAULT_COLLECTION .equals (collectionName )) {
96
83
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) {
102
89
"A collectionName must be null or " + DEFAULT_COLLECTION + " if scope is null or " + DEFAULT_SCOPE );
103
90
}
104
91
}
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 ));
106
93
}
107
94
108
95
@ Override
109
- public Collection getBlockingCollection (String collectionName ) {
96
+ public Collection getCollection (String collectionName ) {
110
97
if (getScopeName () != null && !DEFAULT_SCOPE .equals (getScopeName ())) {
111
98
if (collectionName == null || DEFAULT_COLLECTION .equals (collectionName )) {
112
99
throw new IllegalStateException ("A collectionName must be provided if a non-default scope is used." );
@@ -118,20 +105,13 @@ public Collection getBlockingCollection(String collectionName) {
118
105
"A collectionName must be null or " + DEFAULT_COLLECTION + " if scope is null or " + DEFAULT_SCOPE );
119
106
}
120
107
}
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 );
130
110
}
131
111
132
112
@ Override
133
113
public ReactiveCouchbaseClientFactory withScope (String scopeName ) {
134
- return new SimpleReactiveCouchbaseClientFactory ((Cluster ) cluster . block () , bucketName ,
114
+ return new SimpleReactiveCouchbaseClientFactory ((Cluster ) cluster , bucketName ,
135
115
scopeName != null ? scopeName : this .scopeName );
136
116
}
137
117
@@ -142,17 +122,17 @@ public PersistenceExceptionTranslator getExceptionTranslator() {
142
122
143
123
@ Override
144
124
public void close () {
145
- cluster .block (). disconnect ();
125
+ cluster .disconnect ();
146
126
}
147
127
148
128
@ 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 ));
151
131
}
152
132
153
133
@ Override
154
- public ReactiveCouchbaseResourceHolder getTransactionResources (TransactionOptions options ,
155
- CoreTransactionAttemptContext atr ) {
134
+ public ReactiveCouchbaseResourceHolder getResourceHolder (TransactionOptions options ,
135
+ CoreTransactionAttemptContext atr ) {
156
136
if (atr == null ) {
157
137
atr = AttemptContextReactiveAccessor
158
138
.newCoreTranactionAttemptContext (AttemptContextReactiveAccessor .reactive (transactions ));
@@ -177,7 +157,7 @@ public CouchbaseTransactionalOperator getTransactionalOperator() {
177
157
178
158
@ Override
179
159
public ReactiveCouchbaseClientFactory with (CouchbaseTransactionalOperator txOp ) {
180
- return new SimpleReactiveCouchbaseClientFactory ((Cluster ) getCluster (). block () , bucketName , scopeName , txOp );
160
+ return new SimpleReactiveCouchbaseClientFactory ((Cluster ) getCluster (), bucketName , scopeName , txOp );
181
161
}
182
162
183
163
private <T > T createProxyInstance (ReactiveCouchbaseResourceHolder session , T target , Class <T > targetType ) {
@@ -213,56 +193,37 @@ static final class CoreTransactionAttemptContextBoundCouchbaseClientFactory
213
193
214
194
private final ReactiveCouchbaseResourceHolder transactionResources ;
215
195
private final ReactiveCouchbaseClientFactory delegate ;
216
- // private final Transactions transactions;
217
196
218
197
CoreTransactionAttemptContextBoundCouchbaseClientFactory (ReactiveCouchbaseResourceHolder transactionResources ,
219
- ReactiveCouchbaseClientFactory delegate , Transactions transactions ) {
198
+ ReactiveCouchbaseClientFactory delegate , Transactions transactions ) {
220
199
this .transactionResources = transactionResources ;
221
200
this .delegate = delegate ;
222
- // this.transactions = transactions;
223
201
}
224
202
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
- }
233
203
234
204
@ Override
235
- public ClusterInterface getBlockingCluster () throws DataAccessException {
236
- return decorateDatabase (delegate .getBlockingCluster ());
205
+ public ClusterInterface getCluster () throws DataAccessException {
206
+ return decorateDatabase (delegate .getCluster ());
237
207
}
238
208
239
209
@ Override
240
- public Mono <Bucket > getBucket ( ) {
241
- return delegate .getBucket ( );
210
+ public Mono <Collection > getCollectionMono ( String name ) {
211
+ return Mono . just ( delegate .getCollection ( name ) );
242
212
}
243
213
244
214
@ Override
245
- public Mono < Scope > getScope ( ) {
246
- return delegate .getScope ( );
215
+ public Collection getCollection ( String collectionName ) {
216
+ return delegate .getCollection ( collectionName );
247
217
}
248
218
249
219
@ Override
250
- public Mono < Collection > getCollection (String name ) {
251
- return delegate .getCollection ( name );
220
+ public Scope getScope (String scopeName ) {
221
+ return delegate .getScope ( scopeName );
252
222
}
253
223
254
224
@ 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 ();
266
227
}
267
228
268
229
@ Override
@@ -300,14 +261,14 @@ public void close() throws IOException {
300
261
*/
301
262
302
263
@ Override
303
- public Mono <ReactiveCouchbaseResourceHolder > getTransactionResources ( TransactionOptions options ) {
264
+ public Mono <ReactiveCouchbaseResourceHolder > getResourceHolderMono ( ) {
304
265
return Mono .just (transactionResources );
305
266
}
306
267
307
268
@ 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 );
311
272
return holder ;
312
273
}
313
274
@@ -364,10 +325,6 @@ private <T> T createProxyInstance(ReactiveCouchbaseResourceHolder session, T tar
364
325
return targetType .cast (factory .getProxy (target .getClass ().getClassLoader ()));
365
326
}
366
327
367
- public ReactiveCouchbaseResourceHolder getTransactionResources () {
368
- return this .transactionResources ;
369
- }
370
-
371
328
public ReactiveCouchbaseClientFactory getDelegate () {
372
329
return this .delegate ;
373
330
}
@@ -396,7 +353,7 @@ public int hashCode() {
396
353
397
354
public String toString () {
398
355
return "SimpleReactiveCouchbaseDatabaseFactory.CoreTransactionAttemptContextBoundCouchDbFactory(session="
399
- + this .getTransactionResources () + ", delegate=" + this .getDelegate () + ")" ;
356
+ + this .getResourceHolderMono () + ", delegate=" + this .getDelegate () + ")" ;
400
357
}
401
358
}
402
359
}
0 commit comments