DATACOUCH-509 - Restore CouchbaseConfigurer

Since boot needs it for easy mocking/testing, restoring the
configurer (but with the new corresponding beans and only
the subset that is currently available).
This commit is contained in:
Michael Nitschinger
2020-03-09 06:59:38 +01:00
parent 4abad35639
commit daf479b345
2 changed files with 59 additions and 7 deletions

View File

@@ -59,7 +59,7 @@ import com.couchbase.client.java.json.JacksonTransformers;
* @author Subhashni Balakrishnan
*/
@Configuration
public abstract class AbstractCouchbaseConfiguration {
public abstract class AbstractCouchbaseConfiguration implements CouchbaseConfigurer {
public abstract String getConnectionString();
@@ -78,13 +78,15 @@ public abstract class AbstractCouchbaseConfiguration {
}
@Bean
@Override
public CouchbaseClientFactory couchbaseClientFactory(ClusterEnvironment clusterEnvironment) {
return new SimpleCouchbaseClientFactory(getConnectionString(), authenticator(), getBucketName(),
getScopeName(), clusterEnvironment);
}
@Override
@Bean(destroyMethod = "shutdown")
protected ClusterEnvironment clusterEnvironment() {
public ClusterEnvironment clusterEnvironment() {
ClusterEnvironment.Builder builder = ClusterEnvironment.builder();
configureEnvironment(builder);
return builder.build();
@@ -149,7 +151,8 @@ public abstract class AbstractCouchbaseConfiguration {
/**
* Determines the name of the field that will store the type information for complex types when using the
* {@link #mappingCouchbaseConverter()}. Defaults to {@value MappingCouchbaseConverter#TYPEKEY_DEFAULT}.
* {@link #mappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions)}. Defaults
* to {@value MappingCouchbaseConverter#TYPEKEY_DEFAULT}.
*
* @see MappingCouchbaseConverter#TYPEKEY_DEFAULT
* @see MappingCouchbaseConverter#TYPEKEY_SYNCGATEWAY_COMPATIBLE
@@ -192,18 +195,19 @@ public abstract class AbstractCouchbaseConfiguration {
* @throws Exception on Bean construction failure.
*/
@Bean
public CouchbaseMappingContext couchbaseMappingContext() throws Exception {
public CouchbaseMappingContext couchbaseMappingContext(CustomConversions customConversions) throws Exception {
CouchbaseMappingContext mappingContext = new CouchbaseMappingContext();
mappingContext.setInitialEntitySet(getInitialEntitySet());
mappingContext.setSimpleTypeHolder(customConversions().getSimpleTypeHolder());
mappingContext.setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
mappingContext.setFieldNamingStrategy(fieldNamingStrategy());
return mappingContext;
}
/**
* Register custom Converters in a {@link CustomConversions} object if required. These {@link CustomConversions} will
* be registered with the {@link #mappingCouchbaseConverter(CouchbaseMappingContext)} )} and
* {@link #couchbaseMappingContext()}. Returns an empty {@link CustomConversions} instance by default.
* be registered with the {@link #mappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions)} )}
* and {@link #couchbaseMappingContext(CustomConversions)}. Returns an empty {@link CustomConversions} instance by
* default.
*
* @return must not be {@literal null}.
*/

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2020 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.couchbase.config;
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
* by the Couchbase integration.
*
* This allows to centralize instantiation of Couchbase SDK core elements.
*
* @author Stephane Nicoll
* @author Michael Nitschinger
*/
public interface CouchbaseConfigurer {
/**
* Set up the underlying main {@link ClusterEnvironment}, allowing tuning of the Couchbase SDK.
*
* @throws Exception in case of error during the ClusterEnvironment instantiation.
*/
ClusterEnvironment clusterEnvironment() throws Exception;
/**
* Set up the underlying main {@link CouchbaseClientFactory} reference to be used by the Spring Data framework
* when storing into Couchbase.
*
* @throws Exception in case of error during the CouchbaseClientFactory instantiation.
*/
CouchbaseClientFactory couchbaseClientFactory(ClusterEnvironment clusterEnvironment) throws Exception;
}