Skip to content

Commit 1ee0045

Browse files
committed
DATACOUCH-509 - Expose only SDK related infos on configurer
Since the client factory is a spring data concept, it cannot be exposed on the configurer. Only expose the cluster and the environment on it. This also modifies the config to populate the right beans from the configurer methods as well.
1 parent cf67ab4 commit 1ee0045

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/main/java/org/springframework/data/couchbase/SimpleCouchbaseClientFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public SimpleCouchbaseClientFactory(final String connectionString, final Authent
5050
this(Cluster.connect(connectionString, ClusterOptions.clusterOptions(authenticator).environment(environment)), bucketName, scopeName);
5151
}
5252

53-
SimpleCouchbaseClientFactory(final Cluster cluster, final String bucketName, final String scopeName) {
53+
public SimpleCouchbaseClientFactory(final Cluster cluster, final String bucketName, final String scopeName) {
5454
this.cluster = cluster;
5555
this.bucket = cluster.bucket(bucketName);
5656
this.scope = scopeName == null ? bucket.defaultScope() : bucket.scope(scopeName);

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.HashSet;
2121
import java.util.Set;
2222

23+
import com.couchbase.client.java.Cluster;
24+
import com.couchbase.client.java.ClusterOptions;
2325
import org.springframework.beans.factory.config.BeanDefinition;
2426
import org.springframework.context.annotation.Bean;
2527
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
@@ -50,6 +52,8 @@
5052
import com.couchbase.client.java.env.ClusterEnvironment;
5153
import com.couchbase.client.java.json.JacksonTransformers;
5254

55+
import static com.couchbase.client.java.ClusterOptions.*;
56+
5357
/**
5458
* Base class for Spring Data Couchbase configuration using JavaConfig.
5559
*
@@ -61,6 +65,10 @@
6165
@Configuration
6266
public abstract class AbstractCouchbaseConfiguration implements CouchbaseConfigurer {
6367

68+
protected CouchbaseConfigurer couchbaseConfigurer() {
69+
return this;
70+
}
71+
6472
public abstract String getConnectionString();
6573

6674
public abstract String getUserName();
@@ -78,10 +86,17 @@ protected Authenticator authenticator() {
7886
}
7987

8088
@Bean
89+
public CouchbaseClientFactory couchbaseClientFactory(Cluster couchbaseCluster) {
90+
return new SimpleCouchbaseClientFactory(couchbaseCluster, getBucketName(), getScopeName());
91+
}
92+
8193
@Override
82-
public CouchbaseClientFactory couchbaseClientFactory(ClusterEnvironment clusterEnvironment) {
83-
return new SimpleCouchbaseClientFactory(getConnectionString(), authenticator(), getBucketName(),
84-
getScopeName(), clusterEnvironment);
94+
@Bean
95+
public Cluster couchbaseCluster() throws Exception {
96+
return Cluster.connect(
97+
getConnectionString(),
98+
clusterOptions(authenticator()).environment(couchbaseConfigurer().clusterEnvironment())
99+
);
85100
}
86101

87102
@Override

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

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

19+
import com.couchbase.client.java.Cluster;
1920
import com.couchbase.client.java.env.ClusterEnvironment;
20-
import org.springframework.data.couchbase.CouchbaseClientFactory;
2121

2222
/**
2323
* Strategy interface for users to provide as a factory for custom components needed
@@ -38,11 +38,11 @@ public interface CouchbaseConfigurer {
3838
ClusterEnvironment clusterEnvironment() throws Exception;
3939

4040
/**
41-
* Set up the underlying main {@link CouchbaseClientFactory} reference to be used by the Spring Data framework
41+
* Set up the underlying main {@link Cluster} reference to be used by the Spring Data framework
4242
* when storing into Couchbase.
4343
*
44-
* @throws Exception in case of error during the CouchbaseClientFactory instantiation.
44+
* @throws Exception in case of error during the Cluster instantiation.
4545
*/
46-
CouchbaseClientFactory couchbaseClientFactory(ClusterEnvironment clusterEnvironment) throws Exception;
46+
Cluster couchbaseCluster() throws Exception;
4747

4848
}

0 commit comments

Comments
 (0)