DATADOC-278 - QueryMapper now converts ids for $ne correctly.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user