Search in sources :

Example 1 with DefaultMethodInvokingMethodInterceptor

use of org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor in project spring-data-commons by spring-projects.

the class RepositoryFactorySupport method getRepository.

/**
 * Returns a repository instance for the given interface backed by an instance providing implementation logic for
 * custom logic.
 *
 * @param repositoryInterface must not be {@literal null}.
 * @param fragments must not be {@literal null}.
 * @return
 * @since 2.0
 */
@SuppressWarnings({ "unchecked" })
public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fragments) {
    Assert.notNull(repositoryInterface, "Repository interface must not be null!");
    Assert.notNull(fragments, "RepositoryFragments must not be null!");
    RepositoryMetadata metadata = getRepositoryMetadata(repositoryInterface);
    RepositoryComposition composition = getRepositoryComposition(metadata, fragments);
    RepositoryInformation information = getRepositoryInformation(metadata, composition);
    validate(information, composition);
    Object target = getTargetRepository(information);
    // Create proxy
    ProxyFactory result = new ProxyFactory();
    result.setTarget(target);
    result.setInterfaces(repositoryInterface, Repository.class, TransactionalProxy.class);
    if (MethodInvocationValidator.supports(repositoryInterface)) {
        result.addAdvice(new MethodInvocationValidator());
    }
    result.addAdvice(SurroundingTransactionDetectorMethodInterceptor.INSTANCE);
    result.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    postProcessors.forEach(processor -> processor.postProcess(result, information));
    result.addAdvice(new DefaultMethodInvokingMethodInterceptor());
    ProjectionFactory projectionFactory = getProjectionFactory(classLoader, beanFactory);
    result.addAdvice(new QueryExecutorMethodInterceptor(information, projectionFactory));
    composition = composition.append(RepositoryFragment.implemented(target));
    result.addAdvice(new ImplementationMethodExecutionInterceptor(composition));
    return (T) result.getProxy(classLoader);
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) ProjectionFactory(org.springframework.data.projection.ProjectionFactory) ProxyFactory(org.springframework.aop.framework.ProxyFactory) RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) DefaultMethodInvokingMethodInterceptor(org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation)

Aggregations

ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 DefaultMethodInvokingMethodInterceptor (org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor)1 ProjectionFactory (org.springframework.data.projection.ProjectionFactory)1 SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)1 RepositoryInformation (org.springframework.data.repository.core.RepositoryInformation)1 RepositoryMetadata (org.springframework.data.repository.core.RepositoryMetadata)1