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, EnvironmentAware, EnvironmentCapable
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(EntityManager entityManager) Creates a newJpaRepositoryFactory. -
Method Summary
Modifier and TypeMethodDescription<T,ID> JpaEntityInformation <T, ID> getEntityInformation(Class<T> domainClass) EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) protected ProjectionFactorygetProjectionFactory(@Nullable ClassLoader classLoader, @Nullable BeanFactory beanFactory) protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key, ValueExpressionDelegate valueExpressionDelegate) protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) getRepositoryFragments(RepositoryMetadata metadata) getRepositoryFragments(RepositoryMetadata metadata, EntityManager entityManager, EntityPathResolver resolver, CrudMethodMetadata crudMethodMetadata) CreatesRepositoryComposition.RepositoryFragmentsbased onRepositoryMetadatato add JPA-specific extensions.protected final JpaRepositoryImplementation<?, ?> getTargetRepository(RepositoryInformation information) protected JpaRepositoryImplementation<?, ?> getTargetRepository(RepositoryInformation information, EntityManager entityManager) Callback to create aJpaRepositoryinstance with the givenEntityManagervoidsetBeanClassLoader(@Nullable ClassLoader classLoader) voidsetBeanFactory(BeanFactory beanFactory) If aBeanFactoryis being set, this is clearly in a Spring context, and so we can capture theQueryRewriterProviderbeing aBeanFactoryQueryRewriterProvider.voidsetEntityPathResolver(EntityPathResolver entityPathResolver) Configures theEntityPathResolverto be used.voidsetEscapeCharacter(EscapeCharacter escapeCharacter) Configures the escape character to be used for like-expressions created for derived queries.voidsetFragmentsContributor(JpaRepositoryFragmentsContributor fragmentsContributor) Configures theJpaRepositoryFragmentsContributorto be used.voidsetQueryEnhancerSelector(QueryEnhancerSelector queryEnhancerSelector) Configures theQueryEnhancerSelectorto be used.voidsetQueryMethodFactory(JpaQueryMethodFactory queryMethodFactory) Configures theJpaQueryMethodFactoryto be used.voidsetQueryRewriterProvider(QueryRewriterProvider queryRewriterProvider) Configures theQueryRewriterProviderto be used.voidsetValidateQueries(boolean validateQueries) Configures whether queries should be validated on creation.Methods inherited from class RepositoryFactorySupport
addInvocationListener, addQueryCreationListener, addRepositoryProxyPostProcessor, getEnvironment, getProjectionFactory, getQueryMethods, getRepository, getRepository, getRepository, getRepositoryInformation, getRepositoryMetadata, getTargetRepositoryViaReflection, instantiateClass, setEnvironment, setEvaluationContextProvider, setExposeMetadata, setNamedQueries, setQueryLookupStrategyKey, setRepositoryBaseClass, validate
-
Constructor Details
-
JpaRepositoryFactory
Creates a newJpaRepositoryFactory.- Parameters:
entityManager- must not be null
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceBeanClassLoaderAware- Overrides:
setBeanClassLoaderin classRepositoryFactorySupport
-
setBeanFactory
If aBeanFactoryis being set, this is clearly in a Spring context, and so we can capture theQueryRewriterProviderbeing aBeanFactoryQueryRewriterProvider.- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Overrides:
setBeanFactoryin classRepositoryFactorySupport- Parameters:
beanFactory-- Throws:
BeansException
-
setEntityPathResolver
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.
-
setValidateQueries
public void setValidateQueries(boolean validateQueries) Configures whether queries should be validated on creation.- Parameters:
validateQueries-- Since:
- 4.2
-
setFragmentsContributor
Configures theJpaRepositoryFragmentsContributorto be used. Defaults toJpaRepositoryFragmentsContributor.DEFAULT.- Parameters:
fragmentsContributor-- Since:
- 4.0
-
setQueryMethodFactory
Configures theJpaQueryMethodFactoryto be used. Defaults toDefaultJpaQueryMethodFactory.- Parameters:
queryMethodFactory- must not be null.
-
setQueryEnhancerSelector
Configures theQueryEnhancerSelectorto be used. Defaults toQueryEnhancerSelector.DEFAULT_SELECTOR.- Parameters:
queryEnhancerSelector- 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(RepositoryInformation information) - Specified by:
getTargetRepositoryin classRepositoryFactorySupport
-
getTargetRepository
protected JpaRepositoryImplementation<?,?> getTargetRepository(RepositoryInformation information, EntityManager entityManager) Callback to create aJpaRepositoryinstance with the givenEntityManager- Parameters:
information- will never be null.entityManager- will never be null.- Returns:
-
getRepositoryBaseClass
- Specified by:
getRepositoryBaseClassin classRepositoryFactorySupport
-
getProjectionFactory
protected ProjectionFactory getProjectionFactory(@Nullable ClassLoader classLoader, @Nullable BeanFactory beanFactory) - Overrides:
getProjectionFactoryin classRepositoryFactorySupport
-
getQueryLookupStrategy
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key, ValueExpressionDelegate valueExpressionDelegate) - Overrides:
getQueryLookupStrategyin classRepositoryFactorySupport
-
getEntityInformation
- Overrides:
getEntityInformationin classRepositoryFactorySupport
-
getEntityInformation
- Overrides:
getEntityInformationin classRepositoryFactorySupport
-
getRepositoryFragments
protected RepositoryComposition.RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) - Overrides:
getRepositoryFragmentsin classRepositoryFactorySupport
-
getRepositoryFragments
protected RepositoryComposition.RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata, EntityManager entityManager, EntityPathResolver resolver, CrudMethodMetadata crudMethodMetadata) CreatesRepositoryComposition.RepositoryFragmentsbased onRepositoryMetadatato add JPA-specific extensions. Typically, adds aQuerydslJpaPredicateExecutorif the repository interface uses Querydsl.Built-in fragment contribution can be customized by configuring
JpaRepositoryFragmentsContributor.- 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:
RepositoryComposition.RepositoryFragmentsto be added to the repository.- Since:
- 2.5.1
-