use of org.sirix.node.interfaces.immutable.ImmutableNameNode in project sirix by sirixdb.
the class PathSummaryWriter method processFoundPathNode.
/**
* Process a found path node.
*
* @param oldPathNodeKey key of old path node
* @param newPathNodeKey key of new path node
* @param oldNodeKey key of old node
* @param uriKey key of URI
* @param prefixKey key of prefix
* @param localNameKey key of local name
* @param remove determines if a {@link PathNode} must be removed or not
* @param type type of operation
* @throws SirixException if Sirix fails to do so
*/
private void processFoundPathNode(@Nonnegative final long oldPathNodeKey, @Nonnegative final long newPathNodeKey, @Nonnegative final long oldNodeKey, final int uriKey, final int prefixKey, final int localNameKey, final Remove remove, final OPType type) throws SirixException {
final PathSummaryReader cloned = PathSummaryReader.getInstance(mPageWriteTrx, mNodeRtx.getResourceManager());
boolean moved = cloned.moveTo(oldPathNodeKey).hasMoved();
assert moved;
// Set new reference count of the root.
if (type != OPType.MOVEDSAMELEVEL) {
final PathNode currNode = (PathNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getNodeKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
currNode.setReferenceCount(currNode.getReferences() + cloned.getReferences());
currNode.setLocalNameKey(localNameKey);
currNode.setPrefixKey(prefixKey);
currNode.setURIKey(uriKey);
}
// For all old path nodes: Merge paths and adapt reference counts.
mPathSummaryReader.moveToFirstChild();
final int oldLevel = cloned.getLevel();
for (final Axis oldDescendants = new DescendantAxis(cloned); oldDescendants.hasNext(); ) {
oldDescendants.next();
// Search for new path entry.
final Axis axis = new FilterAxis(new LevelOrderAxis.Builder(mPathSummaryReader).filterLevel(cloned.getLevel() - oldLevel).includeSelf().build(), new NameFilter(mPathSummaryReader, Utils.buildName(cloned.getName())), new PathKindFilter(mPathSummaryReader, cloned.getPathKind()), new PathLevelFilter(mPathSummaryReader, cloned.getLevel()));
if (axis.hasNext()) {
axis.next();
// Set new reference count.
if (type != OPType.MOVEDSAMELEVEL) {
final PathNode currNode = (PathNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getNodeKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
currNode.setReferenceCount(currNode.getReferences() + cloned.getReferences());
}
} else {
// Insert new node.
insertPathAsFirstChild(cloned.getName(), cloned.getPathKind(), mPathSummaryReader.getLevel() + 1);
// Set new reference count.
final PathNode currNode = (PathNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getNodeKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
currNode.setReferenceCount(cloned.getReferences());
}
mPathSummaryReader.moveTo(newPathNodeKey);
}
// Set new path nodes of the changed nodes, that is set their PCR
// references.
mPathSummaryReader.moveTo(newPathNodeKey);
mNodeRtx.moveTo(oldNodeKey);
boolean first = true;
for (final Axis axis = new DescendantAxis(mNodeRtx, IncludeSelf.YES); axis.hasNext(); ) {
axis.next();
if (first && type == OPType.SETNAME) {
first = false;
} else if (mNodeRtx.getNode() instanceof ImmutableNameNode) {
cloned.moveTo(((NameNode) mNodeRtx.getCurrentNode()).getPathNodeKey());
resetPath(newPathNodeKey, cloned.getLevel());
if (mNodeRtx.getNode().getKind() == Kind.ELEMENT) {
final ElementNode element = (ElementNode) mNodeRtx.getCurrentNode();
for (int i = 0, nspCount = element.getNamespaceCount(); i < nspCount; i++) {
mNodeRtx.moveToNamespace(i);
cloned.moveTo(((NameNode) mNodeRtx.getCurrentNode()).getPathNodeKey());
resetPath(newPathNodeKey, cloned.getLevel());
mNodeRtx.moveToParent();
}
for (int i = 0, attCount = element.getAttributeCount(); i < attCount; i++) {
mNodeRtx.moveToAttribute(i);
cloned.moveTo(((NameNode) mNodeRtx.getCurrentNode()).getPathNodeKey());
resetPath(newPathNodeKey, cloned.getLevel());
mNodeRtx.moveToParent();
}
}
}
}
// Then: Remove old nodes.
if (remove == Remove.YES) {
mPathSummaryReader.moveTo(oldPathNodeKey);
removePathSummaryNode(remove);
}
}
Aggregations