Browse Source

DATAMONGO-631 - Explictly reject Order instances with ignore-case flag.

pull/14/merge
Oliver Gierke 13 years ago
parent
commit
3410a0589c
  1. 8
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java
  2. 23
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java

8
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java

@ -24,6 +24,7 @@ import java.util.List;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException; import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -150,6 +151,13 @@ public class Query {
return this; return this;
} }
for (Order order : sort) {
if (order.isIgnoreCase()) {
throw new IllegalArgumentException(String.format("Gven sort contained an Order for %s with ignore case! "
+ "MongoDB does not support sorting ignoreing case currently!", order.getProperty()));
}
}
if (this.coreSort == null) { if (this.coreSort == null) {
this.coreSort = sort; this.coreSort = sort;
} else { } else {

23
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2012 the original author or authors. * Copyright 2010-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,12 +20,24 @@ import static org.junit.Assert.*;
import static org.springframework.data.mongodb.core.query.Criteria.*; import static org.springframework.data.mongodb.core.query.Criteria.*;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction; import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException; import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
/**
* Unit tests for {@link Query}.
*
* @author Thomas Risberg
* @author Oliver Gierke
*/
public class QueryTests { public class QueryTests {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test @Test
public void testSimpleQuery() { public void testSimpleQuery() {
Query q = new Query(where("name").is("Thomas").and("age").lt(80)); Query q = new Query(where("name").is("Thomas").and("age").lt(80));
@ -170,4 +182,13 @@ public class QueryTests {
Query query = new Query().with(new org.springframework.data.domain.Sort(Direction.DESC, "foo")); Query query = new Query().with(new org.springframework.data.domain.Sort(Direction.DESC, "foo"));
assertThat(query.getSortObject().toString(), is("{ \"foo\" : -1}")); assertThat(query.getSortObject().toString(), is("{ \"foo\" : -1}"));
} }
@Test
public void rejectsOrderWithIgnoreCase() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("foo");
new Query().with(new Sort(new Sort.Order("foo").ignoreCase()));
}
} }

Loading…
Cancel
Save