org.springframework.data.repository.core.support

## Class RepositoryFactorySupport

- java.lang.Object
- - org.springframework.data.repository.core.support.RepositoryFactorySupport

All Implemented Interfaces:
  Aware, BeanClassLoaderAware, BeanFactoryAware

Direct Known Subclasses:
  ReactiveRepositoryFactorySupport

    public abstract class RepositoryFactorySupport
    extends Object
    implements BeanClassLoaderAware, BeanFactoryAware

Factory bean to create instances of a given repository interface. Creates a proxy implementing the configured repository interface and apply an advice handing the control to the `QueryExecutorMethodInterceptor`. Query detection strategy can be configured by setting `QueryLookupStrategy.Key`.

Author:
  Oliver Gierke, Mark Paluch, Christoph Strobl, Jens Schauder, John Blum

### Constructor Summary

Constructors
Constructor and Description
`RepositoryFactorySupport()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`void` `addInvocationListener(RepositoryMethodInvocationListener listener)` Adds a `RepositoryMethodInvocationListener` to the factory to plug in functionality triggered right after running `query methods` and `fragment methods`.
`void` `addQueryCreationListener(QueryCreationListener<?> listener)` Adds a `QueryCreationListener` to the factory to plug in functionality triggered right after creation of `RepositoryQuery` instances.
`void` `addRepositoryProxyPostProcessor(RepositoryProxyPostProcessor processor)` Adds `RepositoryProxyPostProcessor`s to the factory to allow manipulation of the `ProxyFactory` before the proxy gets created.
`abstract <T,ID> EntityInformation<T,ID>` `getEntityInformation(Class<T> domainClass)` Returns the `EntityInformation` for the given domain class.
`protected ProjectionFactory` `getProjectionFactory(ClassLoader classLoader, BeanFactory beanFactory)` Returns the `ProjectionFactory` to be used with the repository instances created.
`protected Optional<QueryLookupStrategy>` `getQueryLookupStrategy(QueryLookupStrategy.Key key, QueryMethodEvaluationContextProvider evaluationContextProvider)` Returns the `QueryLookupStrategy` for the given `QueryLookupStrategy.Key` and `QueryMethodEvaluationContextProvider`.
`protected List<QueryMethod>` `getQueryMethods()`
`<T> T` `getRepository(Class<T> repositoryInterface)` Returns a repository instance for the given interface.
`<T> T` `getRepository(Class<T> repositoryInterface, Object customImplementation)` Returns a repository instance for the given interface backed by a single instance providing implementation logic for custom logic.
`<T> T` `getRepository(Class<T> repositoryInterface, RepositoryComposition.RepositoryFragments fragments)` Returns a repository instance for the given interface backed by an instance providing implementation logic for custom logic.
`protected abstract Class<?>` `getRepositoryBaseClass(RepositoryMetadata metadata)` Returns the base class backing the actual repository instance.
`protected RepositoryComposition.RepositoryFragments` `getRepositoryFragments(RepositoryMetadata metadata)` Creates `RepositoryComposition.RepositoryFragments` based on `RepositoryMetadata` to add repository-specific extensions.
`protected RepositoryInformation` `getRepositoryInformation(RepositoryMetadata metadata, RepositoryComposition.RepositoryFragments fragments)` Returns the `RepositoryInformation` for the given `RepositoryMetadata` and custom `RepositoryComposition.RepositoryFragments`.
`protected RepositoryMetadata` `getRepositoryMetadata(Class<?> repositoryInterface)` Returns the `RepositoryMetadata` for the given repository interface.
`protected abstract Object` `getTargetRepository(RepositoryInformation metadata)` Create a repository instance as backing for the query proxy.
`protected <R> R` `getTargetRepositoryViaReflection(Class<?> baseClass, Object... constructorArguments)` Creates a repository of the repository base class defined in the given `RepositoryInformation` using reflection.
`protected <R> R` `getTargetRepositoryViaReflection(RepositoryInformation information, Object... constructorArguments)` Creates a repository of the repository base class defined in the given `RepositoryInformation` using reflection.
`void` `setBeanClassLoader(ClassLoader classLoader)`
`void` `setBeanFactory(BeanFactory beanFactory)`
`void` `setEvaluationContextProvider(QueryMethodEvaluationContextProvider evaluationContextProvider)` Sets the `QueryMethodEvaluationContextProvider` to be used to evaluate SpEL expressions in manually defined queries.
`void` `setNamedQueries(NamedQueries namedQueries)` Configures a `NamedQueries` instance to be handed to the `QueryLookupStrategy` for query creation.
`void` `setQueryLookupStrategyKey(QueryLookupStrategy.Key key)` Sets the strategy of how to lookup a query to execute finders.
`void` `setRepositoryBaseClass(Class<?> repositoryBaseClass)` Configures the repository base class to use when creating the repository proxy.
`protected void` `validate(RepositoryMetadata repositoryMetadata)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### RepositoryFactorySupport

    public RepositoryFactorySupport()

### Method Detail

#### setQueryLookupStrategyKey

    public void setQueryLookupStrategyKey(QueryLookupStrategy.Key key)

Sets the strategy of how to lookup a query to execute finders.

Parameters:
  `key` -

#### setNamedQueries

    public void setNamedQueries(NamedQueries namedQueries)

Configures a `NamedQueries` instance to be handed to the `QueryLookupStrategy` for query creation.

Parameters:
  `namedQueries` - the namedQueries to set

#### setBeanClassLoader

    public void setBeanClassLoader(ClassLoader classLoader)

Specified by:
  `setBeanClassLoader` in interface `BeanClassLoaderAware`

#### setBeanFactory

    public void setBeanFactory(BeanFactory beanFactory)
                        throws BeansException

Specified by:
  `setBeanFactory` in interface `BeanFactoryAware`
Throws:
  `BeansException`

#### setEvaluationContextProvider

    public void setEvaluationContextProvider(QueryMethodEvaluationContextProvider evaluationContextProvider)

Sets the `QueryMethodEvaluationContextProvider` to be used to evaluate SpEL expressions in manually defined queries.

Parameters:
  `evaluationContextProvider` - can be null, defaults to `QueryMethodEvaluationContextProvider#INSTANCE`.

#### setRepositoryBaseClass

    public void setRepositoryBaseClass(Class<?> repositoryBaseClass)

Configures the repository base class to use when creating the repository proxy. If not set, the factory will use the type returned by `getRepositoryBaseClass(RepositoryMetadata)` by default.

Parameters:
  `repositoryBaseClass` - the repository base class to back the repository proxy, can be null.
Since:
  1.11

#### addQueryCreationListener

    public void addQueryCreationListener(QueryCreationListener<?> listener)

Adds a `QueryCreationListener` to the factory to plug in functionality triggered right after creation of `RepositoryQuery` instances.

Parameters:
  `listener` -

#### addInvocationListener

    public void addInvocationListener(RepositoryMethodInvocationListener listener)

Adds a `RepositoryMethodInvocationListener` to the factory to plug in functionality triggered right after running `query methods` and `fragment methods`.

Parameters:
  `listener` -
Since:
  2.4

#### addRepositoryProxyPostProcessor

    public void addRepositoryProxyPostProcessor(RepositoryProxyPostProcessor processor)

Adds `RepositoryProxyPostProcessor`s to the factory to allow manipulation of the `ProxyFactory` before the proxy gets created. Note that the `QueryExecutorMethodInterceptor` will be added to the proxy after the `RepositoryProxyPostProcessor`s are considered.

Parameters:
  `processor` -

#### getRepositoryFragments

    protected RepositoryComposition.RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata)

Creates `RepositoryComposition.RepositoryFragments` based on `RepositoryMetadata` to add repository-specific extensions.

Parameters:
  `metadata` -
Returns:

#### getRepository

    public <T> T getRepository(Class<T> repositoryInterface)

Returns a repository instance for the given interface.

Parameters:
  `repositoryInterface` - must not be null.
Returns:

#### getRepository

    public <T> T getRepository(Class<T> repositoryInterface,
                               Object customImplementation)

Returns a repository instance for the given interface backed by a single instance providing implementation logic for custom logic. For more advanced composition needs use `#getRepository(Class, RepositoryFragments)`.

Parameters:
  `repositoryInterface` - must not be null.
  `customImplementation` - must not be null.
Returns:

#### getRepository

    public <T> T getRepository(Class<T> repositoryInterface,
                               RepositoryComposition.RepositoryFragments fragments)

Returns a repository instance for the given interface backed by an instance providing implementation logic for custom logic.

Parameters:
  `repositoryInterface` - must not be null.
  `fragments` - must not be null.
Returns:
Since:
  2.0

#### getProjectionFactory

    protected ProjectionFactory getProjectionFactory(ClassLoader classLoader,
                                                     BeanFactory beanFactory)

Returns the `ProjectionFactory` to be used with the repository instances created.

Parameters:
  `classLoader` - will never be null.
  `beanFactory` - will never be null.
Returns:
  will never be null.

#### getRepositoryMetadata

    protected RepositoryMetadata getRepositoryMetadata(Class<?> repositoryInterface)

Returns the `RepositoryMetadata` for the given repository interface.

Parameters:
  `repositoryInterface` - will never be null.
Returns:

#### getRepositoryInformation

    protected RepositoryInformation getRepositoryInformation(RepositoryMetadata metadata,
                                                             RepositoryComposition.RepositoryFragments fragments)

Returns the `RepositoryInformation` for the given `RepositoryMetadata` and custom `RepositoryComposition.RepositoryFragments`.

Parameters:
  `metadata` - must not be null.
  `fragments` - must not be null.
Returns:
  will never be null.

#### getQueryMethods

    protected List<QueryMethod> getQueryMethods()

#### getEntityInformation

    public abstract <T,ID> EntityInformation<T,ID> getEntityInformation(Class<T> domainClass)

Returns the `EntityInformation` for the given domain class.

Type Parameters:
  `T` - the entity type
  `ID` - the id type
Parameters:
  `domainClass` -
Returns:

#### getTargetRepository

    protected abstract Object getTargetRepository(RepositoryInformation metadata)

Create a repository instance as backing for the query proxy.

Parameters:
  `metadata` -
Returns:

#### getRepositoryBaseClass

    protected abstract Class<?> getRepositoryBaseClass(RepositoryMetadata metadata)

Returns the base class backing the actual repository instance. Make sure `getTargetRepository(RepositoryInformation)` returns an instance of this class.

Parameters:
  `metadata` -
Returns:

#### getQueryLookupStrategy

    protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable
                                                                   QueryLookupStrategy.Key key,
                                                                   QueryMethodEvaluationContextProvider evaluationContextProvider)

Returns the `QueryLookupStrategy` for the given `QueryLookupStrategy.Key` and `QueryMethodEvaluationContextProvider`.

Parameters:
  `key` - can be null.
  `evaluationContextProvider` - will never be null.
Returns:
  the `QueryLookupStrategy` to use or null if no queries should be looked up.
Since:
  1.9

#### validate

    protected void validate(RepositoryMetadata repositoryMetadata)

#### getTargetRepositoryViaReflection

    protected final <R> R getTargetRepositoryViaReflection(RepositoryInformation information,
                                                           Object... constructorArguments)

Creates a repository of the repository base class defined in the given `RepositoryInformation` using reflection.

Parameters:
  `information` -
  `constructorArguments` -
Returns:

#### getTargetRepositoryViaReflection

    protected final <R> R getTargetRepositoryViaReflection(Class<?> baseClass,
                                                           Object... constructorArguments)

Creates a repository of the repository base class defined in the given `RepositoryInformation` using reflection.

Parameters:
  `baseClass` -
  `constructorArguments` -
Returns: