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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Set to true if field names should be abbreviated with theCamelCaseAbbreviatingFieldNamingStrategy
.protected com.couchbase.client.core.env.Authenticator
Allows to override theAuthenticator
used.protected boolean
Configure whether to automatically create indices for domain types by deriving the from the entity or not.protected void
configureEnvironment
(com.couchbase.client.java.env.ClusterEnvironment.Builder builder) Can be overridden to customize the configuration of the environment before bootstrap.protected void
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).protected void
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).couchbaseClientFactory
(com.couchbase.client.java.Cluster couchbaseCluster) TheCouchbaseClientFactory
provides access to the lower level SDK resources.com.couchbase.client.java.Cluster
couchbaseCluster
(com.couchbase.client.java.env.ClusterEnvironment couchbaseClusterEnvironment) com.couchbase.client.java.env.ClusterEnvironment
couchbaseMappingContext
(CustomConversions customConversions) Creates aCouchbaseMappingContext
equipped with entity classes scanned from the mapping base package.com.fasterxml.jackson.databind.ObjectMapper
Creates aObjectMapper
for the jsonSerializer of the ClusterEnvironmentcouchbaseRepositoryOperationsMapping
(CouchbaseTemplate couchbaseTemplate) couchbaseTemplate
(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter) Deprecated.couchbaseTemplate
(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) couchbaseTransactionalOperator
(CouchbaseCallbackTransactionManager couchbaseCallbackTransactionManager) The default TransactionalOperator.Creates aTranslationService
.protected com.couchbase.client.core.encryption.CryptoManager
Register custom Converters in aCustomConversions
object if required.customConversions
(com.couchbase.client.core.encryption.CryptoManager cryptoManager) Register custom Converters in aCustomConversions
object if required.protected FieldNamingStrategy
Configures aFieldNamingStrategy
on theCouchbaseMappingContext
instance created.abstract String
The name of the bucket that should be used (for example "travel-sample").abstract String
The connection string which allows the SDK to connect to the cluster.com.couchbase.client.java.query.QueryScanConsistency
Scans the mapping base package for classes annotated withDocument
.protected String
Return the base package to scan for mappedDocument
s.abstract String
The password used or the username to authenticate against the cluster.protected String
If a non-default scope should be used, override this method.abstract String
The username of the user accessing Couchbase, configured on the cluster.mappingCouchbaseConverter
(CouchbaseMappingContext couchbaseMappingContext, CouchbaseCustomConversions couchbaseCustomConversions) Creates aMappingCouchbaseConverter
using the configuredcouchbaseMappingContext(org.springframework.data.convert.CustomConversions)
.reactiveCouchbaseRepositoryOperationsMapping
(ReactiveCouchbaseTemplate reactiveCouchbaseTemplate) reactiveCouchbaseTemplate
(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter) Deprecated.reactiveCouchbaseTemplate
(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) transactionInterceptor
(TransactionManager couchbaseTransactionManager) 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 theAuthenticator
used.The default implementation uses the
PasswordAuthenticator
and 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) TheCouchbaseClientFactory
provides 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) -
couchbaseTemplate
@Deprecated public CouchbaseTemplate couchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter) Deprecated. -
reactiveCouchbaseTemplate
@Bean(name="reactiveCouchbaseTemplate") public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService) -
reactiveCouchbaseTemplate
@Deprecated public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter) Deprecated. -
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 aMappingCouchbaseConverter
using 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 aCouchbaseMappingContext
equipped with entity classes scanned from the mapping base package.- Throws:
Exception
-
couchbaseObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper couchbaseObjectMapper()Creates aObjectMapper
for the jsonSerializer of the ClusterEnvironment- Returns:
- ObjectMapper
-
couchbaseTransactionalOperator
@Bean("couchbaseTransactionalOperator") public CouchbaseTransactionalOperator couchbaseTransactionalOperator(CouchbaseCallbackTransactionManager couchbaseCallbackTransactionManager) The default TransactionalOperator.- Parameters:
couchbaseCallbackTransactionManager
-- Returns:
-
transactionInterceptor
@Bean @Role(2) public TransactionInterceptor transactionInterceptor(TransactionManager couchbaseTransactionManager) -
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 aCustomConversions
object if required. TheseCustomConversions
will be registered with themappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions)
)} andcouchbaseMappingContext(CustomConversions)
.- Returns:
- must not be null.
-
customConversions
public CustomConversions customConversions(com.couchbase.client.core.encryption.CryptoManager cryptoManager) Register custom Converters in aCustomConversions
object if required. TheseCustomConversions
will be registered with themappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions)
)} andcouchbaseMappingContext(CustomConversions)
.- Parameters:
cryptoManager
-- Returns:
- must not be null.
-
cryptoManager
protected com.couchbase.client.core.encryption.CryptoManager cryptoManager() -
getMappingBasePackage
Return the base package to scan for mappedDocument
s. 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.AppConfig
extendingAbstractCouchbaseConfiguration
the base package will be consideredcom.acme
unless the method is overridden to implement alternate behavior.- Returns:
- the base package to scan for mapped
Document
classes 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 aFieldNamingStrategy
on theCouchbaseMappingContext
instance created.- Returns:
- the naming strategy.
-
getDefaultConsistency
public com.couchbase.client.java.query.QueryScanConsistency getDefaultConsistency()
-