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);
}
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();
}
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);
}
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);
}
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;
}
Aggregations