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 Details

    • JpaRepositoryFactory

      public JpaRepositoryFactory(jakarta.persistence.EntityManager entityManager)
      Creates a new JpaRepositoryFactory.
      Parameters:
      entityManager - must not be null
  • Method Details

    • setBeanClassLoader

      public void setBeanClassLoader(ClassLoader classLoader)
      Specified by:
      setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAware
      Overrides:
      setBeanClassLoader in class org.springframework.data.repository.core.support.RepositoryFactorySupport
    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      If a BeanFactory is being set, this is clearly in a Spring context, and so we can capture the QueryRewriterProvider being a BeanFactoryQueryRewriterProvider.
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Overrides:
      setBeanFactory in class org.springframework.data.repository.core.support.RepositoryFactorySupport
      Parameters:
      beanFactory -
      Throws:
      org.springframework.beans.BeansException
    • setEntityPathResolver

      public void setEntityPathResolver(org.springframework.data.querydsl.EntityPathResolver entityPathResolver)
      Configures the EntityPathResolver to be used. Defaults to SimpleEntityPathResolver.INSTANCE.
      Parameters:
      entityPathResolver - must not be null.
    • setEscapeCharacter

      public void setEscapeCharacter(EscapeCharacter escapeCharacter)
      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

      public void setQueryMethodFactory(JpaQueryMethodFactory queryMethodFactory)
      Configures the JpaQueryMethodFactory to be used. Defaults to DefaultJpaQueryMethodFactory.
      Parameters:
      queryMethodFactory - must not be null.
    • setQueryRewriterProvider

      public void setQueryRewriterProvider(QueryRewriterProvider queryRewriterProvider)
      Configures the QueryRewriterProvider to be used. Defaults to instantiate query rewriters through BeanUtils.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 class org.springframework.data.repository.core.support.RepositoryFactorySupport
    • getTargetRepository

      protected JpaRepositoryImplementation<?,?> getTargetRepository(org.springframework.data.repository.core.RepositoryInformation information, jakarta.persistence.EntityManager entityManager)
      Callback to create a JpaRepository instance with the given EntityManager
      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 class org.springframework.data.repository.core.support.RepositoryFactorySupport
    • getProjectionFactory

      protected org.springframework.data.projection.ProjectionFactory getProjectionFactory(ClassLoader classLoader, org.springframework.beans.factory.BeanFactory beanFactory)
      Overrides:
      getProjectionFactory in class org.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 class org.springframework.data.repository.core.support.RepositoryFactorySupport
    • getEntityInformation

      public <T, ID> JpaEntityInformation<T,ID> getEntityInformation(Class<T> domainClass)
      Specified by:
      getEntityInformation in class org.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 class org.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)
      Creates RepositoryComposition.RepositoryFragments based on RepositoryMetadata to add JPA-specific extensions. Typically adds a QuerydslJpaPredicateExecutor 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 a EntityPath.
      crudMethodMetadata - metadata about the invoked CRUD methods.
      Returns:
      Since:
      2.5.1