|
25 | 25 |
|
26 | 26 | import org.slf4j.Logger;
|
27 | 27 | import org.slf4j.LoggerFactory;
|
28 |
| - |
29 | 28 | import org.springframework.data.domain.Range;
|
30 | 29 | import org.springframework.data.domain.Range.Bound;
|
31 | 30 | import org.springframework.data.domain.Sort;
|
|
51 | 50 | import org.springframework.data.repository.query.parser.Part.IgnoreCaseType;
|
52 | 51 | import org.springframework.data.repository.query.parser.Part.Type;
|
53 | 52 | import org.springframework.data.repository.query.parser.PartTree;
|
| 53 | +import org.springframework.data.util.Streamable; |
54 | 54 | import org.springframework.util.Assert;
|
55 | 55 | import org.springframework.util.ClassUtils;
|
| 56 | +import org.springframework.util.ObjectUtils; |
56 | 57 |
|
57 | 58 | /**
|
58 | 59 | * Custom query creator to create Mongo criterias.
|
@@ -196,9 +197,9 @@ private Criteria from(Part part, MongoPersistentProperty property, Criteria crit
|
196 | 197 | case IS_NULL:
|
197 | 198 | return criteria.is(null);
|
198 | 199 | case NOT_IN:
|
199 |
| - return criteria.nin(nextAsArray(parameters)); |
| 200 | + return criteria.nin(nextAsList(parameters, part)); |
200 | 201 | case IN:
|
201 |
| - return criteria.in(nextAsArray(parameters)); |
| 202 | + return criteria.in(nextAsList(parameters, part)); |
202 | 203 | case LIKE:
|
203 | 204 | case STARTING_WITH:
|
204 | 205 | case ENDING_WITH:
|
@@ -337,7 +338,7 @@ private Criteria createContainingCriteria(Part part, MongoPersistentProperty pro
|
337 | 338 | Iterator<Object> parameters) {
|
338 | 339 |
|
339 | 340 | if (property.isCollectionLike()) {
|
340 |
| - return criteria.in(nextAsArray(parameters)); |
| 341 | + return criteria.in(nextAsList(parameters, part)); |
341 | 342 | }
|
342 | 343 |
|
343 | 344 | return addAppropriateLikeRegexTo(criteria, part, parameters.next());
|
@@ -400,17 +401,24 @@ private <T> T nextAs(Iterator<Object> iterator, Class<T> type) {
|
400 | 401 | String.format("Expected parameter type of %s but got %s!", type, parameter.getClass()));
|
401 | 402 | }
|
402 | 403 |
|
403 |
| - private Object[] nextAsArray(Iterator<Object> iterator) { |
| 404 | + private java.util.List<?> nextAsList(Iterator<Object> iterator, Part part) { |
| 405 | + |
| 406 | + Streamable<?> streamable = asStreamable(iterator.next()); |
| 407 | + if(!isSimpleComparisionPossible(part)) { |
| 408 | + streamable = streamable.map(MongoRegexCreator.INSTANCE::toCaseInsensitiveMatch); |
| 409 | + } |
| 410 | + |
| 411 | + return streamable.toList(); |
| 412 | + } |
404 | 413 |
|
405 |
| - Object next = iterator.next(); |
| 414 | + private Streamable<?> asStreamable(Object value) { |
406 | 415 |
|
407 |
| - if (next instanceof Collection) { |
408 |
| - return ((Collection<?>) next).toArray(); |
409 |
| - } else if (next != null && next.getClass().isArray()) { |
410 |
| - return (Object[]) next; |
| 416 | + if (value instanceof Collection) { |
| 417 | + return Streamable.of((Collection<?>) value); |
| 418 | + } else if (ObjectUtils.isArray(value)) { |
| 419 | + return Streamable.of((Object[]) value); |
411 | 420 | }
|
412 |
| - |
413 |
| - return new Object[] { next }; |
| 421 | + return Streamable.of(value); |
414 | 422 | }
|
415 | 423 |
|
416 | 424 | private String toLikeRegex(String source, Part part) {
|
|
0 commit comments