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:19:28 +02:00
parent 5986b4b7af
commit 3676ae0c87
2 changed files with 26 additions and 6 deletions

View File

@@ -38,6 +38,7 @@ import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.AbstractRepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.util.Version;
@@ -230,6 +231,15 @@ public class QueryMethodUnitTests {
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isTrue();
}
@Test // DATACMNS-1300
public void doesNotConsiderMethodForIterableAggregateACollectionQuery() throws Exception {
RepositoryMetadata metadata = AbstractRepositoryMetadata.getMetadata(ContainerRepository.class);
Method method = ContainerRepository.class.getMethod("someMethod");
assertThat(new QueryMethod(method, metadata, factory).isCollectionQuery()).isFalse();
}
interface SampleRepository extends Repository<User, Serializable> {
String pagingMethodWithInvalidReturnType(Pageable pageable);
@@ -283,4 +293,14 @@ public class QueryMethodUnitTests {
class SpecialUser extends User {
}
// DATACMNS-1300
class Element {}
abstract class Container implements Iterable<Element> {}
interface ContainerRepository extends Repository<Container, Long> {
Container someMethod();
}
}