Skip to content

Commit 3c96e4e

Browse files
committed
DATACMNS-1158 - Polishing.
Some code reorganization, polishing of nullable annotations, JavaDoc. Original pull request: #243. Related issue: DATAJPA-1173.
1 parent 300f3cf commit 3c96e4e

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import org.aopalliance.intercept.MethodInterceptor;
3636
import org.aopalliance.intercept.MethodInvocation;
37-
import org.jetbrains.annotations.NotNull;
3837
import org.springframework.aop.framework.ProxyFactory;
3938
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
4039
import org.springframework.beans.BeanUtils;
@@ -315,18 +314,23 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
315314
postProcessors.forEach(processor -> processor.postProcess(result, information));
316315

317316
result.addAdvice(new DefaultMethodInvokingMethodInterceptor());
318-
result.addAdvice(new QueryExecutorMethodInterceptor( //
319-
information, //
320-
getProjectionFactory(classLoader, beanFactory) //
321-
));
317+
318+
ProjectionFactory projectionFactory = getProjectionFactory(classLoader, beanFactory);
319+
result.addAdvice(new QueryExecutorMethodInterceptor(information, projectionFactory));
322320

323321
composition = composition.append(RepositoryFragment.implemented(target));
324322
result.addAdvice(new ImplementationMethodExecutionInterceptor(composition));
325323

326324
return (T) result.getProxy(classLoader);
327325
}
328326

329-
@NotNull
327+
/**
328+
* Returns the {@link ProjectionFactory} to be used with the repository instances created.
329+
*
330+
* @param classLoader will never be {@literal null}.
331+
* @param beanFactory will never be {@literal null}.
332+
* @return will never be {@literal null}.
333+
*/
330334
protected ProjectionFactory getProjectionFactory(ClassLoader classLoader, BeanFactory beanFactory) {
331335

332336
SpelAwareProxyProjectionFactory factory = new SpelAwareProxyProjectionFactory();
@@ -532,22 +536,25 @@ public QueryExecutorMethodInterceptor(RepositoryInformation repositoryInformatio
532536
+ "infrastructure apparently does not support query methods!");
533537
}
534538

535-
this.queries = lookupStrategy.map( //
536-
it -> mapMethodsToQuery(repositoryInformation, projectionFactory, it) //
537-
).orElse(Collections.emptyMap());
539+
this.queries = lookupStrategy //
540+
.map(it -> mapMethodsToQuery(repositoryInformation, it, projectionFactory)) //
541+
.orElse(Collections.emptyMap());
538542
}
539543

540544
private Map<Method, RepositoryQuery> mapMethodsToQuery(RepositoryInformation repositoryInformation,
541-
ProjectionFactory projectionFactory, QueryLookupStrategy lookupStrategy) {
545+
QueryLookupStrategy lookupStrategy, ProjectionFactory projectionFactory) {
542546

543547
return repositoryInformation.getQueryMethods().stream() //
544-
.map(method -> Pair.of( //
545-
method, //
546-
lookupStrategy.resolveQuery(method, repositoryInformation, projectionFactory, namedQueries))) //
548+
.map(method -> lookupQuery(method, repositoryInformation, lookupStrategy, projectionFactory)) //
547549
.peek(pair -> invokeListeners(pair.getSecond())) //
548550
.collect(Pair.toMap());
549551
}
550552

553+
private Pair<Method, RepositoryQuery> lookupQuery(Method method, RepositoryInformation information,
554+
QueryLookupStrategy strategy, ProjectionFactory projectionFactory) {
555+
return Pair.of(method, strategy.resolveQuery(method, information, projectionFactory, namedQueries));
556+
}
557+
551558
@SuppressWarnings({ "rawtypes", "unchecked" })
552559
private void invokeListeners(RepositoryQuery query) {
553560

@@ -580,6 +587,7 @@ public Object invoke(@SuppressWarnings("null") MethodInvocation invocation) thro
580587
return resultHandler.postProcessInvocationResult(result, methodReturnTypeDescriptor);
581588
}
582589

590+
@Nullable
583591
private Object doInvoke(MethodInvocation invocation) throws Throwable {
584592

585593
Method method = invocation.getMethod();
@@ -603,7 +611,6 @@ private boolean hasQueryFor(Method method) {
603611
}
604612
}
605613

606-
607614
/**
608615
* Method interceptor that calls methods on the {@link RepositoryComposition}.
609616
*

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Map;
2525
import java.util.stream.Collector;
2626
import java.util.stream.Collectors;
27+
import java.util.stream.Stream;
2728

2829
/**
2930
* A tuple of things.
@@ -72,6 +73,11 @@ public T getSecond() {
7273
return second;
7374
}
7475

76+
/**
77+
* A collector to create a {@link Map} from a {@link Stream} of {@link Pair}s.
78+
*
79+
* @return
80+
*/
7581
public static <S, T> Collector<Pair<S, T>, ?, Map<S, T>> toMap() {
7682
return Collectors.toMap(Pair::getFirst, Pair::getSecond);
7783
}

0 commit comments

Comments
 (0)