Browse Source

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

pull/1/head
Oliver Gierke 14 years ago
parent
commit
3bdeb68617
  1. 6
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/QueryMapper.java
  2. 17
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryMapperUnitTests.java

6
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/QueryMapper.java

@ -60,7 +60,9 @@ public class QueryMapper { @@ -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 { @@ -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 { @@ -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;
}

17
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryMapperUnitTests.java

@ -15,7 +15,7 @@ @@ -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 { @@ -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

Loading…
Cancel
Save