Class AbstractCouchbaseConfiguration
java.lang.Object
org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration
Base class for Spring Data Couchbase configuration using JavaConfig.
- Author:
- Michael Nitschinger, Simon Baslé, Stephane Nicoll, Subhashni Balakrishnan, Jorge Rodriguez Martin, Michael Reiche, Vipul Gupta
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanSet to true if field names should be abbreviated with theCamelCaseAbbreviatingFieldNamingStrategy.protected voidadditionalConverters(List<Object> converters) This should be overridden in order to update thecustomConversions(CryptoManager cryptoManager, ObjectMapper objectMapper)Liststatic Map<Class<? extends Annotation>,Class<?>> protected com.couchbase.client.core.env.AuthenticatorAllows to override theAuthenticatorused.protected booleanConfigure whether to automatically create indices for domain types by deriving the from the entity or not.protected voidconfigureEnvironment(com.couchbase.client.java.env.ClusterEnvironment.Builder builder) Can be overridden to customize the configuration of the environment before bootstrap.protected voidIn order to customize the mapping between repositories/entity types to couchbase templates, use the provided mapping's api (eg. in order to have different buckets backing different repositories).protected voidIn order to customize the mapping between repositories/entity types to couchbase templates, use the provided mapping's api (eg. in order to have different buckets backing different repositories).couchbaseClientFactory(com.couchbase.client.java.Cluster couchbaseCluster) TheCouchbaseClientFactoryprovides access to the lower level SDK resources.com.couchbase.client.java.ClustercouchbaseCluster(com.couchbase.client.java.env.ClusterEnvironment couchbaseClusterEnvironment) com.couchbase.client.java.env.ClusterEnvironmentcouchbaseMappingContext(CustomConversions customConversions) Creates aCouchbaseMappingContextequipped with entity classes scanned from the mapping base package.protected com.fasterxml.jackson.databind.ObjectMapperCreates aObjectMapperfor the jsonSerializer of the ClusterEnvironment and spring-data-couchbase jacksonTranslationService and also some converters (EnumToObject, StringToEnum, IntegerToEnum)couchbaseRepositoryOperationsMapping(CouchbaseTemplate couchbaseTemplate) couchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) couchbaseTransactionalOperator(CouchbaseCallbackTransactionManager couchbaseCallbackTransactionManager) The default TransactionalOperator.Creates aTranslationService.protected com.couchbase.client.core.encryption.CryptoManagerRegister custom Converters in aCustomConversionsobject if required.customConversions(com.couchbase.client.core.encryption.CryptoManager cryptoManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Register custom Converters in aCustomConversionsobject if required.protected FieldNamingStrategyConfigures aFieldNamingStrategyon theCouchbaseMappingContextinstance created.abstract StringThe name of the bucket that should be used (for example "travel-sample").abstract StringThe connection string which allows the SDK to connect to the cluster.com.couchbase.client.java.query.QueryScanConsistencyScans the mapping base package for classes annotated withDocument.protected StringReturn the base package to scan for mappedDocuments.final com.fasterxml.jackson.databind.ObjectMapperabstract StringThe password used or the username to authenticate against the cluster.protected StringIf a non-default scope should be used, override this method.abstract StringThe username of the user accessing Couchbase, configured on the cluster.mappingCouchbaseConverter(CouchbaseMappingContext couchbaseMappingContext, CouchbaseCustomConversions couchbaseCustomConversions) Creates aMappingCouchbaseConverterusing the configuredcouchbaseMappingContext(org.springframework.data.convert.CustomConversions).reactiveCouchbaseRepositoryOperationsMapping(ReactiveCouchbaseTemplate reactiveCouchbaseTemplate) reactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) typeKey()Determines the name of the field that will store the type information for complex types when using themappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions).
-
Constructor Details
-
AbstractCouchbaseConfiguration
public AbstractCouchbaseConfiguration()
-
-
Method Details
-
getConnectionString
The connection string which allows the SDK to connect to the cluster.Note that the connection string can take many forms, in its simplest it is just a single hostname like "127.0.0.1". Please refer to the couchbase Java SDK documentation for all the different possibilities and options.
-
getUserName
The username of the user accessing Couchbase, configured on the cluster. -
getPassword
The password used or the username to authenticate against the cluster. -
getBucketName
The name of the bucket that should be used (for example "travel-sample"). -
getScopeName
If a non-default scope should be used, override this method.- Returns:
- the custom scope name or null if the default scope should be used (default).
-
authenticator
protected com.couchbase.client.core.env.Authenticator authenticator()Allows to override theAuthenticatorused.The default implementation uses the
PasswordAuthenticatorand takes the username and password fromgetUserName()andgetPassword()respectively.- Returns:
- the authenticator to be passed into the SDK.
-
couchbaseClientFactory
@Bean(name="couchbaseClientFactory") public CouchbaseClientFactory couchbaseClientFactory(com.couchbase.client.java.Cluster couchbaseCluster) TheCouchbaseClientFactoryprovides access to the lower level SDK resources.- Parameters:
couchbaseCluster- the cluster reference from the SDK.- Returns:
- the initialized factory.
-
couchbaseCluster
@Bean(destroyMethod="disconnect") public com.couchbase.client.java.Cluster couchbaseCluster(com.couchbase.client.java.env.ClusterEnvironment couchbaseClusterEnvironment) -
couchbaseClusterEnvironment
@Bean(destroyMethod="shutdown") public com.couchbase.client.java.env.ClusterEnvironment couchbaseClusterEnvironment() -
configureEnvironment
protected void configureEnvironment(com.couchbase.client.java.env.ClusterEnvironment.Builder builder) Can be overridden to customize the configuration of the environment before bootstrap.- Parameters:
builder- the builder that can be customized.
-
couchbaseTemplate
@Bean(name="couchbaseTemplate") public CouchbaseTemplate couchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) -
reactiveCouchbaseTemplate
@Bean(name="reactiveCouchbaseTemplate") public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) -
couchbaseRepositoryOperationsMapping
@Bean(name="couchbaseRepositoryOperationsMapping") public RepositoryOperationsMapping couchbaseRepositoryOperationsMapping(CouchbaseTemplate couchbaseTemplate) -
configureRepositoryOperationsMapping
In order to customize the mapping between repositories/entity types to couchbase templates, use the provided mapping's api (eg. in order to have different buckets backing different repositories).- Parameters:
mapping- the default mapping (will associate all repositories to the default template).
-
reactiveCouchbaseRepositoryOperationsMapping
@Bean(name="reactiveCouchbaseRepositoryOperationsMapping") public ReactiveRepositoryOperationsMapping reactiveCouchbaseRepositoryOperationsMapping(ReactiveCouchbaseTemplate reactiveCouchbaseTemplate) -
configureReactiveRepositoryOperationsMapping
protected void configureReactiveRepositoryOperationsMapping(ReactiveRepositoryOperationsMapping mapping) In order to customize the mapping between repositories/entity types to couchbase templates, use the provided mapping's api (eg. in order to have different buckets backing different repositories).- Parameters:
mapping- the default mapping (will associate all repositories to the default template).
-
getInitialEntitySet
Scans the mapping base package for classes annotated withDocument.- Throws:
ClassNotFoundException- if initial entity sets could not be loaded.
-
typeKey
Determines the name of the field that will store the type information for complex types when using themappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions). Defaults to "_class". -
mappingCouchbaseConverter
@Bean public MappingCouchbaseConverter mappingCouchbaseConverter(CouchbaseMappingContext couchbaseMappingContext, CouchbaseCustomConversions couchbaseCustomConversions) Creates aMappingCouchbaseConverterusing the configuredcouchbaseMappingContext(org.springframework.data.convert.CustomConversions). -
couchbaseTranslationService
Creates aTranslationService.- Returns:
- TranslationService, defaulting to JacksonTranslationService.
-
couchbaseMappingContext
@Bean("couchbaseMappingContext") public CouchbaseMappingContext couchbaseMappingContext(CustomConversions customConversions) throws Exception Creates aCouchbaseMappingContextequipped with entity classes scanned from the mapping base package.- Throws:
Exception
-
getObjectMapper
public final com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() -
couchbaseObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper couchbaseObjectMapper()Creates aObjectMapperfor the jsonSerializer of the ClusterEnvironment and spring-data-couchbase jacksonTranslationService and also some converters (EnumToObject, StringToEnum, IntegerToEnum)- Returns:
- ObjectMapper
-
couchbaseTransactionalOperator
@Bean("couchbaseTransactionalOperator") public CouchbaseTransactionalOperator couchbaseTransactionalOperator(CouchbaseCallbackTransactionManager couchbaseCallbackTransactionManager) The default TransactionalOperator.- Parameters:
couchbaseCallbackTransactionManager-- Returns:
-
autoIndexCreation
protected boolean autoIndexCreation()Configure whether to automatically create indices for domain types by deriving the from the entity or not. -
customConversions
Register custom Converters in aCustomConversionsobject if required. TheseCustomConversionswill be registered with themappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions))} andcouchbaseMappingContext(CustomConversions).- Returns:
- must not be null.
-
customConversions
public CustomConversions customConversions(com.couchbase.client.core.encryption.CryptoManager cryptoManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Register custom Converters in aCustomConversionsobject if required. TheseCustomConversionswill be registered with themappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions))} andcouchbaseMappingContext(CustomConversions).- Parameters:
cryptoManager-objectMapper-- Returns:
- must not be null.
-
additionalConverters
This should be overridden in order to update thecustomConversions(CryptoManager cryptoManager, ObjectMapper objectMapper)List -
annotationToConverterMap
-
cryptoManager
protected com.couchbase.client.core.encryption.CryptoManager cryptoManager() -
getMappingBasePackage
Return the base package to scan for mappedDocuments. Will return the package name of the configuration class (the concrete class, not this one here) by default.So if you have a
com.acme.AppConfigextendingAbstractCouchbaseConfigurationthe base package will be consideredcom.acmeunless the method is overridden to implement alternate behavior.- Returns:
- the base package to scan for mapped
Documentclasses or null to not enable scanning for entities.
-
abbreviateFieldNames
protected boolean abbreviateFieldNames()Set to true if field names should be abbreviated with theCamelCaseAbbreviatingFieldNamingStrategy.- Returns:
- true if field names should be abbreviated, default is false.
-
fieldNamingStrategy
Configures aFieldNamingStrategyon theCouchbaseMappingContextinstance created.- Returns:
- the naming strategy.
-
getDefaultConsistency
public com.couchbase.client.java.query.QueryScanConsistency getDefaultConsistency()
-