Search in sources :

Example 1 with StructNode

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());
}
Also used : StructNode(org.sirix.node.interfaces.StructNode)

Example 2 with StructNode

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();
}
Also used : StructNode(org.sirix.node.interfaces.StructNode)

Example 3 with StructNode

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());
        }
    }
}
Also used : UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) StructNode(org.sirix.node.interfaces.StructNode)

Example 4 with StructNode

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());
}
Also used : UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) ChildAxis(org.sirix.axis.ChildAxis) PostOrderAxis(org.sirix.axis.PostOrderAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) LevelOrderAxis(org.sirix.axis.LevelOrderAxis) StructNode(org.sirix.node.interfaces.StructNode)

Example 5 with StructNode

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;
}
Also used : PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) StructNode(org.sirix.node.interfaces.StructNode)

Aggregations

StructNode (org.sirix.node.interfaces.StructNode)41 SirixDeweyID (org.sirix.node.SirixDeweyID)12 SirixUsageException (org.sirix.exception.SirixUsageException)11 ElementNode (org.sirix.node.ElementNode)10 TextNode (org.sirix.node.TextNode)8 ImmutableNode (org.sirix.node.interfaces.immutable.ImmutableNode)8 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)8 CommentNode (org.sirix.node.CommentNode)6 PINode (org.sirix.node.PINode)6 AttributeNode (org.sirix.node.AttributeNode)5 Kind (org.sirix.node.Kind)5 NamespaceNode (org.sirix.node.NamespaceNode)5 NameNode (org.sirix.node.interfaces.NameNode)5 Node (org.sirix.node.interfaces.Node)5 ValueNode (org.sirix.node.interfaces.ValueNode)5 PageKind (org.sirix.page.PageKind)5 Optional (java.util.Optional)3 PostOrderAxis (org.sirix.axis.PostOrderAxis)3 Axis (org.sirix.api.Axis)2 DescendantAxis (org.sirix.axis.DescendantAxis)2