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
ModifierConstructorDescriptionprotected
RepositoryFactoryBeanSupport
(Class<? extends T> repositoryInterface) Creates a newRepositoryFactoryBeanSupport
for the given repository interface. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Register aRepositoryFactoryCustomizer
to customize therepository factor
before creating the repository.void
protected Optional<QueryMethodEvaluationContextProvider>
Create a defaultQueryMethodEvaluationContextProvider
(or subclass) fromListableBeanFactory
.protected abstract RepositoryFactorySupport
Create the actualRepositoryFactorySupport
instance.ReturnsEntityInformation
the repository factory is using.PersistentEntity<?,
?> Returns thePersistentEntity
managed by the underlying repository.Returns allQueryMethod
s declared for that repository.Returns theRepositoryInformation
to determine meta-information about the repository being used.boolean
void
void
setBeanClassLoader
(ClassLoader classLoader) void
setBeanFactory
(BeanFactory beanFactory) void
setCustomImplementation
(Object customImplementation) Setter to inject a custom repository implementation.void
setEvaluationContextProvider
(QueryMethodEvaluationContextProvider evaluationContextProvider) Sets theQueryMethodEvaluationContextProvider
to be used to evaluate SpEL expressions in manually defined queries.void
setLazyInit
(boolean lazy) Configures whether to initialize the repository proxy lazily.protected void
setMappingContext
(MappingContext<?, ?> mappingContext) Configures theMappingContext
to be used to lookupPersistentEntity
instances forgetPersistentEntity()
.void
setNamedQueries
(NamedQueries namedQueries) Setter to inject aNamedQueries
instance.void
setQueryLookupStrategyKey
(QueryLookupStrategy.Key queryLookupStrategyKey) Set theQueryLookupStrategy.Key
to be used.void
setRepositoryBaseClass
(Class<?> repositoryBaseClass) Configures the repository base class to be used.void
setRepositoryFragments
(RepositoryComposition.RepositoryFragments repositoryFragments) Setter to inject repository fragments.
-
Constructor Details
-
RepositoryFactoryBeanSupport
Creates a newRepositoryFactoryBeanSupport
for 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.Key
to 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 aNamedQueries
instance.- Parameters:
namedQueries
- the namedQueries to set
-
setMappingContext
Configures theMappingContext
to be used to lookupPersistentEntity
instances forgetPersistentEntity()
.- Parameters:
mappingContext
-
-
setEvaluationContextProvider
public void setEvaluationContextProvider(QueryMethodEvaluationContextProvider evaluationContextProvider) Sets theQueryMethodEvaluationContextProvider
to be used to evaluate SpEL expressions in manually defined queries.- Parameters:
evaluationContextProvider
- must not be null.
-
addRepositoryFactoryCustomizer
Register aRepositoryFactoryCustomizer
to customize therepository factor
before 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:
setBeanClassLoader
in interfaceBeanClassLoaderAware
-
setBeanFactory
- Specified by:
setBeanFactory
in 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:
setApplicationEventPublisher
in interfaceApplicationEventPublisherAware
-
getEntityInformation
Description copied from interface:RepositoryFactoryInformation
ReturnsEntityInformation
the repository factory is using.- Specified by:
getEntityInformation
in interfaceRepositoryFactoryInformation<T extends Repository<S,
ID>, S> - Returns:
-
getRepositoryInformation
Description copied from interface:RepositoryFactoryInformation
Returns theRepositoryInformation
to determine meta-information about the repository being used.- Specified by:
getRepositoryInformation
in interfaceRepositoryFactoryInformation<T extends Repository<S,
ID>, S> - Returns:
-
getPersistentEntity
Description copied from interface:RepositoryFactoryInformation
Returns thePersistentEntity
managed by the underlying repository. Can be null in case the underlying persistence mechanism does not expose aMappingContext
.- Specified by:
getPersistentEntity
in interfaceRepositoryFactoryInformation<T extends Repository<S,
ID>, S> - Returns:
-
getQueryMethods
Description copied from interface:RepositoryFactoryInformation
Returns allQueryMethod
s declared for that repository.- Specified by:
getQueryMethods
in interfaceRepositoryFactoryInformation<T extends Repository<S,
ID>, S> - Returns:
-
getObject
- Specified by:
getObject
in interfaceFactoryBean<T extends Repository<S,
ID>>
-
getObjectType
- Specified by:
getObjectType
in interfaceFactoryBean<T extends Repository<S,
ID>>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingleton
in interfaceFactoryBean<T extends Repository<S,
ID>>
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
createRepositoryFactory
Create the actualRepositoryFactorySupport
instance.- Returns:
-