DATAMONGO-472 - MongoQueryCreator now correctly translates Not keyword.

We're now translating a negating property reference into a ne(…) call instead of a not().is(…).
This commit is contained in:
Oliver Gierke
2012-08-10 19:58:36 +02:00
parent 05baa851d8
commit 1f4264e6a7
3 changed files with 20 additions and 2 deletions

View File

@@ -228,7 +228,7 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
case SIMPLE_PROPERTY:
return criteria.is(parameters.nextConverted(property));
case NEGATING_SIMPLE_PROPERTY:
return criteria.not().is(parameters.nextConverted(property));
return criteria.ne(parameters.nextConverted(property));
}
throw new IllegalArgumentException("Unsupported keyword!");

View File

@@ -495,4 +495,15 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
List<Person> result = repository.findByCreatedAtLessThanManually(boyd.createdAt);
assertThat(result.isEmpty(), is(false));
}
}
/**
* @see DATAMONGO-472
*/
@Test
public void findsPeopleUsingNotPredicate() {
List<Person> result = repository.findByLastnameNot("Matthews");
assertThat(result, not(hasItem(dave)));
assertThat(result, hasSize(5));
}
}

View File

@@ -183,4 +183,11 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
*/
List<Person> findByCreatedAtAfter(Date date);
/**
* @see DATAMONGO-472
* @param lastname
* @return
*/
List<Person> findByLastnameNot(String lastname);
}