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.
This commit is contained in:
Michael Nitschinger
2020-03-09 09:37:11 +01:00
parent cf67ab44cc
commit 1ee0045f0e
3 changed files with 23 additions and 8 deletions

View File

@@ -50,7 +50,7 @@ public class SimpleCouchbaseClientFactory implements CouchbaseClientFactory {
this(Cluster.connect(connectionString, ClusterOptions.clusterOptions(authenticator).environment(environment)), bucketName, scopeName);
}
SimpleCouchbaseClientFactory(final Cluster cluster, final String bucketName, final String scopeName) {
public SimpleCouchbaseClientFactory(final Cluster cluster, final String bucketName, final String scopeName) {
this.cluster = cluster;
this.bucket = cluster.bucket(bucketName);
this.scope = scopeName == null ? bucket.defaultScope() : bucket.scope(scopeName);

View File

@@ -20,6 +20,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.ClusterOptions;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
@@ -50,6 +52,8 @@ import com.couchbase.client.core.env.PasswordAuthenticator;
import com.couchbase.client.java.env.ClusterEnvironment;
import com.couchbase.client.java.json.JacksonTransformers;
import static com.couchbase.client.java.ClusterOptions.*;
/**
* Base class for Spring Data Couchbase configuration using JavaConfig.
*
@@ -61,6 +65,10 @@ import com.couchbase.client.java.json.JacksonTransformers;
@Configuration
public abstract class AbstractCouchbaseConfiguration implements CouchbaseConfigurer {
protected CouchbaseConfigurer couchbaseConfigurer() {
return this;
}
public abstract String getConnectionString();
public abstract String getUserName();
@@ -78,10 +86,17 @@ public abstract class AbstractCouchbaseConfiguration implements CouchbaseConfigu
}
@Bean
public CouchbaseClientFactory couchbaseClientFactory(Cluster couchbaseCluster) {
return new SimpleCouchbaseClientFactory(couchbaseCluster, getBucketName(), getScopeName());
}
@Override
public CouchbaseClientFactory couchbaseClientFactory(ClusterEnvironment clusterEnvironment) {
return new SimpleCouchbaseClientFactory(getConnectionString(), authenticator(), getBucketName(),
getScopeName(), clusterEnvironment);
@Bean
public Cluster couchbaseCluster() throws Exception {
return Cluster.connect(
getConnectionString(),
clusterOptions(authenticator()).environment(couchbaseConfigurer().clusterEnvironment())
);
}
@Override

View File

@@ -16,8 +16,8 @@
package org.springframework.data.couchbase.config;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.env.ClusterEnvironment;
import org.springframework.data.couchbase.CouchbaseClientFactory;
/**
* Strategy interface for users to provide as a factory for custom components needed
@@ -38,11 +38,11 @@ public interface CouchbaseConfigurer {
ClusterEnvironment clusterEnvironment() throws Exception;
/**
* Set up the underlying main {@link CouchbaseClientFactory} reference to be used by the Spring Data framework
* Set up the underlying main {@link Cluster} reference to be used by the Spring Data framework
* when storing into Couchbase.
*
* @throws Exception in case of error during the CouchbaseClientFactory instantiation.
* @throws Exception in case of error during the Cluster instantiation.
*/
CouchbaseClientFactory couchbaseClientFactory(ClusterEnvironment clusterEnvironment) throws Exception;
Cluster couchbaseCluster() throws Exception;
}