Module spring.data.commons
Class RepositoryFactoryBeanSupport<T extends Repository<S,ID>,S,ID>
java.lang.Object
org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport<T,S,ID>
- Type Parameters:
T- the type of the repository.S- the entity type.ID- the entity identifier type.
- All Implemented Interfaces:
Aware,BeanClassLoaderAware,BeanFactoryAware,FactoryBean<T>,InitializingBean,ApplicationEventPublisherAware,RepositoryFactoryInformation<S,ID>
- Direct Known Subclasses:
TransactionalRepositoryFactoryBeanSupport
public abstract class RepositoryFactoryBeanSupport<T extends Repository<S,ID>,S,ID>
extends Object
implements InitializingBean, RepositoryFactoryInformation<S,ID>, FactoryBean<T>, BeanClassLoaderAware, BeanFactoryAware, ApplicationEventPublisherAware
Adapter for Spring's
FactoryBean interface to allow easy setup of repository factories via Spring
configuration.
Subclasses may pass-thru generics, provide a fixed domain, provide a fixed identifier type, or provide additional generic type parameters. Type parameters must appear in the same order the ones from this class (repository type, entity type, identifier type, additional type parameters). Using a different ordering will result in invalid type definitions.
- Author:
- Oliver Gierke, Thomas Darimont, Mark Paluch, Johannes Englmeier
-
Field Summary
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRepositoryFactoryBeanSupport(Class<? extends T> repositoryInterface) Creates a newRepositoryFactoryBeanSupportfor the given repository interface. -
Method Summary
Modifier and TypeMethodDescriptionvoidRegister aRepositoryFactoryCustomizerto customize therepository factorbefore creating the repository.voidprotected Optional<QueryMethodEvaluationContextProvider>Create a defaultQueryMethodEvaluationContextProvider(or subclass) fromListableBeanFactory.protected abstract RepositoryFactorySupportCreate the actualRepositoryFactorySupportinstance.ReturnsEntityInformationthe repository factory is using.PersistentEntity<?,?> Returns thePersistentEntitymanaged by the underlying repository.Returns allQueryMethods declared for that repository.Returns theRepositoryInformationto determine meta-information about the repository being used.booleanvoidvoidsetBeanClassLoader(ClassLoader classLoader) voidsetBeanFactory(BeanFactory beanFactory) voidsetCustomImplementation(Object customImplementation) Setter to inject a custom repository implementation.voidsetEvaluationContextProvider(QueryMethodEvaluationContextProvider evaluationContextProvider) Sets theQueryMethodEvaluationContextProviderto be used to evaluate SpEL expressions in manually defined queries.voidsetLazyInit(boolean lazy) Configures whether to initialize the repository proxy lazily.protected voidsetMappingContext(MappingContext<?, ?> mappingContext) Configures theMappingContextto be used to lookupPersistentEntityinstances forgetPersistentEntity().voidsetNamedQueries(NamedQueries namedQueries) Setter to inject aNamedQueriesinstance.voidsetQueryLookupStrategyKey(QueryLookupStrategy.Key queryLookupStrategyKey) Set theQueryLookupStrategy.Keyto be used.voidsetRepositoryBaseClass(Class<?> repositoryBaseClass) Configures the repository base class to be used.voidsetRepositoryFragments(RepositoryComposition.RepositoryFragments repositoryFragments) Setter to inject repository fragments.
-
Constructor Details
-
RepositoryFactoryBeanSupport
Creates a newRepositoryFactoryBeanSupportfor the given repository interface.- Parameters:
repositoryInterface- must not be null.
-
-
Method Details
-
setRepositoryBaseClass
Configures the repository base class to be used.- Parameters:
repositoryBaseClass- the repositoryBaseClass to set, can be null.- Since:
- 1.11
-
setQueryLookupStrategyKey
Set theQueryLookupStrategy.Keyto be used.- Parameters:
queryLookupStrategyKey-
-
setCustomImplementation
Setter to inject a custom repository implementation.- Parameters:
customImplementation-
-
setRepositoryFragments
Setter to inject repository fragments.- Parameters:
repositoryFragments-
-
setNamedQueries
Setter to inject aNamedQueriesinstance.- Parameters:
namedQueries- the namedQueries to set
-
setMappingContext
Configures theMappingContextto be used to lookupPersistentEntityinstances forgetPersistentEntity().- Parameters:
mappingContext-
-
setEvaluationContextProvider
public void setEvaluationContextProvider(QueryMethodEvaluationContextProvider evaluationContextProvider) Sets theQueryMethodEvaluationContextProviderto be used to evaluate SpEL expressions in manually defined queries.- Parameters:
evaluationContextProvider- must not be null.
-
addRepositoryFactoryCustomizer
Register aRepositoryFactoryCustomizerto customize therepository factorbefore creating the repository.- Parameters:
customizer- must not be null.- Since:
- 2.4
-
setLazyInit
public void setLazyInit(boolean lazy) Configures whether to initialize the repository proxy lazily. This defaults to false.- Parameters:
lazy- whether to initialize the repository proxy lazily. This defaults to false.
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceBeanClassLoaderAware
-
setBeanFactory
- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Throws:
BeansException
-
createDefaultQueryMethodEvaluationContextProvider
protected Optional<QueryMethodEvaluationContextProvider> createDefaultQueryMethodEvaluationContextProvider(ListableBeanFactory beanFactory) Create a defaultQueryMethodEvaluationContextProvider(or subclass) fromListableBeanFactory.- Parameters:
beanFactory- the bean factory to use.- Returns:
- the default instance. May be
Optional.empty(). - Since:
- 2.4
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware
-
getEntityInformation
Description copied from interface:RepositoryFactoryInformationReturnsEntityInformationthe repository factory is using.- Specified by:
getEntityInformationin interfaceRepositoryFactoryInformation<T extends Repository<S,ID>, S> - Returns:
-
getRepositoryInformation
Description copied from interface:RepositoryFactoryInformationReturns theRepositoryInformationto determine meta-information about the repository being used.- Specified by:
getRepositoryInformationin interfaceRepositoryFactoryInformation<T extends Repository<S,ID>, S> - Returns:
-
getPersistentEntity
Description copied from interface:RepositoryFactoryInformationReturns thePersistentEntitymanaged by the underlying repository. Can be null in case the underlying persistence mechanism does not expose aMappingContext.- Specified by:
getPersistentEntityin interfaceRepositoryFactoryInformation<T extends Repository<S,ID>, S> - Returns:
-
getQueryMethods
Description copied from interface:RepositoryFactoryInformationReturns allQueryMethods declared for that repository.- Specified by:
getQueryMethodsin interfaceRepositoryFactoryInformation<T extends Repository<S,ID>, S> - Returns:
-
getObject
- Specified by:
getObjectin interfaceFactoryBean<T extends Repository<S,ID>>
-
getObjectType
- Specified by:
getObjectTypein interfaceFactoryBean<T extends Repository<S,ID>>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingletonin interfaceFactoryBean<T extends Repository<S,ID>>
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
createRepositoryFactory
Create the actualRepositoryFactorySupportinstance.- Returns:
-