DATAMONGO-508 - Eagerly return DBRef creation if the given value already is a DBRef.

This commit is contained in:
Oliver Gierke
2012-08-15 16:38:56 +02:00
parent d7ae95a779
commit 5e2f16c678
2 changed files with 18 additions and 0 deletions

View File

@@ -671,6 +671,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
Assert.notNull(target);
if (target instanceof DBRef) {
return (DBRef) target;
}
MongoPersistentEntity<?> targetEntity = mappingContext.getPersistentEntity(target.getClass());
if (null == targetEntity) {

View File

@@ -1278,6 +1278,20 @@ public class MappingMongoConverterUnitTests {
fail(String.format("Didn't find synthetic field on %s!", target));
}
/**
* @see DATAMGONGO-508
*/
@Test
public void eagerlyReturnsDBRefObjectIfTargetAlreadyIsOne() {
DB db = mock(DB.class);
DBRef dbRef = new DBRef(db, "collection", "id");
org.springframework.data.mongodb.core.mapping.DBRef annotation = mock(org.springframework.data.mongodb.core.mapping.DBRef.class);
assertThat(converter.createDBRef(dbRef, annotation), is(dbRef));
}
static class GenericType<T> {
T content;
}