Skip to content

Commit 58c3aa3

Browse files
committed
Add doc for multiple buckets and heading for overriding SDK.
Closes #878, #1788.
1 parent df547a0 commit 58c3aa3

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/main/asciidoc/configuration.adoc

+60-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This chapter describes the common installation and configuration steps needed wh
99
All versions intended for production use are distributed across Maven Central and the Spring release repository.
1010
As a result, the library can be included like any other maven dependency:
1111

12+
== Configuration
1213
.Including the dependency through maven
1314
====
1415
[source,xml,subs="+attributes"]
@@ -26,6 +27,8 @@ This will pull in several dependencies, including the underlying Couchbase Java
2627
You can also grab snapshots from the https://repo.spring.io/ui/repos/tree/General/snapshot/org/springframework/data/spring-data-couchbase[spring snapshot repository] ( \https://repo.spring.io/snapshot ) and milestone releases from the https://repo.spring.io/ui/repos/tree/General/milestone/org/springframework/data/spring-data-couchbase[spring milestone repository] ( \https://repo.spring.io/milestone ).
2728
Here is an example on how to use the current SNAPSHOT dependency:
2829

30+
== Snapshot Configuration
31+
2932
.Using a snapshot version
3033
====
3134
[source,xml]
@@ -44,7 +47,7 @@ Here is an example on how to use the current SNAPSHOT dependency:
4447
----
4548
====
4649

47-
.Overriding the Couchbase SDK Version
50+
== Overriding the Couchbase SDK Version
4851

4952
Some users may wish to use a Couchbase Java SDK version different from the one referenced in a Spring Data Couchbase release for the purpose of obtaining bug and vulnerability fixes. Since Couchbase Java SDK minor version releases are backwards compatible, this version of Spring Data Couchbase is compatible and supported with any 3.x version of the Couchbase Java SDK newer than the one specified in the release dependencies. To change the Couchbase Java SDK version used by Spring Data Couchbase, simply override the dependency in the application pom.xml as follows:
5053

@@ -165,3 +168,59 @@ If you start your application, you should see Couchbase INFO level logging in th
165168
Couchbase Java SDK is connecting to the database. If any errors are reported, make sure that the given credentials
166169
and host information are correct.
167170

171+
172+
== Configuring Multiple Buckets
173+
174+
To leverage multi-bucket repositories, implement the methods below in your Config class. The config*OperationsMapping methods configure the mapping of entity-objects to buckets. Be careful with the method names - using a method name that is a Bean will result in the value of that bean being used instead of the result of the method.
175+
176+
This example maps Person -> protected, User -> mybucket, and everything else goes to getBucketName(). Note that this only maps calls through the Repository.
177+
178+
====
179+
[source,java]
180+
----
181+
@Override
182+
public void configureReactiveRepositoryOperationsMapping(ReactiveRepositoryOperationsMapping baseMapping) {
183+
try {
184+
ReactiveCouchbaseTemplate personTemplate = myReactiveCouchbaseTemplate(myCouchbaseClientFactory("protected"),new MappingCouchbaseConverter());
185+
baseMapping.mapEntity(Person.class, personTemplate); // Person goes in "protected" bucket
186+
ReactiveCouchbaseTemplate userTemplate = myReactiveCouchbaseTemplate(myCouchbaseClientFactory("mybucket"),new MappingCouchbaseConverter());
187+
baseMapping.mapEntity(User.class, userTemplate); // User goes in "mybucket"
188+
// everything else goes in getBucketName()
189+
} catch (Exception e) {
190+
throw e;
191+
}
192+
}
193+
@Override
194+
public void configureRepositoryOperationsMapping(RepositoryOperationsMapping baseMapping) {
195+
try {
196+
CouchbaseTemplate personTemplate = myCouchbaseTemplate(myCouchbaseClientFactory("protected"),new MappingCouchbaseConverter());
197+
baseMapping.mapEntity(Person.class, personTemplate); // Person goes in "protected" bucket
198+
CouchbaseTemplate userTemplate = myCouchbaseTemplate(myCouchbaseClientFactory("mybucket"),new MappingCouchbaseConverter());
199+
baseMapping.mapEntity(User.class, userTemplate); // User goes in "mybucket"
200+
// everything else goes in getBucketName()
201+
} catch (Exception e) {
202+
throw e;
203+
}
204+
}
205+
206+
// do not use reactiveCouchbaseTemplate for the name of this method, otherwise the value of that bean
207+
// will be used instead of the result of this call (the client factory arg is different)
208+
public ReactiveCouchbaseTemplate myReactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
209+
MappingCouchbaseConverter mappingCouchbaseConverter) {
210+
return new ReactiveCouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter);
211+
}
212+
213+
// do not use couchbaseTemplate for the name of this method, otherwise the value of that been
214+
// will be used instead of the result from this call (the client factory arg is different)
215+
public CouchbaseTemplate myCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
216+
MappingCouchbaseConverter mappingCouchbaseConverter) {
217+
return new CouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter);
218+
}
219+
220+
// do not use couchbaseClientFactory for the name of this method, otherwise the value of that bean will
221+
// will be used instead of this call being made ( bucketname is an arg here, instead of using bucketName() )
222+
public CouchbaseClientFactory myCouchbaseClientFactory(String bucketName) {
223+
return new SimpleCouchbaseClientFactory(getConnectionString(),authenticator(), bucketName );
224+
}
225+
----
226+
====

0 commit comments

Comments
 (0)