DATAJPA-1619 - in/notIn predicate now accept Iterable arguments.
Original pull request: #396.
This commit is contained in:
committed by
Mark Paluch
parent
2be332c51d
commit
6a868d09d0
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.query;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -187,14 +186,14 @@ public class PartTreeJpaQuery extends AbstractJpaQuery {
|
||||
}
|
||||
|
||||
private static boolean parameterIsCollectionLike(JpaParameter parameter) {
|
||||
return Collection.class.isAssignableFrom(parameter.getType()) || parameter.getType().isArray();
|
||||
return Iterable.class.isAssignableFrom(parameter.getType()) || parameter.getType().isArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Arrays are may be treated as collection like or in the case of binary data as scalar
|
||||
*/
|
||||
private static boolean parameterIsScalarLike(JpaParameter parameter) {
|
||||
return !Collection.class.isAssignableFrom(parameter.getType());
|
||||
return !Iterable.class.isAssignableFrom(parameter.getType());
|
||||
}
|
||||
|
||||
private static boolean expectsCollection(Type type) {
|
||||
|
||||
@@ -197,6 +197,16 @@ public class PartTreeJpaQueryIntegrationTests {
|
||||
.withMessageContaining("Collection");
|
||||
}
|
||||
|
||||
@Test // DATAJPA-1619
|
||||
public void acceptsInPredicateWithIterableParameter() throws Exception {
|
||||
|
||||
JpaQueryMethod method = getQueryMethod("findByFirstnameIn", Iterable.class);
|
||||
|
||||
new PartTreeJpaQuery(method, entityManager, provider);
|
||||
|
||||
assertThat(method).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAJPA-863
|
||||
public void errorsDueToMismatchOfParametersContainNameOfMethodInterfaceAndPropertyPath() throws Exception {
|
||||
|
||||
@@ -299,6 +309,9 @@ public class PartTreeJpaQueryIntegrationTests {
|
||||
// should fail, since we can't do an IN on a scalar
|
||||
List<User> findByIdIn(Long id);
|
||||
|
||||
// should succeed
|
||||
List<User> findByFirstnameIn(Iterable<String> id);
|
||||
|
||||
// Wrong number of parameters
|
||||
User findByFirstname();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user