39
39
import org .springframework .data .couchbase .core .ReactiveCouchbaseTemplate ;
40
40
import org .springframework .data .couchbase .core .convert .CouchbaseCustomConversions ;
41
41
import org .springframework .data .couchbase .core .convert .CouchbasePropertyValueConverterFactory ;
42
- import org .springframework .data .couchbase .core .convert .CryptoConverter ;
43
42
import org .springframework .data .couchbase .core .convert .MappingCouchbaseConverter ;
44
43
import org .springframework .data .couchbase .core .convert .translation .JacksonTranslationService ;
45
44
import org .springframework .data .couchbase .core .convert .translation .TranslationService ;
88
87
@ Configuration
89
88
public abstract class AbstractCouchbaseConfiguration {
90
89
90
+ ObjectMapper mapper ;
91
+ CryptoManager cryptoManager = null ;
92
+
91
93
/**
92
94
* The connection string which allows the SDK to connect to the cluster.
93
95
* <p>
@@ -155,9 +157,8 @@ public ClusterEnvironment couchbaseClusterEnvironment() {
155
157
if (!nonShadowedJacksonPresent ()) {
156
158
throw new CouchbaseException ("non-shadowed Jackson not present" );
157
159
}
158
- CryptoManager cryptoManager = cryptoManager ();
159
- builder .jsonSerializer (JacksonJsonSerializer .create (couchbaseObjectMapper (cryptoManager )));
160
- builder .cryptoManager (cryptoManager );
160
+ builder .jsonSerializer (JacksonJsonSerializer .create (getCouchbaseObjectMapper ()));
161
+ builder .cryptoManager (getCryptoManager ());
161
162
configureEnvironment (builder );
162
163
return builder .build ();
163
164
}
@@ -167,8 +168,7 @@ public ClusterEnvironment couchbaseClusterEnvironment() {
167
168
*
168
169
* @param builder the builder that can be customized.
169
170
*/
170
- protected void configureEnvironment (final ClusterEnvironment .Builder builder ) {
171
- }
171
+ protected void configureEnvironment (final ClusterEnvironment .Builder builder ) {}
172
172
173
173
@ Bean (name = BeanNames .COUCHBASE_TEMPLATE )
174
174
public CouchbaseTemplate couchbaseTemplate (CouchbaseClientFactory couchbaseClientFactory ,
@@ -177,6 +177,7 @@ public CouchbaseTemplate couchbaseTemplate(CouchbaseClientFactory couchbaseClien
177
177
getDefaultConsistency ());
178
178
}
179
179
180
+ @ Deprecated
180
181
public CouchbaseTemplate couchbaseTemplate (CouchbaseClientFactory couchbaseClientFactory ,
181
182
MappingCouchbaseConverter mappingCouchbaseConverter ) {
182
183
return couchbaseTemplate (couchbaseClientFactory , mappingCouchbaseConverter , new JacksonTranslationService ());
@@ -189,6 +190,7 @@ public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseClientFactor
189
190
getDefaultConsistency ());
190
191
}
191
192
193
+ @ Deprecated
192
194
public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate (CouchbaseClientFactory couchbaseClientFactory ,
193
195
MappingCouchbaseConverter mappingCouchbaseConverter ) {
194
196
return reactiveCouchbaseTemplate (couchbaseClientFactory , mappingCouchbaseConverter ,
@@ -288,7 +290,7 @@ public MappingCouchbaseConverter mappingCouchbaseConverter(CouchbaseMappingConte
288
290
@ Bean
289
291
public TranslationService couchbaseTranslationService () {
290
292
final JacksonTranslationService jacksonTranslationService = new JacksonTranslationService ();
291
- jacksonTranslationService .setObjectMapper (couchbaseObjectMapper ( cryptoManager () ));
293
+ jacksonTranslationService .setObjectMapper (getCouchbaseObjectMapper ( ));
292
294
jacksonTranslationService .afterPropertiesSet ();
293
295
// for sdk3, we need to ask the mapper _it_ uses to ignore extra fields...
294
296
JacksonTransformers .MAPPER .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
@@ -309,35 +311,26 @@ public CouchbaseMappingContext couchbaseMappingContext(CustomConversions customC
309
311
return mappingContext ;
310
312
}
311
313
312
- /**
313
- * Creates a {@link ObjectMapper} for the jsonSerializer of the ClusterEnvironment
314
- *
315
- * @return ObjectMapper
316
- */
317
- private ObjectMapper couchbaseObjectMapper () {
318
- return couchbaseObjectMapper (cryptoManager ());
314
+ private ObjectMapper getCouchbaseObjectMapper () {
315
+ if (mapper != null ) {
316
+ return mapper ;
317
+ }
318
+ return mapper = couchbaseObjectMapper ();
319
319
}
320
320
321
321
/**
322
322
* Creates a {@link ObjectMapper} for the jsonSerializer of the ClusterEnvironment
323
323
*
324
- * @param cryptoManager
325
324
* @return ObjectMapper
326
325
*/
327
-
328
- ObjectMapper mapper ;
329
-
330
- public ObjectMapper couchbaseObjectMapper (CryptoManager cryptoManager ) {
331
- if (mapper != null ) {
332
- return mapper ;
333
- }
334
- mapper = new ObjectMapper (); // or use the one from the Java SDK (?) JacksonTransformers.MAPPER
335
- mapper .configure (com .fasterxml .jackson .databind .DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
336
- mapper .registerModule (new JsonValueModule ());
337
- if (cryptoManager != null ) {
338
- mapper .registerModule (new EncryptionModule (cryptoManager ));
326
+ public ObjectMapper couchbaseObjectMapper () {
327
+ ObjectMapper om = new ObjectMapper (); // or use the one from the Java SDK (?) JacksonTransformers.MAPPER
328
+ om .configure (com .fasterxml .jackson .databind .DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
329
+ om .registerModule (new JsonValueModule ());
330
+ if (getCryptoManager () != null ) {
331
+ om .registerModule (new EncryptionModule (getCryptoManager ()));
339
332
}
340
- return mapper ;
333
+ return om ;
341
334
}
342
335
343
336
/**
@@ -405,7 +398,7 @@ protected boolean autoIndexCreation() {
405
398
*/
406
399
@ Bean (name = BeanNames .COUCHBASE_CUSTOM_CONVERSIONS )
407
400
public CustomConversions customConversions () {
408
- return customConversions (cryptoManager ());
401
+ return customConversions (getCryptoManager ());
409
402
}
410
403
411
404
/**
@@ -428,14 +421,18 @@ public CustomConversions customConversions(CryptoManager cryptoManager) {
428
421
return customConversions ;
429
422
}
430
423
431
- @ Bean
432
- protected CryptoManager cryptoManager () {
433
- return null ;
424
+ /**
425
+ * cryptoManager can be null, so it cannot be a bean and then used as an arg for bean methods
426
+ */
427
+ private CryptoManager getCryptoManager () {
428
+ if (cryptoManager == null ) {
429
+ cryptoManager = cryptoManager ();
430
+ }
431
+ return cryptoManager ;
434
432
}
435
433
436
- @ Bean
437
- protected CryptoConverter cryptoConverter (CryptoManager cryptoManager ) {
438
- return cryptoManager == null ? null : new CryptoConverter (cryptoManager );
434
+ protected CryptoManager cryptoManager () {
435
+ return null ;
439
436
}
440
437
441
438
/**
0 commit comments