DATADOC-129 changed Criteria to disallow 'not' before 'is' - should use 'ne' instead
This commit is contained in:
@@ -75,14 +75,17 @@ public class Criteria implements CriteriaDefinition {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a criterion using the $is operator
|
||||
* Creates a criterion using equality
|
||||
*
|
||||
* @param o
|
||||
* @return
|
||||
*/
|
||||
public Criteria is(Object o) {
|
||||
if (isValue != null) {
|
||||
throw new InvalidDocumentStoreApiUsageException("Multiple 'is' values declared.");
|
||||
throw new InvalidDocumentStoreApiUsageException("Multiple 'is' values declared. You need to use 'and' with multiple criteria");
|
||||
}
|
||||
if ( this.criteria.size() > 0 && "$not".equals(this.criteria.keySet().toArray()[this.criteria.size() - 1])) {
|
||||
throw new InvalidDocumentStoreApiUsageException("Invalid query: 'not' can't be used with 'is' - use 'ne' instead.");
|
||||
}
|
||||
this.isValue = o;
|
||||
return this;
|
||||
@@ -186,8 +189,8 @@ public class Criteria implements CriteriaDefinition {
|
||||
* @param o
|
||||
* @return
|
||||
*/
|
||||
public Criteria all(Object o) {
|
||||
criteria.put("$is", o);
|
||||
public Criteria all(Object... o) {
|
||||
criteria.put("$all", o);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ public class MongoTemplateTests {
|
||||
testProperHandlingOfDifferentIdTypes(this.mappingTemplate);
|
||||
}
|
||||
|
||||
public void testProperHandlingOfDifferentIdTypes(MongoTemplate mongoTemplate) throws Exception {
|
||||
private void testProperHandlingOfDifferentIdTypes(MongoTemplate mongoTemplate) throws Exception {
|
||||
PersonWithIdPropertyOfTypeString p1 = new PersonWithIdPropertyOfTypeString();
|
||||
p1.setFirstName("Sven_1");
|
||||
p1.setAge(22);
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.springframework.data.document.mongodb.query.Criteria.where;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.document.InvalidDocumentStoreApiUsageException;
|
||||
|
||||
public class QueryTests {
|
||||
|
||||
@@ -37,6 +38,14 @@ public class QueryTests {
|
||||
Assert.assertEquals(expected, q.getQueryObject().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidQueryWithNotIs() {
|
||||
try {
|
||||
new Query(where("name").not().is("Thomas"));
|
||||
Assert.fail("This should have caused an InvalidDocumentStoreApiUsageException");
|
||||
} catch (InvalidDocumentStoreApiUsageException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrQuery() {
|
||||
Query q = new OrQuery(new Query(where("name").is("Sven").and("age")
|
||||
|
||||
Reference in New Issue
Block a user