Skip to content

Commit 1329cae

Browse files
authored
DATACOUCH-652 - Inject translation service bean in CouchbaseTemplateSupport. (#294)
1 parent ad55516 commit 1329cae

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* @author Simon Baslé
6363
* @author Stephane Nicoll
6464
* @author Subhashni Balakrishnan
65+
* @author Jorge Rodriguez Martin
6566
*/
6667
@Configuration
6768
public abstract class AbstractCouchbaseConfiguration {
@@ -145,15 +146,27 @@ protected void configureEnvironment(final ClusterEnvironment.Builder builder) {
145146
}
146147

147148
@Bean(name = BeanNames.COUCHBASE_TEMPLATE)
149+
public CouchbaseTemplate couchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
150+
MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) {
151+
return new CouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter, couchbaseTranslationService);
152+
}
153+
148154
public CouchbaseTemplate couchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
149155
MappingCouchbaseConverter mappingCouchbaseConverter) {
150-
return new CouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter);
156+
return couchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter, new JacksonTranslationService());
151157
}
152158

153159
@Bean(name = BeanNames.REACTIVE_COUCHBASE_TEMPLATE)
160+
public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
161+
MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) {
162+
return new ReactiveCouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter,
163+
couchbaseTranslationService);
164+
}
165+
154166
public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
155167
MappingCouchbaseConverter mappingCouchbaseConverter) {
156-
return new ReactiveCouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter);
168+
return reactiveCouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter,
169+
new JacksonTranslationService());
157170
}
158171

159172
@Bean(name = BeanNames.COUCHBASE_OPERATIONS_MAPPING)

src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplate.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.springframework.context.ApplicationContextAware;
2222
import org.springframework.data.couchbase.CouchbaseClientFactory;
2323
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
24+
import org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService;
25+
import org.springframework.data.couchbase.core.convert.translation.TranslationService;
2426

2527
import com.couchbase.client.java.Collection;
2628

@@ -30,6 +32,7 @@
3032
* @author Michael Nitschinger
3133
* @author Michael Reiche
3234
* @author Aaron Whiteside
35+
* @author Jorge Rodriguez Martin
3336
* @since 3.0
3437
*/
3538
public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContextAware {
@@ -40,10 +43,15 @@ public class CouchbaseTemplate implements CouchbaseOperations, ApplicationContex
4043
private final ReactiveCouchbaseTemplate reactiveCouchbaseTemplate;
4144

4245
public CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final CouchbaseConverter converter) {
46+
this(clientFactory, converter, new JacksonTranslationService());
47+
}
48+
49+
public CouchbaseTemplate(final CouchbaseClientFactory clientFactory, final CouchbaseConverter converter,
50+
final TranslationService translationService) {
4351
this.clientFactory = clientFactory;
4452
this.converter = converter;
45-
this.templateSupport = new CouchbaseTemplateSupport(converter);
46-
this.reactiveCouchbaseTemplate = new ReactiveCouchbaseTemplate(clientFactory, converter);
53+
this.templateSupport = new CouchbaseTemplateSupport(converter, translationService);
54+
this.reactiveCouchbaseTemplate = new ReactiveCouchbaseTemplate(clientFactory, converter, translationService);
4755
}
4856

4957
@Override

src/main/java/org/springframework/data/couchbase/core/CouchbaseTemplateSupport.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
package org.springframework.data.couchbase.core;
1818

19-
import org.slf4j.Logger;
20-
import org.slf4j.LoggerFactory;
2119
import org.springframework.beans.BeansException;
2220
import org.springframework.context.ApplicationContext;
2321
import org.springframework.context.ApplicationContextAware;
2422
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
25-
import org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService;
2623
import org.springframework.data.couchbase.core.convert.translation.TranslationService;
2724
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
2825
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
@@ -39,11 +36,15 @@
3936
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
4037
import org.springframework.util.Assert;
4138

39+
import org.slf4j.Logger;
40+
import org.slf4j.LoggerFactory;
41+
4242
/**
4343
* Internal encode/decode support for CouchbaseTemplate.
4444
*
4545
* @author Michael Nitschinger
4646
* @author Michael Reiche
47+
* @author Jorge Rodriguez Martin
4748
* @since 3.0
4849
*/
4950
class CouchbaseTemplateSupport implements ApplicationContextAware {
@@ -56,10 +57,10 @@ class CouchbaseTemplateSupport implements ApplicationContextAware {
5657
private EntityCallbacks entityCallbacks;
5758
private ApplicationContext applicationContext;
5859

59-
public CouchbaseTemplateSupport(final CouchbaseConverter converter) {
60+
public CouchbaseTemplateSupport(final CouchbaseConverter converter, final TranslationService translationService) {
6061
this.converter = converter;
6162
this.mappingContext = converter.getMappingContext();
62-
this.translationService = new JacksonTranslationService();
63+
this.translationService = translationService;
6364
}
6465

6566
public CouchbaseDocument encodeEntity(final Object entityToEncode) {

src/main/java/org/springframework/data/couchbase/core/ReactiveCouchbaseTemplate.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.springframework.dao.support.PersistenceExceptionTranslator;
2424
import org.springframework.data.couchbase.CouchbaseClientFactory;
2525
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
26+
import org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService;
27+
import org.springframework.data.couchbase.core.convert.translation.TranslationService;
2628

2729
import com.couchbase.client.java.Collection;
2830

@@ -31,6 +33,7 @@
3133
*
3234
* @author Michael Nitschinger
3335
* @author Michael Reiche
36+
* @author Jorge Rodriguez Martin
3437
*/
3538
public class ReactiveCouchbaseTemplate implements ReactiveCouchbaseOperations, ApplicationContextAware {
3639

@@ -40,10 +43,15 @@ public class ReactiveCouchbaseTemplate implements ReactiveCouchbaseOperations, A
4043
private final CouchbaseTemplateSupport templateSupport;
4144

4245
public ReactiveCouchbaseTemplate(final CouchbaseClientFactory clientFactory, final CouchbaseConverter converter) {
46+
this(clientFactory, converter, new JacksonTranslationService());
47+
}
48+
49+
public ReactiveCouchbaseTemplate(final CouchbaseClientFactory clientFactory, final CouchbaseConverter converter,
50+
final TranslationService translationService) {
4351
this.clientFactory = clientFactory;
4452
this.converter = converter;
4553
this.exceptionTranslator = clientFactory.getExceptionTranslator();
46-
this.templateSupport = new CouchbaseTemplateSupport(converter);
54+
this.templateSupport = new CouchbaseTemplateSupport(converter, translationService);
4755
}
4856

4957
@Override

src/test/java/org/springframework/data/couchbase/domain/Config.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
/**
4444
* @author Michael Nitschinger
4545
* @author Michael Reiche
46+
* @author Jorge Rodriguez Martin
4647
* @since 3.0
4748
*/
4849
@Configuration

0 commit comments

Comments
 (0)