Class RepositoryConfigurationExtensionSupport

java.lang.Object
org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport
All Implemented Interfaces:
RepositoryConfigurationExtension

public abstract class RepositoryConfigurationExtensionSupport extends Object implements RepositoryConfigurationExtension
Base implementation of RepositoryConfigurationExtension to ease the implementation of the interface. Will default the default named query location based on a module prefix provided by implementors (see getModulePrefix()). Stubs out the post-processing methods as they might not be needed by default.
Author:
Oliver Gierke, Mark Paluch, Christoph Strobl, Johannes Englmeier
  • Constructor Details

    • RepositoryConfigurationExtensionSupport

      public RepositoryConfigurationExtensionSupport()
  • Method Details

    • getModuleName

      public String getModuleName()
      Description copied from interface: RepositoryConfigurationExtension
      Returns the descriptive name of the module.
      Specified by:
      getModuleName in interface RepositoryConfigurationExtension
      Returns:
      will never be null.
    • getRepositoryConfigurations

      public <T extends RepositoryConfigurationSource> Collection<RepositoryConfiguration<T>> getRepositoryConfigurations(T configSource, org.springframework.core.io.ResourceLoader loader)
    • getRepositoryConfigurations

      public <T extends RepositoryConfigurationSource> Collection<RepositoryConfiguration<T>> getRepositoryConfigurations(T configSource, org.springframework.core.io.ResourceLoader loader, boolean strictMatchesOnly)
      Description copied from interface: RepositoryConfigurationExtension
      Returns all RepositoryConfigurations obtained through the given RepositoryConfigurationSource.
      Specified by:
      getRepositoryConfigurations in interface RepositoryConfigurationExtension
      Parameters:
      configSource - RepositoryConfigurationSource encapsulating the source (XML, Annotation) of the repository configuration.
      loader - ResourceLoader used to load resources.
      strictMatchesOnly - whether to return strict repository matches only. Handing in true will cause the repository interfaces and domain types handled to be checked whether they are managed by the current store.
      Returns:
      will never be null.
    • getDefaultNamedQueryLocation

      public String getDefaultNamedQueryLocation()
      Description copied from interface: RepositoryConfigurationExtension
      Returns the default location of the Spring Data named queries.
      Specified by:
      getDefaultNamedQueryLocation in interface RepositoryConfigurationExtension
      Returns:
      will never be null.
    • registerBeansForRoot

      public void registerBeansForRoot(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource)
      Description copied from interface: RepositoryConfigurationExtension
      Callback to register additional bean definitions for a repositories root node. This usually includes beans you have to set up once independently of the number of repositories to be created. Will be called before any repositories bean definitions have been registered.
      Specified by:
      registerBeansForRoot in interface RepositoryConfigurationExtension
      Parameters:
      registry - BeanDefinitionRegistry containing bean definitions.
      configurationSource - RepositoryConfigurationSource encapsulating the source (e.g. XML, Annotation) of the repository configuration.
    • getModulePrefix

      @Deprecated protected abstract String getModulePrefix()
      Deprecated.
      since 3.0, refer to RepositoryConfigurationExtension.getModuleIdentifier() instead and implement either getModuleName() directly or both methods if the default translation from name to identifier as defined in RepositoryConfigurationExtension.getModuleIdentifier() doesn't suit you.
      Returns the prefix of the module to be used to create the default location for Spring Data named queries.
      Returns:
      must not be null.
    • postProcess

      public void postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder builder, RepositoryConfigurationSource source)
      Description copied from interface: RepositoryConfigurationExtension
      Callback to post process the BeanDefinition and tweak the configuration if necessary.
      Specified by:
      postProcess in interface RepositoryConfigurationExtension
      Parameters:
      builder - will never be null.
      source - will never be null.
    • postProcess

      public void postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config)
      Description copied from interface: RepositoryConfigurationExtension
      Callback to post process the BeanDefinition built from annotations and tweak the configuration if necessary.
      Specified by:
      postProcess in interface RepositoryConfigurationExtension
      Parameters:
      builder - will never be null.
      config - will never be null.
    • postProcess

      public void postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config)
      Description copied from interface: RepositoryConfigurationExtension
      Callback to post process the BeanDefinition built from XML and tweak the configuration if necessary.
      Specified by:
      postProcess in interface RepositoryConfigurationExtension
      Parameters:
      builder - will never be null.
      config - will never be null.
    • getIdentifyingAnnotations

      protected Collection<Class<? extends Annotation>> getIdentifyingAnnotations()
      Return the annotations to scan domain types for when evaluating repository interfaces for store assignment. Modules should return the annotations that identify a domain type as managed by the store explicitly.
      Returns:
      Since:
      1.9
    • getIdentifyingTypes

      protected Collection<Class<?>> getIdentifyingTypes()
      Returns the types that indicate a store match when inspecting repositories for strict matches.
      Returns:
      Since:
      1.9
    • getConfigurationInspectionClassLoader

      @Nullable protected ClassLoader getConfigurationInspectionClassLoader(org.springframework.core.io.ResourceLoader loader)
      Returns the ClassLoader to load repository interfaces for configuration inspection. Subclasses may override this method to provide a customized class loader.
      Parameters:
      loader - must not be null.
      Returns:
      the ClassLoader for repository interfaces configuration inspection.
      Since:
      2.1
    • registerWithSourceAndGeneratedBeanName

      public static String registerWithSourceAndGeneratedBeanName(org.springframework.beans.factory.support.AbstractBeanDefinition bean, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Object source)
      Sets the given source on the given AbstractBeanDefinition and registers it inside the given BeanDefinitionRegistry. For BeanDefinitions to be registered once-and-only-once for all configuration elements (annotation or XML), prefer calling registerIfNotAlreadyRegistered(Supplier, BeanDefinitionRegistry, String, Object) with a dedicated bean name to avoid the bead definition being registered multiple times.
      Parameters:
      bean - must not be null.
      registry - must not be null.
      source - must not be null.
      Returns:
      the bean name generated for the given BeanDefinition
    • registerIfNotAlreadyRegistered

      public static void registerIfNotAlreadyRegistered(Supplier<org.springframework.beans.factory.support.AbstractBeanDefinition> supplier, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, String beanName, Object source)
      Registers the AbstractBeanDefinition produced by the given Supplier with the given registry with the given bean name unless the registry already contains a bean with that name.
      Parameters:
      supplier - must not be null.
      registry - must not be null.
      beanName - must not be null or empty.
      source - must not be null.
      Since:
      2.1
    • registerLazyIfNotAlreadyRegistered

      public static void registerLazyIfNotAlreadyRegistered(Supplier<org.springframework.beans.factory.support.AbstractBeanDefinition> supplier, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, String beanName, Object source)
      Registers the AbstractBeanDefinition produced by the given Supplier as lazy bean definition with the given registry with the given bean name unless the registry already contains a bean with that name.
      Parameters:
      supplier - must not be null.
      registry - must not be null.
      beanName - must not be null or empty.
      source - must not be null.
      Since:
      2.1
    • hasBean

      public static boolean hasBean(Class<?> type, org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
      Returns whether the given BeanDefinitionRegistry already contains a bean of the given type assuming the bean name has been auto-generated.
      Parameters:
      type -
      registry -
      Returns:
    • getRepositoryConfiguration

      protected <T extends RepositoryConfigurationSource> RepositoryConfiguration<T> getRepositoryConfiguration(org.springframework.beans.factory.config.BeanDefinition definition, T configSource)
      Creates a actual RepositoryConfiguration instance for the given RepositoryConfigurationSource and interface name. Defaults to the DefaultRepositoryConfiguration but allows sub-classes to override this to customize the behavior.
      Parameters:
      definition - will never be null or empty.
      configSource - will never be null.
      Returns:
    • isStrictRepositoryCandidate

      protected boolean isStrictRepositoryCandidate(RepositoryMetadata metadata)
      Returns whether the given repository metadata is a candidate for bean definition creation in the strict repository detection mode. The default implementation inspects the domain type managed for a set of well-known annotations (see getIdentifyingAnnotations()). If none of them is found, the candidate is discarded. Implementations should make sure, the only return true if they're really sure the interface handed to the method is really a store interface.
      Parameters:
      metadata -
      Returns:
      Since:
      1.9
    • useRepositoryConfiguration

      protected boolean useRepositoryConfiguration(RepositoryMetadata metadata)
      Return whether to use the configuration for the repository with the given metadata. Defaults to true and InvalidDataAccessApiUsageException for reactive repositories. Must be overridden by store modules that wish to provide reactive repositories.
      Parameters:
      metadata - will never be null.
      Returns:
      Throws:
      org.springframework.dao.InvalidDataAccessApiUsageException - on repositories by default.