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
}
@@ -177,24 +178,13 @@ public CouchbaseTemplate couchbaseTemplate(CouchbaseClientFactory couchbaseClien
177
178
getDefaultConsistency ());
178
179
}
179
180
180
- public CouchbaseTemplate couchbaseTemplate (CouchbaseClientFactory couchbaseClientFactory ,
181
- MappingCouchbaseConverter mappingCouchbaseConverter ) {
182
- return couchbaseTemplate (couchbaseClientFactory , mappingCouchbaseConverter , new JacksonTranslationService ());
183
- }
184
-
185
181
@ Bean (name = BeanNames .REACTIVE_COUCHBASE_TEMPLATE )
186
182
public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate (CouchbaseClientFactory couchbaseClientFactory ,
187
183
MappingCouchbaseConverter mappingCouchbaseConverter , TranslationService couchbaseTranslationService ) {
188
184
return new ReactiveCouchbaseTemplate (couchbaseClientFactory , mappingCouchbaseConverter , couchbaseTranslationService ,
189
185
getDefaultConsistency ());
190
186
}
191
187
192
- public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate (CouchbaseClientFactory couchbaseClientFactory ,
193
- MappingCouchbaseConverter mappingCouchbaseConverter ) {
194
- return reactiveCouchbaseTemplate (couchbaseClientFactory , mappingCouchbaseConverter ,
195
- new JacksonTranslationService ());
196
- }
197
-
198
188
@ Bean (name = BeanNames .COUCHBASE_OPERATIONS_MAPPING )
199
189
public RepositoryOperationsMapping couchbaseRepositoryOperationsMapping (CouchbaseTemplate couchbaseTemplate ) {
200
190
// create a base mapping that associates all repositories to the default template
@@ -288,7 +278,7 @@ public MappingCouchbaseConverter mappingCouchbaseConverter(CouchbaseMappingConte
288
278
@ Bean
289
279
public TranslationService couchbaseTranslationService () {
290
280
final JacksonTranslationService jacksonTranslationService = new JacksonTranslationService ();
291
- jacksonTranslationService .setObjectMapper (couchbaseObjectMapper ( cryptoManager () ));
281
+ jacksonTranslationService .setObjectMapper (getCouchbaseObjectMapper ( ));
292
282
jacksonTranslationService .afterPropertiesSet ();
293
283
// for sdk3, we need to ask the mapper _it_ uses to ignore extra fields...
294
284
JacksonTransformers .MAPPER .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
@@ -309,35 +299,27 @@ public CouchbaseMappingContext couchbaseMappingContext(CustomConversions customC
309
299
return mappingContext ;
310
300
}
311
301
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 ());
302
+
303
+ private ObjectMapper getCouchbaseObjectMapper () {
304
+ if (mapper != null ) {
305
+ return mapper ;
306
+ }
307
+ return mapper = couchbaseObjectMapper ();
319
308
}
320
309
321
310
/**
322
311
* Creates a {@link ObjectMapper} for the jsonSerializer of the ClusterEnvironment
323
312
*
324
- * @param cryptoManager
325
313
* @return ObjectMapper
326
314
*/
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 ));
315
+ public ObjectMapper couchbaseObjectMapper () {
316
+ ObjectMapper om = new ObjectMapper (); // or use the one from the Java SDK (?) JacksonTransformers.MAPPER
317
+ om .configure (com .fasterxml .jackson .databind .DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
318
+ om .registerModule (new JsonValueModule ());
319
+ if (getCryptoManager () != null ) {
320
+ om .registerModule (new EncryptionModule (getCryptoManager ()));
339
321
}
340
- return mapper ;
322
+ return om ;
341
323
}
342
324
343
325
/**
@@ -405,7 +387,7 @@ protected boolean autoIndexCreation() {
405
387
*/
406
388
@ Bean (name = BeanNames .COUCHBASE_CUSTOM_CONVERSIONS )
407
389
public CustomConversions customConversions () {
408
- return customConversions (cryptoManager ());
390
+ return customConversions (getCryptoManager ());
409
391
}
410
392
411
393
/**
@@ -428,14 +410,18 @@ public CustomConversions customConversions(CryptoManager cryptoManager) {
428
410
return customConversions ;
429
411
}
430
412
431
- @ Bean
432
- protected CryptoManager cryptoManager () {
433
- return null ;
413
+ /**
414
+ * cryptoManager can be null, so it cannot be a bean and then used as an arg for bean methods
415
+ */
416
+ private CryptoManager getCryptoManager () {
417
+ if (cryptoManager == null ){
418
+ cryptoManager = cryptoManager ();
419
+ }
420
+ return cryptoManager ;
434
421
}
435
422
436
- @ Bean
437
- protected CryptoConverter cryptoConverter (CryptoManager cryptoManager ) {
438
- return cryptoManager == null ? null : new CryptoConverter (cryptoManager );
423
+ protected CryptoManager cryptoManager () {
424
+ return null ;
439
425
}
440
426
441
427
/**
0 commit comments