if (property != null && property.isReference()) {
updatedPropertyIsReference = true;
propertyWhichWasAdded = property;
for (Object referenceObject : property.getValuesAsArray()) {
assert referenceObject instanceof Reference;
Reference updatedReference = (Reference)referenceObject;
if (referencesToRemove.contains(updatedReference)) {
// the reference is already present on a property with the same name, so this is a no-op for that reference
// therefore we remove it from the list of references that will be removed
if (referencesToRemove.remove(updatedReference)) {
// Make sure that the referenced node is not modified to remove the back-reference to this node.
// See MODE-2283 for an example ...
NodeKey referredKey = nodeKeyFromReference(updatedReference);
CachedNode referredNode = cache.getNode(referredKey);
if (referredNode instanceof SessionNode) {
// The node was modified during this session and has unsaved changes ...
SessionNode changedReferrerNode = (SessionNode)referredNode;
ReferrerChanges changes = changedReferrerNode.getReferrerChanges();
if (changes != null) {
// There are changes to that node's referrers ...
ReferenceType type = updatedReference.isWeak() ? ReferenceType.WEAK : ReferenceType.STRONG;
if (changes.isRemovedReferrer(key, type)) {
// The referenced node had a back reference to this node, but we're no longer removing
// this node's reference to the referenced node, and that means we should no longer remove
// the referenced node's backreference to this node ...
if (updatedReference.isWeak()) changes.addWeakReferrer(propertyWhichWasRemoved, key);
else changes.addStrongReferrer(propertyWhichWasRemoved, key);
}
}
}
}