GH-2261 - Isolate checks for imperative and reactive query methods.

The deep scanning by `ClassUtils` whether a class has a given method triggers type resolution of some reactive types that might not be present in non-reactive applications. Therefore the check must be separated for imperative and reactive code paths.
This commit is contained in:
Michael Simons
2021-06-21 10:19:02 +02:00
parent 27679af5fe
commit 07a427c6b3
2 changed files with 16 additions and 4 deletions

View File

@@ -22,7 +22,6 @@ import java.util.Optional;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.data.neo4j.repository.support.CypherdslStatementExecutor;
import org.springframework.data.neo4j.repository.support.ReactiveCypherdslStatementExecutor;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.Parameter;
@@ -61,12 +60,24 @@ class Neo4jQueryMethod extends QueryMethod {
* @param factory must not be {@literal null}.
*/
Neo4jQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) {
this(method, metadata, factory, ClassUtils.hasMethod(CypherdslStatementExecutor.class, method));
}
/**
* Allows to configure {@link #cypherBasedProjection} from inheriting classes. Not meant to be called outside the
* inheritance tree.
*
* @param method must not be {@literal null}.
* @param metadata must not be {@literal null}.
* @param factory must not be {@literal null}.
* @param cypherBasedProjection True if this points to a Cypher-DSL based projection.
*/
Neo4jQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory, boolean cypherBasedProjection) {
super(method, metadata, factory);
Class<?> declaringClass = method.getDeclaringClass();
this.repositoryName = declaringClass.getName();
this.cypherBasedProjection = ClassUtils.hasMethod(CypherdslStatementExecutor.class, method) || ClassUtils
.hasMethod(ReactiveCypherdslStatementExecutor.class, method);
this.cypherBasedProjection = cypherBasedProjection;
this.queryAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, Query.class);
}

View File

@@ -21,6 +21,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.neo4j.repository.support.ReactiveCypherdslStatementExecutor;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.util.ReactiveWrappers;
@@ -54,7 +55,7 @@ final class ReactiveNeo4jQueryMethod extends Neo4jQueryMethod {
* @param factory must not be {@literal null}.
*/
ReactiveNeo4jQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) {
super(method, metadata, factory);
super(method, metadata, factory, ClassUtils.hasMethod(ReactiveCypherdslStatementExecutor.class, method));
if (org.springframework.data.repository.util.ClassUtils.hasParameterOfType(method, Pageable.class)) {