// check whether removed referenceable nodes are still being referenced
for (ItemState state : local.deletedStates()) {
if (state.isNode()) {
NodeState node = (NodeState) state;
if (isReferenceable(node)) {
NodeId targetId = node.getNodeId();
// either get node references from change log or
// load from persistence manager
NodeReferences refs = local.getReferencesTo(targetId);
if (refs == null) {
if (!hasNodeReferences(targetId)) {
continue;
}
refs = getNodeReferences(targetId);
}
// in some versioning operations (such as restore) a node
// may actually be deleted and then again added with the
// same UUID, i.e. the node is still referenceable.
if (refs.hasReferences() && !local.has(targetId)) {
String msg = node.getNodeId()
+ ": the node cannot be removed because it is still being referenced.";
log.debug(msg);
throw new ReferentialIntegrityException(msg);
}
}
}
}
// check whether targets of modified node references exist
for (NodeReferences refs : local.modifiedRefs()) {
// no need to check existence of target if there are no references
if (refs.hasReferences()) {
// please note:
// virtual providers are indirectly checked via 'hasItemState()'
NodeId id = refs.getTargetId();
if (!local.has(id) && !hasItemState(id)) {
String msg = "Target node " + id
+ " of REFERENCE property does not exist";
log.debug(msg);
throw new ReferentialIntegrityException(msg);