DATADOC-278 - QueryMapper now converts ids for $ne correctly.

This commit is contained in:
Oliver Gierke
2011-09-27 10:43:02 +02:00
parent 6b40a27c92
commit 3bdeb68617
2 changed files with 21 additions and 2 deletions

View File

@@ -60,7 +60,9 @@ public class QueryMapper {
* @return
*/
public DBObject getMappedObject(DBObject query, MongoPersistentEntity<?> entity) {
String idKey = null;
if (null != entity && entity.getIdProperty() != null) {
idKey = entity.getIdProperty().getName();
} else if (query.containsField("id")) {
@@ -87,7 +89,6 @@ public class QueryMapper {
value = getMappedObject((DBObject) value, entity);
}
} else {
value = convertId(value);
}
newKey = "_id";
@@ -100,10 +101,13 @@ public class QueryMapper {
newConditions.add(getMappedObject((DBObject) iter.next(), entity));
}
value = newConditions;
} else if (key.equals("$ne")) {
value = convertId(value);
}
newDbo.put(newKey, value);
}
return newDbo;
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.mongodb.core.query;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.math.BigInteger;
@@ -89,6 +89,21 @@ public class QueryMapperUnitTests {
assertThat(result.get("_id"), is((Object) "1"));
}
/**
* @see DATADOC-278
*/
@Test
public void translates$NeCorrectly() {
Criteria criteria = Criteria.where("foo").ne(new ObjectId().toString());
DBObject result = mapper.getMappedObject(criteria.getCriteriaObject(), context.getPersistentEntity(Sample.class));
Object object = result.get("_id");
assertThat(object, is(DBObject.class));
DBObject dbObject = (DBObject) object;
assertThat(dbObject.get("$ne"), is(ObjectId.class));
}
class Sample {
@Id