Skip to content

Commit 92a6ec8

Browse files
committed
Polishing.
Use for-loop instead of stream to reduce overhead. See #2722
1 parent 0e57ea8 commit 92a6ec8

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.lang.reflect.Method;
1919
import java.util.Collections;
20+
import java.util.HashMap;
2021
import java.util.List;
2122
import java.util.Map;
2223
import java.util.Optional;
@@ -78,9 +79,9 @@ public QueryExecutorMethodInterceptor(RepositoryInformation repositoryInformatio
7879

7980
if (!queryLookupStrategy.isPresent() && repositoryInformation.hasQueryMethods()) {
8081

81-
throw new IllegalStateException("You have defined query methods in the repository"
82-
+ " but do not have any query lookup strategy defined."
83-
+ " The infrastructure apparently does not support query methods");
82+
throw new IllegalStateException(
83+
"You have defined query methods in the repository" + " but do not have any query lookup strategy defined."
84+
+ " The infrastructure apparently does not support query methods");
8485
}
8586

8687
this.queries = queryLookupStrategy //
@@ -91,10 +92,17 @@ public QueryExecutorMethodInterceptor(RepositoryInformation repositoryInformatio
9192
private Map<Method, RepositoryQuery> mapMethodsToQuery(RepositoryInformation repositoryInformation,
9293
QueryLookupStrategy lookupStrategy, ProjectionFactory projectionFactory) {
9394

94-
return repositoryInformation.getQueryMethods().stream() //
95-
.map(method -> lookupQuery(method, repositoryInformation, lookupStrategy, projectionFactory)) //
96-
.peek(pair -> invokeListeners(pair.getSecond())) //
97-
.collect(Pair.toMap());
95+
Map<Method, RepositoryQuery> result = new HashMap<>();
96+
97+
for (Method method : repositoryInformation.getQueryMethods()) {
98+
99+
Pair<Method, RepositoryQuery> pair = lookupQuery(method, repositoryInformation, lookupStrategy,
100+
projectionFactory);
101+
invokeListeners(pair.getSecond());
102+
result.put(pair.getFirst(), pair.getSecond());
103+
}
104+
105+
return result;
98106
}
99107

100108
private Pair<Method, RepositoryQuery> lookupQuery(Method method, RepositoryInformation information,

0 commit comments

Comments
 (0)