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
public class JpaRepositoryFactory
extends org.springframework.data.repository.core.support.RepositoryFactorySupport
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 org.springframework.data.projection.ProjectionFactory
getProjectionFactory
(ClassLoader classLoader, BeanFactory beanFactory) protected Optional<org.springframework.data.repository.query.QueryLookupStrategy>
getQueryLookupStrategy
(org.springframework.data.repository.query.QueryLookupStrategy.Key key, org.springframework.data.repository.query.QueryMethodEvaluationContextProvider evaluationContextProvider) protected Class<?>
getRepositoryBaseClass
(org.springframework.data.repository.core.RepositoryMetadata metadata) protected org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments
getRepositoryFragments
(org.springframework.data.repository.core.RepositoryMetadata metadata) protected org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments
getRepositoryFragments
(org.springframework.data.repository.core.RepositoryMetadata metadata, jakarta.persistence.EntityManager entityManager, org.springframework.data.querydsl.EntityPathResolver resolver, CrudMethodMetadata crudMethodMetadata) CreatesRepositoryComposition.RepositoryFragments
based onRepositoryMetadata
to add JPA-specific extensions.protected final JpaRepositoryImplementation<?,
?> getTargetRepository
(org.springframework.data.repository.core.RepositoryInformation information) protected JpaRepositoryImplementation<?,
?> getTargetRepository
(org.springframework.data.repository.core.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
(org.springframework.data.querydsl.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 classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
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 classorg.springframework.data.repository.core.support.RepositoryFactorySupport
- Parameters:
beanFactory
-- Throws:
BeansException
-
setEntityPathResolver
public void setEntityPathResolver(org.springframework.data.querydsl.EntityPathResolver entityPathResolver) 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(org.springframework.data.repository.core.RepositoryInformation information) - Specified by:
getTargetRepository
in classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
getTargetRepository
protected JpaRepositoryImplementation<?,?> getTargetRepository(org.springframework.data.repository.core.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
protected Class<?> getRepositoryBaseClass(org.springframework.data.repository.core.RepositoryMetadata metadata) - Specified by:
getRepositoryBaseClass
in classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
getProjectionFactory
protected org.springframework.data.projection.ProjectionFactory getProjectionFactory(ClassLoader classLoader, BeanFactory beanFactory) - Overrides:
getProjectionFactory
in classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
getQueryLookupStrategy
protected Optional<org.springframework.data.repository.query.QueryLookupStrategy> getQueryLookupStrategy(@Nullable org.springframework.data.repository.query.QueryLookupStrategy.Key key, org.springframework.data.repository.query.QueryMethodEvaluationContextProvider evaluationContextProvider) - Overrides:
getQueryLookupStrategy
in classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
getEntityInformation
- Specified by:
getEntityInformation
in classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
getRepositoryFragments
protected org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata metadata) - Overrides:
getRepositoryFragments
in classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
getRepositoryFragments
protected org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata metadata, jakarta.persistence.EntityManager entityManager, org.springframework.data.querydsl.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
-