Search in sources :

Example 21 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation in project spring-data-commons by spring-projects.

the class DefaultRepositoryInformationUnitTests method doesNotConsiderManuallyDefinedSaveMethodAQueryMethod.

// DATACMNS-151
@Test
public void doesNotConsiderManuallyDefinedSaveMethodAQueryMethod() {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(CustomRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, PagingAndSortingRepository.class, RepositoryComposition.empty());
    assertThat(information.getQueryMethods()).isEmpty();
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 22 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation in project spring-data-commons by spring-projects.

the class DefaultRepositoryInformationUnitTests method ignoresDefaultMethod.

// DATACMNS-939
@Test
public void ignoresDefaultMethod() throws SecurityException, NoSuchMethodException {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.just(customImplementation));
    Method method = FooRepository.class.getMethod("defaultMethod");
    assertThat(information.getQueryMethods()).doesNotContain(method);
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 23 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation in project spring-data-commons by spring-projects.

the class EventPublishingRepositoryProxyPostProcessorUnitTests method registersAdviceIfDomainTypeExposesEvents.

// DATACMNS-928
@Test
public void registersAdviceIfDomainTypeExposesEvents() {
    RepositoryInformation information = new DummyRepositoryInformation(SampleRepository.class);
    RepositoryProxyPostProcessor processor = new EventPublishingRepositoryProxyPostProcessor(publisher);
    ProxyFactory factory = mock(ProxyFactory.class);
    processor.postProcess(factory, information);
    verify(factory).addAdvice(any(EventPublishingMethodInterceptor.class));
}
Also used : EventPublishingMethodInterceptor(org.springframework.data.repository.core.support.EventPublishingRepositoryProxyPostProcessor.EventPublishingMethodInterceptor) ProxyFactory(org.springframework.aop.framework.ProxyFactory) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 24 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation in project spring-data-commons by spring-projects.

the class RepositoryFactoryBeanSupportUnitTests method returnsRepositoryInformationForFragmentSetup.

// DATACMNS-1117
@Test
public void returnsRepositoryInformationForFragmentSetup() {
    // 
    RepositoryFactoryBeanSupport<SampleWithQuerydslRepository, Object, Long> factoryBean = new DummyRepositoryFactoryBean<>(SampleWithQuerydslRepository.class);
    factoryBean.afterPropertiesSet();
    RepositoryInformation information = factoryBean.getRepositoryInformation();
    assertThat(information.getQueryMethods()).isEmpty();
}
Also used : RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 25 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation 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

RepositoryInformation (org.springframework.data.repository.core.RepositoryInformation)26 Test (org.junit.Test)22 RepositoryMetadata (org.springframework.data.repository.core.RepositoryMetadata)17 Method (java.lang.reflect.Method)13 ProxyFactory (org.springframework.aop.framework.ProxyFactory)3 HashSet (java.util.HashSet)1 Advice (org.aopalliance.aop.Advice)1 Before (org.junit.Before)1 DefaultMethodInvokingMethodInterceptor (org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor)1 ProjectionFactory (org.springframework.data.projection.ProjectionFactory)1 SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)1 EntityInformation (org.springframework.data.repository.core.EntityInformation)1 EventPublishingMethodInterceptor (org.springframework.data.repository.core.support.EventPublishingRepositoryProxyPostProcessor.EventPublishingMethodInterceptor)1 RepositoryFactoryInformation (org.springframework.data.repository.core.support.RepositoryFactoryInformation)1 QueryByExampleExecutor (org.springframework.data.repository.query.QueryByExampleExecutor)1