34
34
35
35
import org .aopalliance .intercept .MethodInterceptor ;
36
36
import org .aopalliance .intercept .MethodInvocation ;
37
- import org .jetbrains .annotations .NotNull ;
38
37
import org .springframework .aop .framework .ProxyFactory ;
39
38
import org .springframework .aop .interceptor .ExposeInvocationInterceptor ;
40
39
import org .springframework .beans .BeanUtils ;
@@ -315,18 +314,23 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
315
314
postProcessors .forEach (processor -> processor .postProcess (result , information ));
316
315
317
316
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 ));
322
320
323
321
composition = composition .append (RepositoryFragment .implemented (target ));
324
322
result .addAdvice (new ImplementationMethodExecutionInterceptor (composition ));
325
323
326
324
return (T ) result .getProxy (classLoader );
327
325
}
328
326
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
+ */
330
334
protected ProjectionFactory getProjectionFactory (ClassLoader classLoader , BeanFactory beanFactory ) {
331
335
332
336
SpelAwareProxyProjectionFactory factory = new SpelAwareProxyProjectionFactory ();
@@ -532,22 +536,25 @@ public QueryExecutorMethodInterceptor(RepositoryInformation repositoryInformatio
532
536
+ "infrastructure apparently does not support query methods!" );
533
537
}
534
538
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 ());
538
542
}
539
543
540
544
private Map <Method , RepositoryQuery > mapMethodsToQuery (RepositoryInformation repositoryInformation ,
541
- ProjectionFactory projectionFactory , QueryLookupStrategy lookupStrategy ) {
545
+ QueryLookupStrategy lookupStrategy , ProjectionFactory projectionFactory ) {
542
546
543
547
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 )) //
547
549
.peek (pair -> invokeListeners (pair .getSecond ())) //
548
550
.collect (Pair .toMap ());
549
551
}
550
552
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
+
551
558
@ SuppressWarnings ({ "rawtypes" , "unchecked" })
552
559
private void invokeListeners (RepositoryQuery query ) {
553
560
@@ -580,6 +587,7 @@ public Object invoke(@SuppressWarnings("null") MethodInvocation invocation) thro
580
587
return resultHandler .postProcessInvocationResult (result , methodReturnTypeDescriptor );
581
588
}
582
589
590
+ @ Nullable
583
591
private Object doInvoke (MethodInvocation invocation ) throws Throwable {
584
592
585
593
Method method = invocation .getMethod ();
@@ -603,7 +611,6 @@ private boolean hasQueryFor(Method method) {
603
611
}
604
612
}
605
613
606
-
607
614
/**
608
615
* Method interceptor that calls methods on the {@link RepositoryComposition}.
609
616
*
0 commit comments