DATACMNS-1117 - Fixed creation of RepositoryInformation in RepositoryFactoryBeanSupport.

RepositoryFactoryBeanSupport.getRepositoryInformation() previously didn't consider any store-specific compositions (incl. store-specific fragments like the Querydsl support) as it just handed a fragment with the custom implementation to RepositoryFactorySupport.

This is now fixed by improving the API in RepositoryFactorySupport which now exposes a getRepositoryInformation(RepositoryMetadata, RepositoryFragments) which creates a fresh RepositoryComposition from the given RepositoryMetadata. Intermediate setup methods are still kept around but private as RepositoryFactorySupport.getRepository(…) still needs to forward the base RepositoryComposition to method interceptors for query result mapping.
This commit is contained in:
Oliver Gierke
2017-07-20 10:14:57 +02:00
parent dfcb9f77a4
commit 7ee5ae446b
4 changed files with 79 additions and 14 deletions

View File

@@ -202,8 +202,11 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
* @see org.springframework.data.repository.core.support.RepositoryFactoryInformation#getRepositoryInformation()
*/
public RepositoryInformation getRepositoryInformation() {
return this.factory.getRepositoryInformation(repositoryMetadata,
customImplementation.map(RepositoryComposition::just).orElse(RepositoryComposition.empty()));
RepositoryFragments fragments = customImplementation.map(RepositoryFragments::just)//
.orElse(RepositoryFragments.empty());
return factory.getRepositoryInformation(repositoryMetadata, fragments);
}
/*
@@ -216,7 +219,8 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
.getRequiredPersistentEntity(repositoryMetadata.getDomainType());
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.support.RepositoryFactoryInformation#getQueryMethods()
*/
public List<QueryMethod> getQueryMethods() {

View File

@@ -235,7 +235,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
* @param metadata
* @return
*/
protected RepositoryComposition getRepositoryComposition(RepositoryMetadata metadata) {
private RepositoryComposition getRepositoryComposition(RepositoryMetadata metadata) {
RepositoryComposition composition = RepositoryComposition.empty();
@@ -288,13 +288,10 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
Assert.notNull(fragments, "RepositoryFragments must not be null!");
RepositoryMetadata metadata = getRepositoryMetadata(repositoryInterface);
RepositoryComposition composition = getRepositoryComposition(metadata);
RepositoryFragments repositoryAspects = getRepositoryFragments(metadata);
RepositoryComposition composition = getRepositoryComposition(metadata, fragments);
RepositoryInformation information = getRepositoryInformation(metadata, composition);
RepositoryComposition compositionToUse = composition.append(fragments).append(repositoryAspects);
RepositoryInformation information = getRepositoryInformation(metadata, compositionToUse);
validate(information, compositionToUse);
validate(information, composition);
Object target = getTargetRepository(information);
@@ -311,8 +308,8 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
result.addAdvice(new DefaultMethodInvokingMethodInterceptor());
result.addAdvice(new QueryExecutorMethodInterceptor(information));
compositionToUse = compositionToUse.append(RepositoryFragment.implemented(target));
result.addAdvice(new ImplementationMethodExecutionInterceptor(compositionToUse));
composition = composition.append(RepositoryFragment.implemented(target));
result.addAdvice(new ImplementationMethodExecutionInterceptor(composition));
return (T) result.getProxy(classLoader);
}
@@ -327,6 +324,37 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
return AbstractRepositoryMetadata.getMetadata(repositoryInterface);
}
/**
* Returns the {@link RepositoryInformation} for the given {@link RepositoryMetadata} and custom
* {@link RepositoryFragments}.
*
* @param metadata must not be {@literal null}.
* @param fragments must not be {@literal null}.
* @return will never be {@literal null}.
*/
protected RepositoryInformation getRepositoryInformation(RepositoryMetadata metadata, RepositoryFragments fragments) {
return getRepositoryInformation(metadata, getRepositoryComposition(metadata, fragments));
}
/**
* Returns the {@link RepositoryComposition} for the given {@link RepositoryMetadata} and extra
* {@link RepositoryFragments}.
*
* @param metadata must not be {@literal null}.
* @param fragments must not be {@literal null}.
* @return will never be {@literal null}.
*/
private RepositoryComposition getRepositoryComposition(RepositoryMetadata metadata, RepositoryFragments fragments) {
Assert.notNull(metadata, "RepositoryMetadata must not be null!");
Assert.notNull(fragments, "RepositoryFragments must not be null!");
RepositoryComposition composition = getRepositoryComposition(metadata);
RepositoryFragments repositoryAspects = getRepositoryFragments(metadata);
return composition.append(fragments).append(repositoryAspects);
}
/**
* Returns the {@link RepositoryInformation} for the given repository interface.
*
@@ -334,7 +362,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
* @param composition
* @return
*/
protected RepositoryInformation getRepositoryInformation(RepositoryMetadata metadata,
private RepositoryInformation getRepositoryInformation(RepositoryMetadata metadata,
RepositoryComposition composition) {
RepositoryInformationCacheKey cacheKey = new RepositoryInformationCacheKey(metadata, composition);