DATACMNS-1300 - Improved collection query detection for Iterables.

Previously a custom Iterable implementation would've caused QueryMethod.isCollectionQuery() to return true. We now solely rely on TypeInformation.isCollectionLike() (which checks for exact Iterable, Collection assignability and arrays) after handling potential wrapper types.
This commit is contained in:
Oliver Gierke
2018-04-16 16:29:50 +02:00
parent 0daac0c890
commit f3c138258b
2 changed files with 28 additions and 7 deletions

View File

@@ -154,7 +154,8 @@ public class QueryMethod {
Class<?> methodDomainClass = metadata.getReturnedDomainClass(method);
this.domainClass = repositoryDomainClass == null || repositoryDomainClass.isAssignableFrom(methodDomainClass)
? methodDomainClass : repositoryDomainClass;
? methodDomainClass
: repositoryDomainClass;
}
return domainClass;
@@ -186,13 +187,11 @@ public class QueryMethod {
return true;
}
if (QueryExecutionConverters.supports(unwrappedReturnType)
&& QueryExecutionConverters.isSingleValue(unwrappedReturnType)) {
return false;
if (QueryExecutionConverters.supports(unwrappedReturnType)) {
return !QueryExecutionConverters.isSingleValue(unwrappedReturnType);
}
return org.springframework.util.ClassUtils.isAssignable(Iterable.class, unwrappedReturnType)
|| unwrappedReturnType.isArray();
return ClassTypeInformation.from(unwrappedReturnType).isCollectionLike();
}
/**
@@ -285,7 +284,9 @@ public class QueryMethod {
Assert.notEmpty(types, "Types must not be null or empty!");
TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method);
returnType = QueryExecutionConverters.isSingleValue(returnType.getType()) ? returnType.getComponentType()
returnType = QueryExecutionConverters.isSingleValue(returnType.getType()) //
? returnType.getComponentType() //
: returnType;
for (Class<?> type : types) {