Class AbstractCouchbaseConfiguration

java.lang.Object
org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration

@Configuration public abstract class AbstractCouchbaseConfiguration extends Object
Base class for Spring Data Couchbase configuration using JavaConfig.
Author:
Michael Nitschinger, Simon Baslé, Stephane Nicoll, Subhashni Balakrishnan, Jorge Rodriguez Martin, Michael Reiche
  • Constructor Details

    • AbstractCouchbaseConfiguration

      public AbstractCouchbaseConfiguration()
  • Method Details

    • getConnectionString

      public abstract String 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

      public abstract String getUserName()
      The username of the user accessing Couchbase, configured on the cluster.
    • getPassword

      public abstract String getPassword()
      The password used or the username to authenticate against the cluster.
    • getBucketName

      public abstract String getBucketName()
      The name of the bucket that should be used (for example "travel-sample").
    • getScopeName

      protected String 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 the Authenticator used.

      The default implementation uses the PasswordAuthenticator and takes the username and password from getUserName() and getPassword() respectively.

      Returns:
      the authenticator to be passed into the SDK.
    • couchbaseClientFactory

      @Bean(name="couchbaseClientFactory") public CouchbaseClientFactory couchbaseClientFactory(com.couchbase.client.java.Cluster couchbaseCluster)
      The CouchbaseClientFactory 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)
    • reactiveCouchbaseTemplate

      @Bean(name="reactiveCouchbaseTemplate") public ReactiveCouchbaseTemplate reactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory, MappingCouchbaseConverter mappingCouchbaseConverter, TranslationService couchbaseTranslationService)
    • couchbaseRepositoryOperationsMapping

      @Bean(name="couchbaseRepositoryOperationsMapping") public RepositoryOperationsMapping couchbaseRepositoryOperationsMapping(CouchbaseTemplate couchbaseTemplate)
    • configureRepositoryOperationsMapping

      protected void configureRepositoryOperationsMapping(RepositoryOperationsMapping 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).
    • 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

      protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException
      Scans the mapping base package for classes annotated with Document.
      Throws:
      ClassNotFoundException - if initial entity sets could not be loaded.
    • typeKey

      public String typeKey()
      Determines the name of the field that will store the type information for complex types when using the mappingCouchbaseConverter(CouchbaseMappingContext, CouchbaseCustomConversions). Defaults to "_class".
      See Also:
    • mappingCouchbaseConverter

      @Bean public MappingCouchbaseConverter mappingCouchbaseConverter(CouchbaseMappingContext couchbaseMappingContext, CouchbaseCustomConversions couchbaseCustomConversions)
    • couchbaseTranslationService

      @Bean public TranslationService couchbaseTranslationService()
      Returns:
      TranslationService, defaulting to JacksonTranslationService.
    • couchbaseMappingContext

      @Bean("couchbaseMappingContext") public CouchbaseMappingContext couchbaseMappingContext(CustomConversions customConversions) throws Exception
      Creates a CouchbaseMappingContext equipped 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 a ObjectMapper for 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

      @Bean(name="couchbaseCustomConversions") public CustomConversions customConversions()
      Returns:
      must not be null.
    • customConversions

      public CustomConversions customConversions(com.couchbase.client.core.encryption.CryptoManager cryptoManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Parameters:
      cryptoManager -
      Returns:
      must not be null.
    • cryptoManager

      protected com.couchbase.client.core.encryption.CryptoManager cryptoManager()
    • getMappingBasePackage

      protected String getMappingBasePackage()
      Return the base package to scan for mapped Documents. 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 extending AbstractCouchbaseConfiguration the base package will be considered com.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 the CamelCaseAbbreviatingFieldNamingStrategy.
      Returns:
      true if field names should be abbreviated, default is false.
    • fieldNamingStrategy

      protected FieldNamingStrategy fieldNamingStrategy()
      Configures a FieldNamingStrategy on the CouchbaseMappingContext instance created.
      Returns:
      the naming strategy.
    • getDefaultConsistency

      public com.couchbase.client.java.query.QueryScanConsistency getDefaultConsistency()