assert appendedOrRenamedChildrenByName.isEmpty() == false;
// look at the information that was already persisted to determine whether some other thread has already
// created a child with the same name
CachedNode persistentNode = persistentNodeCache.getNode(modifiedNode.getKey());
final ChildReferences persistedChildReferences = persistentNode.getChildReferences(persistentNodeCache);
final SiblingCounter siblingCounter = SiblingCounter.create(persistedChildReferences);
// process appended/renamed children
for (Name childName : appendedOrRenamedChildrenByName.keySet()) {
int existingChildrenWithSameName = persistedChildReferences.getChildCount(childName);
if (existingChildrenWithSameName == 0) {
continue;
}
if (existingChildrenWithSameName == 1) {
// See if the existing same-name sibling is removed ...
NodeKey persistedChildKey = persistedChildReferences.getChild(childName).getKey();
if (removedChildren.contains(persistedChildKey)) {
// the sole existing child with this name is being removed, so we can ignore it ...
// existingChildrenWithSameName = 0;
continue;
}
}
// There is at least one persisted child with the same name, and we're adding a new child
// or renaming an existing child to this name. Therefore, we have to find a child node definition
// that allows SNS. Look for one ignoring the child node type (this is faster than finding the
// child node primary types) ...
NodeDefinitionSet childDefns = nodeTypeCapabilities.findChildNodeDefinitions(primaryType, mixinTypes);
JcrNodeDefinition childNodeDefinition = childDefns.findBestDefinitionForChild(childName, null, true,
siblingCounter);
if (childNodeDefinition != null) {
// found the one child node definition that applies, so it's okay ...
continue;
}
// We were NOT able to find a definition that allows SNS for this name, but we need to make sure that
// the node that already exists (persisted) isn't the one that's being changed
NodeKey persistedChildKey = persistedChildReferences.getChild(childName).getKey();
if (appendedChildren.containsKey(persistedChildKey) || renamedChildren.containsKey(persistedChildKey)) {
// The persisted node is being changed, so it's okay ...
continue;
}