DATAMONGO-1988 - Polishing.
Match exactly for either top-level properties of leaf-properties instead of accepting the property/field name suffix. Downgrade tests to use DBObject API. Original pull request: #565.
This commit is contained in:
@@ -771,7 +771,7 @@ public class QueryMapper {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#isIdKey()
|
||||
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#isIdField()
|
||||
*/
|
||||
@Override
|
||||
public boolean isIdField() {
|
||||
@@ -780,7 +780,9 @@ public class QueryMapper {
|
||||
: entity.getIdProperty();
|
||||
|
||||
if (idProperty != null) {
|
||||
return name.endsWith(idProperty.getName()) || name.endsWith(idProperty.getFieldName());
|
||||
|
||||
return name.equals(idProperty.getName()) || name.equals(idProperty.getFieldName())
|
||||
|| name.endsWith("." + idProperty.getName()) || name.endsWith("." + idProperty.getFieldName());
|
||||
}
|
||||
|
||||
return DEFAULT_ID_NAMES.contains(name);
|
||||
|
||||
@@ -3251,10 +3251,10 @@ public class MongoTemplateTests {
|
||||
|
||||
template.save(source);
|
||||
|
||||
DocumentWithNestedTypeHavingStringIdProperty target = template.query(DocumentWithNestedTypeHavingStringIdProperty.class)
|
||||
.matching(query(where("sample.id").is(source.sample.id))).firstValue();
|
||||
DocumentWithNestedTypeHavingStringIdProperty target = template
|
||||
.findOne(query(where("sample.id").is(source.sample.id)), DocumentWithNestedTypeHavingStringIdProperty.class);
|
||||
|
||||
assertThat(target).isEqualTo(source);
|
||||
assertThat(target, is(source));
|
||||
}
|
||||
|
||||
static class TypeWithNumbers {
|
||||
|
||||
@@ -65,7 +65,7 @@ import com.mongodb.QueryBuilder;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link QueryMapper}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Patryk Wasik
|
||||
* @author Thomas Darimont
|
||||
@@ -762,20 +762,30 @@ public class QueryMapperUnitTests {
|
||||
public void mapsStringObjectIdRepresentationToObjectIdWhenReferencingIdProperty() {
|
||||
|
||||
Query query = query(where("sample.foo").is(new ObjectId().toHexString()));
|
||||
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
|
||||
DBObject dbo = mapper.getMappedObject(query.getQueryObject(),
|
||||
context.getPersistentEntity(ClassWithEmbedded.class));
|
||||
|
||||
assertThat(document.get("sample._id"), instanceOf(ObjectId.class));
|
||||
assertThat(dbo.get("sample._id"), instanceOf(ObjectId.class));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1988
|
||||
public void matchesExactFieldNameToIdProperty() {
|
||||
|
||||
Query query = query(where("sample.iid").is(new ObjectId().toHexString()));
|
||||
DBObject dbo = mapper.getMappedObject(query.getQueryObject(),
|
||||
context.getPersistentEntity(ClassWithEmbedded.class));
|
||||
|
||||
assertThat(dbo.get("sample.iid"), instanceOf(String.class));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1988
|
||||
public void leavesNonObjectIdStringIdRepresentationUntouchedWhenReferencingIdProperty() {
|
||||
|
||||
Query query = query(where("sample.foo").is("id-1"));
|
||||
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
|
||||
DBObject dbo = mapper.getMappedObject(query.getQueryObject(),
|
||||
context.getPersistentEntity(ClassWithEmbedded.class));
|
||||
|
||||
assertThat(document.get("sample._id"), instanceOf(String.class));
|
||||
assertThat(dbo.get("sample._id"), instanceOf(String.class));
|
||||
}
|
||||
|
||||
@Document
|
||||
|
||||
Reference in New Issue
Block a user