|
1 | 1 | /*
|
2 |
| - * Copyright 2010-2013 the original author or authors. |
| 2 | + * Copyright 2010-2014 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
46 | 46 | *
|
47 | 47 | * @author Oliver Gierke
|
48 | 48 | * @author Thomas Darimont
|
| 49 | + * @author Christoph Strobl |
49 | 50 | */
|
50 | 51 | class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
|
51 | 52 |
|
@@ -198,7 +199,7 @@ private Criteria from(Part part, MongoPersistentProperty property, Criteria crit
|
198 | 199 | case STARTING_WITH:
|
199 | 200 | case ENDING_WITH:
|
200 | 201 | case CONTAINING:
|
201 |
| - return addAppropriateLikeRegexTo(criteria, part, parameters.next().toString()); |
| 202 | + return createContainingCriteria(part, property, criteria, parameters); |
202 | 203 | case REGEX:
|
203 | 204 | return criteria.regex(parameters.next().toString());
|
204 | 205 | case EXISTS:
|
@@ -292,6 +293,27 @@ private Criteria createLikeRegexCriteriaOrThrow(Part part, MongoPersistentProper
|
292 | 293 | Arrays.asList(IgnoreCaseType.ALWAYS, IgnoreCaseType.WHEN_POSSIBLE), part.shouldIgnoreCase()));
|
293 | 294 | }
|
294 | 295 |
|
| 296 | + /** |
| 297 | + * If the target property of the comparison is of type String, then the operator checks for match using regular |
| 298 | + * expression. If the target property of the comparison is a {@link Collection} then the operator evaluates to true if |
| 299 | + * it finds an exact match within any member of the {@link Collection}. |
| 300 | + * |
| 301 | + * @param part |
| 302 | + * @param property |
| 303 | + * @param criteria |
| 304 | + * @param parameters |
| 305 | + * @return |
| 306 | + */ |
| 307 | + private Criteria createContainingCriteria(Part part, MongoPersistentProperty property, Criteria criteria, |
| 308 | + PotentiallyConvertingIterator parameters) { |
| 309 | + |
| 310 | + if (property.isCollectionLike()) { |
| 311 | + return criteria.in(nextAsArray(parameters, property)); |
| 312 | + } |
| 313 | + |
| 314 | + return addAppropriateLikeRegexTo(criteria, part, parameters.next().toString()); |
| 315 | + } |
| 316 | + |
295 | 317 | /**
|
296 | 318 | * Creates an appropriate like-regex and appends it to the given criteria.
|
297 | 319 | *
|
|
0 commit comments