Class JpaRepositoryFactory
java.lang.Object
org.springframework.data.repository.core.support.RepositoryFactorySupport
org.springframework.data.jpa.repository.support.JpaRepositoryFactory
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,BeanFactoryAware
JPA specific generic repository factory.
- Author:
- Oliver Gierke, Mark Paluch, Christoph Strobl, Jens Schauder, Stefan Fussenegger, RĂ©da Housni Alaoui, Gabriel Basilio, Greg Turnquist
-
Constructor Summary
ConstructorDescriptionJpaRepositoryFactory
(jakarta.persistence.EntityManager entityManager) Creates a newJpaRepositoryFactory
. -
Method Summary
Modifier and TypeMethodDescription<T,
ID> JpaEntityInformation<T, ID> getEntityInformation
(Class<T> domainClass) protected ProjectionFactory
getProjectionFactory
(ClassLoader classLoader, BeanFactory beanFactory) protected Optional<QueryLookupStrategy>
getQueryLookupStrategy
(QueryLookupStrategy.Key key, QueryMethodEvaluationContextProvider evaluationContextProvider) protected Class<?>
getRepositoryBaseClass
(RepositoryMetadata metadata) getRepositoryFragments
(RepositoryMetadata metadata) getRepositoryFragments
(RepositoryMetadata metadata, jakarta.persistence.EntityManager entityManager, EntityPathResolver resolver, CrudMethodMetadata crudMethodMetadata) CreatesRepositoryComposition.RepositoryFragments
based onRepositoryMetadata
to add JPA-specific extensions.protected final JpaRepositoryImplementation<?,
?> getTargetRepository
(RepositoryInformation information) protected JpaRepositoryImplementation<?,
?> getTargetRepository
(RepositoryInformation information, jakarta.persistence.EntityManager entityManager) Callback to create aJpaRepository
instance with the givenEntityManager
void
setBeanClassLoader
(ClassLoader classLoader) void
setBeanFactory
(BeanFactory beanFactory) If aBeanFactory
is being set, this is clearly in a Spring context, and so we can capture theQueryRewriterProvider
being aBeanFactoryQueryRewriterProvider
.void
setEntityPathResolver
(EntityPathResolver entityPathResolver) Configures theEntityPathResolver
to be used.void
setEscapeCharacter
(EscapeCharacter escapeCharacter) Configures the escape character to be used for like-expressions created for derived queries.void
setQueryMethodFactory
(JpaQueryMethodFactory queryMethodFactory) Configures theJpaQueryMethodFactory
to be used.void
setQueryRewriterProvider
(QueryRewriterProvider queryRewriterProvider) Configures theQueryRewriterProvider
to be used.Methods inherited from class org.springframework.data.repository.core.support.RepositoryFactorySupport
addInvocationListener, addQueryCreationListener, addRepositoryProxyPostProcessor, getProjectionFactory, getQueryMethods, getRepository, getRepository, getRepository, getRepositoryInformation, getRepositoryMetadata, getTargetRepositoryViaReflection, getTargetRepositoryViaReflection, instantiateClass, setEvaluationContextProvider, setNamedQueries, setQueryLookupStrategyKey, setRepositoryBaseClass, validate
-
Constructor Details
-
JpaRepositoryFactory
public JpaRepositoryFactory(jakarta.persistence.EntityManager entityManager) Creates a newJpaRepositoryFactory
.- Parameters:
entityManager
- must not be null
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
- Overrides:
setBeanClassLoader
in classRepositoryFactorySupport
-
setBeanFactory
If aBeanFactory
is being set, this is clearly in a Spring context, and so we can capture theQueryRewriterProvider
being aBeanFactoryQueryRewriterProvider
.- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Overrides:
setBeanFactory
in classRepositoryFactorySupport
- Parameters:
beanFactory
-- Throws:
BeansException
-
setEntityPathResolver
Configures theEntityPathResolver
to be used. Defaults toSimpleEntityPathResolver.INSTANCE
.- Parameters:
entityPathResolver
- must not be null.
-
setEscapeCharacter
Configures the escape character to be used for like-expressions created for derived queries.- Parameters:
escapeCharacter
- a character used for escaping in certain like expressions.
-
setQueryMethodFactory
Configures theJpaQueryMethodFactory
to be used. Defaults toDefaultJpaQueryMethodFactory
.- Parameters:
queryMethodFactory
- must not be null.
-
setQueryRewriterProvider
Configures theQueryRewriterProvider
to be used. Defaults to instantiate query rewriters throughBeanUtils.instantiateClass(Class)
.- Parameters:
queryRewriterProvider
- must not be null.- Since:
- 3.0
-
getTargetRepository
protected final JpaRepositoryImplementation<?,?> getTargetRepository(RepositoryInformation information) - Specified by:
getTargetRepository
in classRepositoryFactorySupport
-
getTargetRepository
protected JpaRepositoryImplementation<?,?> getTargetRepository(RepositoryInformation information, jakarta.persistence.EntityManager entityManager) Callback to create aJpaRepository
instance with the givenEntityManager
- Parameters:
information
- will never be null.entityManager
- will never be null.- Returns:
-
getRepositoryBaseClass
- Specified by:
getRepositoryBaseClass
in classRepositoryFactorySupport
-
getProjectionFactory
- Overrides:
getProjectionFactory
in classRepositoryFactorySupport
-
getQueryLookupStrategy
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key, QueryMethodEvaluationContextProvider evaluationContextProvider) - Overrides:
getQueryLookupStrategy
in classRepositoryFactorySupport
-
getEntityInformation
- Specified by:
getEntityInformation
in classRepositoryFactorySupport
-
getRepositoryFragments
protected RepositoryComposition.RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) - Overrides:
getRepositoryFragments
in classRepositoryFactorySupport
-
getRepositoryFragments
protected RepositoryComposition.RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata, jakarta.persistence.EntityManager entityManager, EntityPathResolver resolver, CrudMethodMetadata crudMethodMetadata) CreatesRepositoryComposition.RepositoryFragments
based onRepositoryMetadata
to add JPA-specific extensions. Typically adds aQuerydslJpaPredicateExecutor
if the repository interface uses Querydsl.Can be overridden by subclasses to customize
RepositoryComposition.RepositoryFragments
.- Parameters:
metadata
- repository metadata.entityManager
- the entity manager.resolver
- resolver to translate a plain domain class into aEntityPath
.crudMethodMetadata
- metadata about the invoked CRUD methods.- Returns:
- Since:
- 2.5.1
-