if (isDirty()) {
final Map<Neo4jPersistentProperty, ExistingValue> dirtyCopy = new HashMap<Neo4jPersistentProperty, ExistingValue>(dirty);
try {
for (final Map.Entry<Neo4jPersistentProperty, ExistingValue> entry : dirtyCopy.entrySet()) {
final Neo4jPersistentProperty property = entry.getKey();
Object valueFromEntity = getValueFromEntity(property, MappingPolicy.MAP_FIELD_DIRECT_POLICY);
cascadePersist(valueFromEntity);
if (log.isDebugEnabled()) log.debug("Flushing dirty Entity new node " + entity + " field " + property+ " with value "+ valueFromEntity);
final MappingPolicy mappingPolicy = property.getMappingPolicy();
checkConcurrentModification(entity, entry, property, mappingPolicy);
delegate.setValue(property, valueFromEntity, mappingPolicy);
dirty.remove(property);
if (valueFromEntity instanceof DirtyValue) {
((DirtyValue)valueFromEntity).setDirty(false);
}
}
} finally {
if (!dirty.isEmpty()) { // restore all dirty data
dirty.putAll(dirtyCopy);
for (Map.Entry<Neo4jPersistentProperty, ExistingValue> entry : dirtyCopy.entrySet()) {
final Neo4jPersistentProperty property = entry.getKey();
Object valueFromEntity = getValueFromEntity(property, MappingPolicy.MAP_FIELD_DIRECT_POLICY);
if (valueFromEntity instanceof DirtyValue) {
((DirtyValue)valueFromEntity).setDirty(true);
}
}