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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ClassLoadergetConfigurationInspectionClassLoader(org.springframework.core.io.ResourceLoader loader) Returns theClassLoaderto load repository interfaces for configuration inspection.Returns the default location of the Spring Data named queries.protected Collection<Class<? extends Annotation>>Return the annotations to scan domain types for when evaluating repository interfaces for store assignment.protected Collection<Class<?>>Returns the types that indicate a store match when inspecting repositories for strict matches.Returns the descriptive name of the module.protected abstract StringDeprecated.protected <T extends RepositoryConfigurationSource>
RepositoryConfiguration<T>getRepositoryConfiguration(org.springframework.beans.factory.config.BeanDefinition definition, T configSource) Creates a actualRepositoryConfigurationinstance for the givenRepositoryConfigurationSourceand interface name.<T extends RepositoryConfigurationSource>
Collection<RepositoryConfiguration<T>>getRepositoryConfigurations(T configSource, org.springframework.core.io.ResourceLoader loader) <T extends RepositoryConfigurationSource>
Collection<RepositoryConfiguration<T>>getRepositoryConfigurations(T configSource, org.springframework.core.io.ResourceLoader loader, boolean strictMatchesOnly) Returns allRepositoryConfigurations obtained through the givenRepositoryConfigurationSource.static booleanReturns whether the givenBeanDefinitionRegistryalready contains a bean of the given type assuming the bean name has been auto-generated.protected booleanReturns whether the given repository metadata is a candidate for bean definition creation in the strict repository detection mode.voidpostProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) Callback to post process theBeanDefinitionbuilt from annotations and tweak the configuration if necessary.voidpostProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder builder, RepositoryConfigurationSource source) Callback to post process theBeanDefinitionand tweak the configuration if necessary.voidpostProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) Callback to post process theBeanDefinitionbuilt from XML and tweak the configuration if necessary.voidregisterBeansForRoot(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) Callback to register additional bean definitions for a repositories root node.static voidregisterIfNotAlreadyRegistered(Supplier<org.springframework.beans.factory.support.AbstractBeanDefinition> supplier, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, String beanName, Object source) Registers theAbstractBeanDefinitionproduced by the givenSupplierwith the given registry with the given bean name unless the registry already contains a bean with that name.static voidregisterLazyIfNotAlreadyRegistered(Supplier<org.springframework.beans.factory.support.AbstractBeanDefinition> supplier, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, String beanName, Object source) Registers theAbstractBeanDefinitionproduced by the givenSupplieras lazy bean definition with the given registry with the given bean name unless the registry already contains a bean with that name.static StringregisterWithSourceAndGeneratedBeanName(org.springframework.beans.factory.support.AbstractBeanDefinition bean, org.springframework.beans.factory.support.BeanDefinitionRegistry registry, Object source) Sets the given source on the givenAbstractBeanDefinitionand registers it inside the givenBeanDefinitionRegistry.protected booleanuseRepositoryConfiguration(RepositoryMetadata metadata) Return whether to use the configuration for the repository with the given metadata.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.repository.config.RepositoryConfigurationExtension
getModuleIdentifier, getRepositoryAotProcessor, getRepositoryFactoryBeanClassName
-
Constructor Details
-
RepositoryConfigurationExtensionSupport
public RepositoryConfigurationExtensionSupport()
-
-
Method Details
-
getModuleName
Description copied from interface:RepositoryConfigurationExtensionReturns the descriptive name of the module.- Specified by:
getModuleNamein interfaceRepositoryConfigurationExtension- 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:RepositoryConfigurationExtensionReturns allRepositoryConfigurations obtained through the givenRepositoryConfigurationSource.- Specified by:
getRepositoryConfigurationsin interfaceRepositoryConfigurationExtension- Parameters:
configSource-RepositoryConfigurationSourceencapsulating the source (XML, Annotation) of the repository configuration.loader-ResourceLoaderused 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
Description copied from interface:RepositoryConfigurationExtensionReturns the default location of the Spring Data named queries.- Specified by:
getDefaultNamedQueryLocationin interfaceRepositoryConfigurationExtension- Returns:
- will never be null.
-
registerBeansForRoot
public void registerBeansForRoot(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) Description copied from interface:RepositoryConfigurationExtensionCallback 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:
registerBeansForRootin interfaceRepositoryConfigurationExtension- Parameters:
registry-BeanDefinitionRegistrycontaining bean definitions.configurationSource-RepositoryConfigurationSourceencapsulating the source (e.g. XML, Annotation) of the repository configuration.
-
getModulePrefix
Deprecated.since 3.0, refer toRepositoryConfigurationExtension.getModuleIdentifier()instead and implement eithergetModuleName()directly or both methods if the default translation from name to identifier as defined inRepositoryConfigurationExtension.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:RepositoryConfigurationExtensionCallback to post process theBeanDefinitionand tweak the configuration if necessary.- Specified by:
postProcessin interfaceRepositoryConfigurationExtension- 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:RepositoryConfigurationExtensionCallback to post process theBeanDefinitionbuilt from annotations and tweak the configuration if necessary.- Specified by:
postProcessin interfaceRepositoryConfigurationExtension- 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:RepositoryConfigurationExtensionCallback to post process theBeanDefinitionbuilt from XML and tweak the configuration if necessary.- Specified by:
postProcessin interfaceRepositoryConfigurationExtension- Parameters:
builder- will never be null.config- will never be null.
-
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
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 theClassLoaderto 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
ClassLoaderfor 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 givenAbstractBeanDefinitionand registers it inside the givenBeanDefinitionRegistry. ForBeanDefinitions to be registered once-and-only-once for all configuration elements (annotation or XML), prefer callingregisterIfNotAlreadyRegistered(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 theAbstractBeanDefinitionproduced by the givenSupplierwith 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 theAbstractBeanDefinitionproduced by the givenSupplieras 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 givenBeanDefinitionRegistryalready 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 actualRepositoryConfigurationinstance for the givenRepositoryConfigurationSourceand interface name. Defaults to theDefaultRepositoryConfigurationbut 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
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 (seegetIdentifyingAnnotations()). 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
Return whether to use the configuration for the repository with the given metadata. Defaults to true andInvalidDataAccessApiUsageExceptionforreactive 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- onrepositoriesby default.
-
RepositoryConfigurationExtension.getModuleIdentifier()instead and implement eithergetModuleName()directly or both methods if the default translation from name to identifier as defined inRepositoryConfigurationExtension.getModuleIdentifier()doesn't suit you.