Class JpaRepositoryFactory
java.lang.Object
org.springframework.data.repository.core.support.RepositoryFactorySupport
org.springframework.data.jpa.repository.support.JpaRepositoryFactory
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanClassLoaderAware,org.springframework.beans.factory.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
ConstructorsConstructorDescriptionJpaRepositoryFactory(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.ProjectionFactorygetProjectionFactory(ClassLoader classLoader, org.springframework.beans.factory.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.RepositoryFragmentsgetRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata metadata) protected org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragmentsgetRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata metadata, jakarta.persistence.EntityManager entityManager, org.springframework.data.querydsl.EntityPathResolver resolver, CrudMethodMetadata crudMethodMetadata) CreatesRepositoryComposition.RepositoryFragmentsbased onRepositoryMetadatato 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 aJpaRepositoryinstance with the givenEntityManagervoidsetBeanClassLoader(ClassLoader classLoader) voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) If aBeanFactoryis being set, this is clearly in a Spring context, and so we can capture theQueryRewriterProviderbeing aBeanFactoryQueryRewriterProvider.voidsetEntityPathResolver(org.springframework.data.querydsl.EntityPathResolver entityPathResolver) Configures theEntityPathResolverto be used.voidsetEscapeCharacter(EscapeCharacter escapeCharacter) Configures the escape character to be used for like-expressions created for derived queries.voidsetQueryMethodFactory(JpaQueryMethodFactory queryMethodFactory) Configures theJpaQueryMethodFactoryto be used.voidsetQueryRewriterProvider(QueryRewriterProvider queryRewriterProvider) Configures theQueryRewriterProviderto 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:
setBeanClassLoaderin interfaceorg.springframework.beans.factory.BeanClassLoaderAware- Overrides:
setBeanClassLoaderin classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException If aBeanFactoryis being set, this is clearly in a Spring context, and so we can capture theQueryRewriterProviderbeing aBeanFactoryQueryRewriterProvider.- Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Overrides:
setBeanFactoryin classorg.springframework.data.repository.core.support.RepositoryFactorySupport- Parameters:
beanFactory-- Throws:
org.springframework.beans.BeansException
-
setEntityPathResolver
public void setEntityPathResolver(org.springframework.data.querydsl.EntityPathResolver entityPathResolver) Configures theEntityPathResolverto 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 theJpaQueryMethodFactoryto be used. Defaults toDefaultJpaQueryMethodFactory.- Parameters:
queryMethodFactory- must not be null.
-
setQueryRewriterProvider
Configures theQueryRewriterProviderto 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:
getTargetRepositoryin 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 aJpaRepositoryinstance 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:
getRepositoryBaseClassin classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
getProjectionFactory
protected org.springframework.data.projection.ProjectionFactory getProjectionFactory(ClassLoader classLoader, org.springframework.beans.factory.BeanFactory beanFactory) - Overrides:
getProjectionFactoryin 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:
getQueryLookupStrategyin classorg.springframework.data.repository.core.support.RepositoryFactorySupport
-
getEntityInformation
- Specified by:
getEntityInformationin 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:
getRepositoryFragmentsin 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.RepositoryFragmentsbased onRepositoryMetadatato add JPA-specific extensions. Typically adds aQuerydslJpaPredicateExecutorif 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
-