Browse Source

DATACMNS-1158 - Polishing.

Some code reorganization, polishing of nullable annotations, JavaDoc.

Original pull request: #243.
Related issue: DATAJPA-1173.
pull/262/head
Oliver Gierke 8 years ago
parent
commit
3c96e4e079
  1. 35
      src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java
  2. 6
      src/main/java/org/springframework/data/util/Pair.java

35
src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java

@ -34,7 +34,6 @@ import java.util.stream.Collectors; @@ -34,7 +34,6 @@ import java.util.stream.Collectors;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.jetbrains.annotations.NotNull;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.beans.BeanUtils;
@ -315,10 +314,9 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, @@ -315,10 +314,9 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
postProcessors.forEach(processor -> processor.postProcess(result, information));
result.addAdvice(new DefaultMethodInvokingMethodInterceptor());
result.addAdvice(new QueryExecutorMethodInterceptor( //
information, //
getProjectionFactory(classLoader, beanFactory) //
));
ProjectionFactory projectionFactory = getProjectionFactory(classLoader, beanFactory);
result.addAdvice(new QueryExecutorMethodInterceptor(information, projectionFactory));
composition = composition.append(RepositoryFragment.implemented(target));
result.addAdvice(new ImplementationMethodExecutionInterceptor(composition));
@ -326,7 +324,13 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, @@ -326,7 +324,13 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
return (T) result.getProxy(classLoader);
}
@NotNull
/**
* Returns the {@link ProjectionFactory} to be used with the repository instances created.
*
* @param classLoader will never be {@literal null}.
* @param beanFactory will never be {@literal null}.
* @return will never be {@literal null}.
*/
protected ProjectionFactory getProjectionFactory(ClassLoader classLoader, BeanFactory beanFactory) {
SpelAwareProxyProjectionFactory factory = new SpelAwareProxyProjectionFactory();
@ -532,22 +536,25 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, @@ -532,22 +536,25 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
+ "infrastructure apparently does not support query methods!");
}
this.queries = lookupStrategy.map( //
it -> mapMethodsToQuery(repositoryInformation, projectionFactory, it) //
).orElse(Collections.emptyMap());
this.queries = lookupStrategy //
.map(it -> mapMethodsToQuery(repositoryInformation, it, projectionFactory)) //
.orElse(Collections.emptyMap());
}
private Map<Method, RepositoryQuery> mapMethodsToQuery(RepositoryInformation repositoryInformation,
ProjectionFactory projectionFactory, QueryLookupStrategy lookupStrategy) {
QueryLookupStrategy lookupStrategy, ProjectionFactory projectionFactory) {
return repositoryInformation.getQueryMethods().stream() //
.map(method -> Pair.of( //
method, //
lookupStrategy.resolveQuery(method, repositoryInformation, projectionFactory, namedQueries))) //
.map(method -> lookupQuery(method, repositoryInformation, lookupStrategy, projectionFactory)) //
.peek(pair -> invokeListeners(pair.getSecond())) //
.collect(Pair.toMap());
}
private Pair<Method, RepositoryQuery> lookupQuery(Method method, RepositoryInformation information,
QueryLookupStrategy strategy, ProjectionFactory projectionFactory) {
return Pair.of(method, strategy.resolveQuery(method, information, projectionFactory, namedQueries));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void invokeListeners(RepositoryQuery query) {
@ -580,6 +587,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, @@ -580,6 +587,7 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
return resultHandler.postProcessInvocationResult(result, methodReturnTypeDescriptor);
}
@Nullable
private Object doInvoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
@ -603,7 +611,6 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware, @@ -603,7 +611,6 @@ public abstract class RepositoryFactorySupport implements BeanClassLoaderAware,
}
}
/**
* Method interceptor that calls methods on the {@link RepositoryComposition}.
*

6
src/main/java/org/springframework/data/util/Pair.java

@ -24,6 +24,7 @@ import lombok.ToString; @@ -24,6 +24,7 @@ import lombok.ToString;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* A tuple of things.
@ -72,6 +73,11 @@ public final class Pair<S, T> { @@ -72,6 +73,11 @@ public final class Pair<S, T> {
return second;
}
/**
* A collector to create a {@link Map} from a {@link Stream} of {@link Pair}s.
*
* @return
*/
public static <S, T> Collector<Pair<S, T>, ?, Map<S, T>> toMap() {
return Collectors.toMap(Pair::getFirst, Pair::getSecond);
}

Loading…
Cancel
Save