DATAMONGO-568 - MongoTemplate.find(…) does not throw NullPointerException anymore.

Trigger findAll(…) if the Query object given to a find(…) method is null.
This commit is contained in:
Michal Vich
2013-01-23 17:46:30 +00:00
committed by Oliver Gierke
parent 38ccc59137
commit b2f82bb5bf
2 changed files with 17 additions and 2 deletions

View File

@@ -487,8 +487,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
}
public <T> List<T> find(final Query query, Class<T> entityClass, String collectionName) {
CursorPreparer cursorPreparer = query == null ? null : new QueryCursorPreparer(query);
return doFind(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass, cursorPreparer);
if (query == null) {
return findAll(entityClass, collectionName);
}
return doFind(collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
new QueryCursorPreparer(query));
}
public <T> T findById(Object id, Class<T> entityClass) {

View File

@@ -1445,6 +1445,16 @@ public class MongoTemplateTests {
assertThat(person.version, is(0));
}
/**
* @see DATAMONGO-568
*/
@Test
public void queryCantBeNull() {
List<PersonWithIdPropertyOfTypeObjectId> result = template.findAll(PersonWithIdPropertyOfTypeObjectId.class);
assertThat(template.find(null, PersonWithIdPropertyOfTypeObjectId.class), is(result));
}
static class MyId {
String first;