use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class PathSummaryReader method moveToPrevious.
@Override
public Move<? extends XdmNodeReadTrx> moveToPrevious() {
assertNotClosed();
final StructNode node = getStructuralNode();
if (node.hasLeftSibling()) {
// Left sibling node.
Move<? extends XdmNodeReadTrx> leftSiblMove = moveTo(node.getLeftSiblingKey());
// Now move down to rightmost descendant node if it has one.
while (leftSiblMove.get().hasFirstChild()) {
leftSiblMove = leftSiblMove.get().moveToLastChild();
}
return leftSiblMove;
}
// Parent node.
return moveTo(node.getParentKey());
}
use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class PathSummaryReader method moveToNext.
@Override
public Move<? extends XdmNodeReadTrx> moveToNext() {
assertNotClosed();
final StructNode node = getStructuralNode();
if (node.hasRightSibling()) {
// Right sibling node.
return moveTo(node.getRightSiblingKey());
}
// Next following node.
return moveToNextFollowing();
}
use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class PathSummaryWriter method adaptForInsert.
/**
* Adapting everything for insert operations.
*
* @param newNode pointer of the new node to be inserted
* @param insertPos determines the position where to insert
* @param pageKind kind of subtree root page
* @throws SirixIOException if anything weird happens
*/
private void adaptForInsert(final Node newNode, final InsertPos insertPos, final PageKind pageKind) throws SirixIOException {
assert newNode != null;
assert insertPos != null;
assert pageKind != null;
if (newNode instanceof StructNode) {
final StructNode strucNode = (StructNode) newNode;
final StructNode parent = (StructNode) mPageWriteTrx.prepareEntryForModification(newNode.getParentKey(), pageKind, 0, Optional.<UnorderedKeyValuePage>empty());
parent.incrementChildCount();
if (insertPos == InsertPos.ASFIRSTCHILD) {
parent.setFirstChildKey(newNode.getNodeKey());
}
if (strucNode.hasRightSibling()) {
final StructNode rightSiblingNode = (StructNode) mPageWriteTrx.prepareEntryForModification(strucNode.getRightSiblingKey(), pageKind, 0, Optional.<UnorderedKeyValuePage>empty());
rightSiblingNode.setLeftSiblingKey(newNode.getNodeKey());
}
if (strucNode.hasLeftSibling()) {
final StructNode leftSiblingNode = (StructNode) mPageWriteTrx.prepareEntryForModification(strucNode.getLeftSiblingKey(), pageKind, 0, Optional.<UnorderedKeyValuePage>empty());
leftSiblingNode.setRightSiblingKey(newNode.getNodeKey());
}
}
}
use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class PathSummaryWriter method removePathSummaryNode.
/**
* Remove a path summary node with the specified PCR.
*
* @throws SirixException if Sirix fails to remove the path node
*/
private void removePathSummaryNode(final Remove remove) throws SirixException {
// Remove all descendant nodes.
if (remove == Remove.YES) {
for (final Axis axis = new DescendantAxis(mPathSummaryReader); axis.hasNext(); ) {
axis.next();
mPathSummaryReader.removeMapping(mPathSummaryReader.getNodeKey());
mPathSummaryReader.removeQNameMapping(mPathSummaryReader.getPathNode(), mPathSummaryReader.getName());
mPageWriteTrx.removeEntry(mPathSummaryReader.getNodeKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
}
}
// Adapt left sibling node if there is one.
if (mPathSummaryReader.hasLeftSibling()) {
final StructNode leftSibling = (StructNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getLeftSiblingKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
leftSibling.setRightSiblingKey(mPathSummaryReader.getRightSiblingKey());
}
// Adapt right sibling node if there is one.
if (mPathSummaryReader.hasRightSibling()) {
final StructNode rightSibling = (StructNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getRightSiblingKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
rightSibling.setLeftSiblingKey(mPathSummaryReader.getLeftSiblingKey());
}
// Adapt parent. If node has no left sibling it is a first child.
StructNode parent = (StructNode) mPageWriteTrx.prepareEntryForModification(mPathSummaryReader.getParentKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
if (!mPathSummaryReader.hasLeftSibling()) {
parent.setFirstChildKey(mPathSummaryReader.getRightSiblingKey());
}
parent.decrementChildCount();
// Remove node.
mPathSummaryReader.removeMapping(mPathSummaryReader.getNodeKey());
mPathSummaryReader.removeQNameMapping(mPathSummaryReader.getPathNode(), mPathSummaryReader.getName());
mPageWriteTrx.removeEntry(mPathSummaryReader.getNodeKey(), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
}
use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.
the class XdmNodeReadTrxImpl method getRightSiblingKind.
@Override
public Kind getRightSiblingKind() {
assertNotClosed();
if (mCurrentNode instanceof StructNode && hasRightSibling()) {
final long nodeKey = mCurrentNode.getNodeKey();
moveToRightSibling();
final Kind rightSiblKind = mCurrentNode.getKind();
moveTo(nodeKey);
return rightSiblKind;
}
return Kind.UNKNOWN;
}
Aggregations