Search in sources :

Example 56 with RepositoryMetadata

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

the class AbstractRepositoryMetadataUnitTests method discoversSimpleReturnTypeCorrectly.

// DATACMNS-98
@Test
public void discoversSimpleReturnTypeCorrectly() throws Exception {
    RepositoryMetadata metadata = new DummyRepositoryMetadata(UserRepository.class);
    Method method = UserRepository.class.getMethod("findSingle");
    assertThat(metadata.getReturnedDomainClass(method)).isEqualTo(User.class);
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 57 with RepositoryMetadata

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

the class AbstractRepositoryMetadataUnitTests method nonPageableRepository.

// DATACMNS-453
@Test
public void nonPageableRepository() {
    RepositoryMetadata metadata = new DummyRepositoryMetadata(UserRepository.class);
    assertThat(metadata.isPagingRepository()).isFalse();
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Test(org.junit.Test)

Example 58 with RepositoryMetadata

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

the class AbstractRepositoryMetadataUnitTests method detectsArrayReturnTypeCorrectly.

// DATACMNS-471
@Test
public void detectsArrayReturnTypeCorrectly() throws Exception {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(PagedRepository.class);
    Method method = PagedRepository.class.getMethod("returnsArray");
    assertThat(metadata.getReturnedDomainClass(method)).isEqualTo(User.class);
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 59 with RepositoryMetadata

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

Example 60 with RepositoryMetadata

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

the class RepositoryConfigurationExtensionSupport method getRepositoryConfigurations.

/*
	 *
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryConfigurations(org.springframework.data.repository.config.RepositoryConfigurationSource, org.springframework.core.io.ResourceLoader, boolean)
	 */
public <T extends RepositoryConfigurationSource> Collection<RepositoryConfiguration<T>> getRepositoryConfigurations(T configSource, ResourceLoader loader, boolean strictMatchesOnly) {
    Assert.notNull(configSource, "ConfigSource must not be null!");
    Assert.notNull(loader, "Loader must not be null!");
    Set<RepositoryConfiguration<T>> result = new HashSet<>();
    for (BeanDefinition candidate : configSource.getCandidates(loader)) {
        RepositoryConfiguration<T> configuration = getRepositoryConfiguration(candidate, configSource);
        Class<?> repositoryInterface = loadRepositoryInterface(configuration, getConfigurationInspectionClassLoader(loader));
        if (repositoryInterface == null) {
            result.add(configuration);
            continue;
        }
        RepositoryMetadata metadata = AbstractRepositoryMetadata.getMetadata(repositoryInterface);
        if (!useRepositoryConfiguration(metadata)) {
            continue;
        }
        if (!strictMatchesOnly || configSource.usesExplicitFilters()) {
            result.add(configuration);
            continue;
        }
        if (isStrictRepositoryCandidate(metadata)) {
            result.add(configuration);
        }
    }
    return result;
}
Also used : AbstractRepositoryMetadata(org.springframework.data.repository.core.support.AbstractRepositoryMetadata) RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) HashSet(java.util.HashSet)

Aggregations

RepositoryMetadata (org.springframework.data.repository.core.RepositoryMetadata)60 Test (org.junit.Test)52 Method (java.lang.reflect.Method)37 RepositoryInformation (org.springframework.data.repository.core.RepositoryInformation)17 DefaultRepositoryMetadata (org.springframework.data.repository.core.support.DefaultRepositoryMetadata)16 AbstractRepositoryMetadata (org.springframework.data.repository.core.support.AbstractRepositoryMetadata)4 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)3 ProjectionFactory (org.springframework.data.projection.ProjectionFactory)3 DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)3 SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 SpelQueryCreator (org.springframework.data.keyvalue.repository.query.SpelQueryCreator)1 DefaultMethodInvokingMethodInterceptor (org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor)1 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)1 QueryMethod (org.springframework.data.repository.query.QueryMethod)1