Search in sources :

Example 11 with RepositoryInformation

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

the class Repositories method cacheRepositoryFactory.

@SuppressWarnings({ "rawtypes", "unchecked" })
private synchronized void cacheRepositoryFactory(String name) {
    RepositoryFactoryInformation repositoryFactoryInformation = beanFactory.get().getBean(name, RepositoryFactoryInformation.class);
    Class<?> domainType = ClassUtils.getUserClass(repositoryFactoryInformation.getRepositoryInformation().getDomainType());
    RepositoryInformation information = repositoryFactoryInformation.getRepositoryInformation();
    Set<Class<?>> alternativeDomainTypes = information.getAlternativeDomainTypes();
    String beanName = BeanFactoryUtils.transformedBeanName(name);
    Set<Class<?>> typesToRegister = new HashSet<>(alternativeDomainTypes.size() + 1);
    typesToRegister.add(domainType);
    typesToRegister.addAll(alternativeDomainTypes);
    for (Class<?> type : typesToRegister) {
        this.repositoryFactoryInfos.put(type, repositoryFactoryInformation);
        this.repositoryBeanNames.put(type, beanName);
    }
}
Also used : RepositoryFactoryInformation(org.springframework.data.repository.core.support.RepositoryFactoryInformation) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) HashSet(java.util.HashSet)

Example 12 with RepositoryInformation

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

the class RepositoryFactorySupportUnitTests method rejectsRepositoryBaseClassWithInvalidConstructor.

// DATACMNS-763
@Test
@SuppressWarnings("rawtypes")
public void rejectsRepositoryBaseClassWithInvalidConstructor() {
    RepositoryInformation information = mock(RepositoryInformation.class);
    doReturn(CustomRepositoryBaseClass.class).when(information).getRepositoryBaseClass();
    EntityInformation entityInformation = mock(EntityInformation.class);
    exception.expect(IllegalStateException.class);
    exception.expectMessage(entityInformation.getClass().getName());
    exception.expectMessage(String.class.getName());
    factory.getTargetRepositoryViaReflection(information, entityInformation, "Foo");
}
Also used : EntityInformation(org.springframework.data.repository.core.EntityInformation) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 13 with RepositoryInformation

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

the class DefaultCrudMethodsUnitTests method getMethodsFor.

private static CrudMethods getMethodsFor(Class<?> repositoryInterface) {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(repositoryInterface);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, PagingAndSortingRepository.class, RepositoryComposition.empty());
    return new DefaultCrudMethods(information);
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation)

Example 14 with RepositoryInformation

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

the class DefaultRepositoryInformationUnitTests method usesCorrectSaveOverload.

// DATACMNS-943
@Test
public void usesCorrectSaveOverload() throws Exception {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(DummyRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, DummyRepositoryImpl.class, RepositoryComposition.empty());
    Method method = DummyRepository.class.getMethod("saveAll", Iterable.class);
    assertThat(information.getTargetClassMethod(method)).isEqualTo(DummyRepositoryImpl.class.getMethod("saveAll", Iterable.class));
}
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 15 with RepositoryInformation

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

the class DefaultRepositoryInformationUnitTests method ignoresStaticMethod.

// DATACMNS-939
@Test
public void ignoresStaticMethod() throws SecurityException, NoSuchMethodException {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.just(customImplementation));
    Method method = FooRepository.class.getMethod("staticMethod");
    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)

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