Skip to content

Commit

Permalink
DATAMONGO-1229 - Fixed application of ignore case flag on nested prop…
Browse files Browse the repository at this point in the history
…erties.

Previously we tried to apply the ignore case settings found in the PartTree to the root PropertyPath we handle in MongoQueryCreator.create(). This is now changed to work on the leaf property of the PropertyPath.
  • Loading branch information
odrotbohm committed Jun 5, 2015
1 parent 62fbe4d commit 218f32e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Expand Up @@ -29,6 +29,7 @@
import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point;
import org.springframework.data.geo.Shape;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.context.PersistentPropertyPath;
import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
Expand Down Expand Up @@ -276,19 +277,23 @@ private boolean isSimpleComparisionPossible(Part part) {
private Criteria createLikeRegexCriteriaOrThrow(Part part, MongoPersistentProperty property, Criteria criteria,
PotentiallyConvertingIterator parameters, boolean shouldNegateExpression) {

PropertyPath path = part.getProperty().getLeafProperty();

switch (part.shouldIgnoreCase()) {

case ALWAYS:
if (part.getProperty().getType() != String.class) {
throw new IllegalArgumentException(String.format("part %s must be of type String but was %s",
part.getProperty(), part.getType()));
if (path.getType() != String.class) {
throw new IllegalArgumentException(
String.format("Part %s must be of type String but was %s", path, path.getType()));
}
// fall-through

case WHEN_POSSIBLE:

if (shouldNegateExpression) {
criteria = criteria.not();
}

return addAppropriateLikeRegexTo(criteria, part, parameters.nextConverted(property).toString());

case NEVER:
Expand Down Expand Up @@ -365,8 +370,8 @@ private <T> T nextAs(Iterator<Object> iterator, Class<T> type) {
return (T) parameter;
}

throw new IllegalArgumentException(String.format("Expected parameter type of %s but got %s!", type,
parameter.getClass()));
throw new IllegalArgumentException(
String.format("Expected parameter type of %s but got %s!", type, parameter.getClass()));
}

private Object[] nextAsArray(PotentiallyConvertingIterator iterator, MongoPersistentProperty property) {
Expand Down
Expand Up @@ -553,6 +553,18 @@ public void shouldCreateNearQueryForMinMaxDistance() {
assertThat(query, is(query(where("address.geo").near(point).minDistance(10D).maxDistance(20D))));
}

/**
* @see DATAMONGO-1229
*/
@Test
public void appliesIgnoreCaseToLeafProperty() {

PartTree tree = new PartTree("findByAddressStreetIgnoreCase", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter, "Street");

assertThat(new MongoQueryCreator(tree, accessor, context).createQuery(), is(notNullValue()));
}

interface PersonRepository extends Repository<Person, Long> {

List<Person> findByLocationNearAndFirstname(Point location, Distance maxDistance, String firstname);
Expand Down

0 comments on commit 218f32e

Please sign in to comment.