DATADOC-166 - Check for null on removing objects.
This commit is contained in:
@@ -1004,10 +1004,18 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
return wr;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.MongoOperations#remove(java.lang.Object)
|
||||
*/
|
||||
public void remove(Object object) {
|
||||
|
||||
if (object == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
remove(new Query(where(getIdPropertyName(object))
|
||||
.is(getIdValue(object))), object.getClass());
|
||||
}
|
||||
@@ -1301,9 +1309,12 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
|
||||
protected String getIdPropertyName(Object object) {
|
||||
Assert.notNull(object);
|
||||
|
||||
MongoPersistentEntity<?> persistentEntity = mappingContext
|
||||
.getPersistentEntity(object.getClass());
|
||||
MongoPersistentProperty idProperty = persistentEntity.getIdProperty();
|
||||
|
||||
return idProperty == null ? ID : idProperty.getName();
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +83,8 @@ public class MongoTemplateTests {
|
||||
MongoMappingContext mappingContext = new MongoMappingContext();
|
||||
mappingContext.setInitialEntitySet(new HashSet<Class<?>>(Arrays.asList(PersonWith_idPropertyOfTypeObjectId.class,
|
||||
PersonWith_idPropertyOfTypeString.class, PersonWithIdPropertyOfTypeObjectId.class,
|
||||
PersonWithIdPropertyOfTypeString.class, PersonWithIdPropertyOfTypeInteger.class,
|
||||
PersonWithIdPropertyOfPrimitiveInt.class, PersonWithIdPropertyOfTypeLong.class,
|
||||
PersonWithIdPropertyOfTypeString.class, PersonWithIdPropertyOfTypeInteger.class,
|
||||
PersonWithIdPropertyOfPrimitiveInt.class, PersonWithIdPropertyOfTypeLong.class,
|
||||
PersonWithIdPropertyOfPrimitiveLong.class)));
|
||||
mappingContext.afterPropertiesSet();
|
||||
|
||||
@@ -758,4 +758,11 @@ public class MongoTemplateTests {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATADOC-166
|
||||
*/
|
||||
@Test
|
||||
public void removingNullIsANoOp() {
|
||||
template.remove(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user