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
-
Method Summary
Modifier and TypeMethodDescriptionprotected ClassLoader
Returns theClassLoader
to 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 String
Deprecated.protected <T extends RepositoryConfigurationSource>
RepositoryConfiguration<T>getRepositoryConfiguration
(BeanDefinition definition, T configSource) Creates a actualRepositoryConfiguration
instance for the givenRepositoryConfigurationSource
and interface name.<T extends RepositoryConfigurationSource>
Collection<RepositoryConfiguration<T>>getRepositoryConfigurations
(T configSource, ResourceLoader loader) <T extends RepositoryConfigurationSource>
Collection<RepositoryConfiguration<T>>getRepositoryConfigurations
(T configSource, ResourceLoader loader, boolean strictMatchesOnly) Returns allRepositoryConfiguration
s obtained through the givenRepositoryConfigurationSource
.static boolean
hasBean
(Class<?> type, BeanDefinitionRegistry registry) Returns whether the givenBeanDefinitionRegistry
already contains a bean of the given type assuming the bean name has been auto-generated.protected boolean
Returns whether the given repository metadata is a candidate for bean definition creation in the strict repository detection mode.void
postProcess
(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) Callback to post process theBeanDefinition
built from annotations and tweak the configuration if necessary.void
postProcess
(BeanDefinitionBuilder builder, RepositoryConfigurationSource source) Callback to post process theBeanDefinition
and tweak the configuration if necessary.void
postProcess
(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) Callback to post process theBeanDefinition
built from XML and tweak the configuration if necessary.void
registerBeansForRoot
(BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) Callback to register additional bean definitions for a repositories root node.static void
registerIfNotAlreadyRegistered
(Supplier<AbstractBeanDefinition> supplier, BeanDefinitionRegistry registry, String beanName, Object source) Registers theAbstractBeanDefinition
produced by the givenSupplier
with the given registry with the given bean name unless the registry already contains a bean with that name.static void
registerLazyIfNotAlreadyRegistered
(Supplier<AbstractBeanDefinition> supplier, BeanDefinitionRegistry registry, String beanName, Object source) Registers theAbstractBeanDefinition
produced by the givenSupplier
as lazy bean definition with the given registry with the given bean name unless the registry already contains a bean with that name.static String
registerWithSourceAndGeneratedBeanName
(AbstractBeanDefinition bean, BeanDefinitionRegistry registry, Object source) Sets the given source on the givenAbstractBeanDefinition
and registers it inside the givenBeanDefinitionRegistry
.protected boolean
useRepositoryConfiguration
(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, wait
Methods inherited from interface org.springframework.data.repository.config.RepositoryConfigurationExtension
getModuleIdentifier, getRepositoryAotProcessor, getRepositoryFactoryBeanClassName
-
Constructor Details
-
RepositoryConfigurationExtensionSupport
public RepositoryConfigurationExtensionSupport()
-
-
Method Details
-
getModuleName
Description copied from interface:RepositoryConfigurationExtension
Returns the descriptive name of the module.- Specified by:
getModuleName
in interfaceRepositoryConfigurationExtension
- Returns:
- will never be null.
-
getRepositoryConfigurations
public <T extends RepositoryConfigurationSource> Collection<RepositoryConfiguration<T>> getRepositoryConfigurations(T configSource, ResourceLoader loader) -
getRepositoryConfigurations
public <T extends RepositoryConfigurationSource> Collection<RepositoryConfiguration<T>> getRepositoryConfigurations(T configSource, ResourceLoader loader, boolean strictMatchesOnly) Description copied from interface:RepositoryConfigurationExtension
Returns allRepositoryConfiguration
s obtained through the givenRepositoryConfigurationSource
.- Specified by:
getRepositoryConfigurations
in interfaceRepositoryConfigurationExtension
- 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
Description copied from interface:RepositoryConfigurationExtension
Returns the default location of the Spring Data named queries.- Specified by:
getDefaultNamedQueryLocation
in interfaceRepositoryConfigurationExtension
- Returns:
- will never be null.
-
registerBeansForRoot
public void registerBeansForRoot(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 interfaceRepositoryConfigurationExtension
- Parameters:
registry
-BeanDefinitionRegistry
containing bean definitions.configurationSource
-RepositoryConfigurationSource
encapsulating 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
Description copied from interface:RepositoryConfigurationExtension
Callback to post process theBeanDefinition
and tweak the configuration if necessary.- Specified by:
postProcess
in interfaceRepositoryConfigurationExtension
- Parameters:
builder
- will never be null.source
- will never be null.
-
postProcess
public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) Description copied from interface:RepositoryConfigurationExtension
Callback to post process theBeanDefinition
built from annotations and tweak the configuration if necessary.- Specified by:
postProcess
in interfaceRepositoryConfigurationExtension
- Parameters:
builder
- will never be null.config
- will never be null.
-
postProcess
Description copied from interface:RepositoryConfigurationExtension
Callback to post process theBeanDefinition
built from XML and tweak the configuration if necessary.- Specified by:
postProcess
in 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
Returns theClassLoader
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(AbstractBeanDefinition bean, BeanDefinitionRegistry registry, Object source) Sets the given source on the givenAbstractBeanDefinition
and registers it inside the givenBeanDefinitionRegistry
. ForBeanDefinition
s 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<AbstractBeanDefinition> supplier, BeanDefinitionRegistry registry, String beanName, Object source) Registers theAbstractBeanDefinition
produced by the givenSupplier
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<AbstractBeanDefinition> supplier, BeanDefinitionRegistry registry, String beanName, Object source) Registers theAbstractBeanDefinition
produced by the givenSupplier
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
Returns whether the givenBeanDefinitionRegistry
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(BeanDefinition definition, T configSource) Creates a actualRepositoryConfiguration
instance for the givenRepositoryConfigurationSource
and interface name. Defaults to theDefaultRepositoryConfiguration
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
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 andInvalidDataAccessApiUsageException
forreactive repositories
. Must be overridden by store modules that wish to provide reactive repositories.- Parameters:
metadata
- will never be null.- Returns:
- Throws:
InvalidDataAccessApiUsageException
- onrepositories
by 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.