Search in sources :

Example 26 with UnorderedKeyValuePage

use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.

the class PathSummaryWriter method resetPath.

/**
 * Reset the path node key of a node.
 *
 * @param newPathNodeKey path node key of new path node
 * @param oldLevel old level of node
 * @throws SirixIOException if an I/O error occurs
 */
private void resetPath(@Nonnegative final long newPathNodeKey, @Nonnegative final int oldLevel) throws SirixIOException {
    // Search for new path entry.
    mPathSummaryReader.moveTo(newPathNodeKey);
    final Axis filterAxis = new FilterAxis(new LevelOrderAxis.Builder(mPathSummaryReader).includeSelf().build(), new NameFilter(mPathSummaryReader, Utils.buildName(mNodeRtx.getName())), new PathKindFilter(mPathSummaryReader, mNodeRtx.getKind()), new PathLevelFilter(mPathSummaryReader, oldLevel));
    if (filterAxis.hasNext()) {
        filterAxis.next();
        // Set new path node.
        final NameNode node = (NameNode) mPageWriteTrx.prepareEntryForModification(mNodeRtx.getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
        node.setPathNodeKey(mPathSummaryReader.getNodeKey());
    } else {
        throw new IllegalStateException();
    }
}
Also used : ImmutableNameNode(org.sirix.node.interfaces.immutable.ImmutableNameNode) NameNode(org.sirix.node.interfaces.NameNode) NameFilter(org.sirix.axis.filter.NameFilter) PathLevelFilter(org.sirix.axis.filter.PathLevelFilter) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) 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) FilterAxis(org.sirix.axis.filter.FilterAxis) PathKindFilter(org.sirix.axis.filter.PathKindFilter) LevelOrderAxis(org.sirix.axis.LevelOrderAxis)

Example 27 with UnorderedKeyValuePage

use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.

the class PathSummaryWriter method resetPathNodeKey.

/**
 * Reset a path node key.
 *
 * @param nodeKey the nodeKey of the node to adapt
 * @throws SirixException if anything fails
 */
private void resetPathNodeKey(@Nonnegative final long nodeKey) throws SirixException {
    final NameNode currNode = (NameNode) mPageWriteTrx.prepareEntryForModification(nodeKey, PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
    currNode.setPathNodeKey(mPathSummaryReader.getNodeKey());
}
Also used : ImmutableNameNode(org.sirix.node.interfaces.immutable.ImmutableNameNode) NameNode(org.sirix.node.interfaces.NameNode) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage)

Example 28 with UnorderedKeyValuePage

use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.

the class PathSummaryWriter method getPathNodeKey.

/**
 * Insert a new path node or increment the counter of an existing node and return the path node
 * key.
 *
 * @param name the name of the path node to search for
 * @param pathKind the kind of the path node to search for
 * @return a path node key of the found node, or the path node key of a new inserted node
 * @throws SirixException if anything went wrong
 */
public long getPathNodeKey(final QNm name, final Kind pathKind) throws SirixException {
    final Kind kind = mNodeRtx.getNode().getKind();
    int level = 0;
    if (kind == Kind.DOCUMENT) {
        mPathSummaryReader.moveTo(Fixed.DOCUMENT_NODE_KEY.getStandardProperty());
    } else {
        movePathSummary();
        level = mPathSummaryReader.getLevel();
    }
    final long nodeKey = mPathSummaryReader.getNodeKey();
    final Axis axis = new FilterAxis(new ChildAxis(mPathSummaryReader), new NameFilter(mPathSummaryReader, pathKind == Kind.NAMESPACE ? name.getPrefix() : Utils.buildName(name)), new PathKindFilter(mPathSummaryReader, pathKind));
    long retVal = nodeKey;
    if (axis.hasNext()) {
        axis.next();
        retVal = mPathSummaryReader.getNodeKey();
        final PathNode pathNode = (PathNode) mPageWriteTrx.prepareEntryForModification(retVal, PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
        pathNode.incrementReferenceCount();
    } else {
        assert nodeKey == mPathSummaryReader.getNodeKey();
        insertPathAsFirstChild(name, pathKind, level + 1);
        retVal = mPathSummaryReader.getNodeKey();
    }
    return retVal;
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) NameFilter(org.sirix.axis.filter.NameFilter) PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) 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) FilterAxis(org.sirix.axis.filter.FilterAxis) PathKindFilter(org.sirix.axis.filter.PathKindFilter)

Example 29 with UnorderedKeyValuePage

use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.

the class AVLTreeWriter method rotateLeft.

/**
 * Left rotation.
 *
 * @param node node to be rotated
 * @throws SirixIOException if an I/O error occurs
 */
@SuppressWarnings({ "unchecked" })
private void rotateLeft(AVLNode<K, V> node) throws SirixIOException {
    moveTo(node.getNodeKey());
    AVLNode<K, V> right = ((AVLTreeReader<K, V>) moveToLastChild().get()).getAVLNode();
    node = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(node.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
    node.setRightChildKey(right.getLeftChildKey());
    if (right.hasLeftChild()) {
        final AVLNode<K, V> rightLeftChild = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(right.getLeftChildKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
        rightLeftChild.setParentKey(node.getNodeKey());
    }
    right = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(right.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
    right.setParentKey(node.getParentKey());
    if (node.getParentKey() == Fixed.DOCUMENT_NODE_KEY.getStandardProperty()) {
        final DocumentRootNode parent = (DocumentRootNode) mPageWriteTrx.prepareEntryForModification(Fixed.DOCUMENT_NODE_KEY.getStandardProperty(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
        parent.setFirstChildKey(right.getNodeKey());
    } else if (moveTo(node.getParentKey()).hasMoved() && mAVLTreeReader.getAVLNode().getLeftChildKey() == node.getNodeKey()) {
        final AVLNode<K, V> parent = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(mAVLTreeReader.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
        parent.setLeftChildKey(right.getNodeKey());
    } else {
        final AVLNode<K, V> parent = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(mAVLTreeReader.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
        parent.setRightChildKey(right.getNodeKey());
    }
    right = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(right.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
    right.setLeftChildKey(node.getNodeKey());
    node = (AVLNode<K, V>) mPageWriteTrx.prepareEntryForModification(node.getNodeKey(), mAVLTreeReader.mPageKind, mAVLTreeReader.mIndex, Optional.<UnorderedKeyValuePage>empty());
    node.setParentKey(right.getNodeKey());
}
Also used : DocumentRootNode(org.sirix.node.DocumentRootNode) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage)

Example 30 with UnorderedKeyValuePage

use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.

the class XdmNodeWriterTrxImpl method computeNewDeweyIDs.

/**
 * Compute the new DeweyIDs.
 *
 * @throws SirixException if anything went wrong
 */
private void computeNewDeweyIDs() throws SirixException {
    SirixDeweyID id = null;
    if (hasLeftSibling() && hasRightSibling()) {
        id = SirixDeweyID.newBetween(getLeftSiblingDeweyID().get(), getRightSiblingDeweyID().get());
    } else if (hasLeftSibling()) {
        id = SirixDeweyID.newBetween(getLeftSiblingDeweyID().get(), null);
    } else if (hasRightSibling()) {
        id = SirixDeweyID.newBetween(null, getRightSiblingDeweyID().get());
    } else {
        id = mNodeReader.getParentDeweyID().get().getNewChildID();
    }
    assert id != null;
    final long nodeKey = mNodeReader.getCurrentNode().getNodeKey();
    final StructNode root = (StructNode) getPageTransaction().prepareEntryForModification(nodeKey, PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
    root.setDeweyID(Optional.of(id));
    if (root.hasFirstChild()) {
        final Node firstChild = (Node) getPageTransaction().prepareEntryForModification(root.getFirstChildKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
        firstChild.setDeweyID(Optional.of(id.getNewChildID()));
        int previousLevel = getDeweyID().get().getLevel();
        mNodeReader.moveTo(firstChild.getNodeKey());
        int attributeNr = 0;
        int nspNr = 0;
        for (@SuppressWarnings("unused") final long key : LevelOrderAxis.newBuilder(this).includeNonStructuralNodes().build()) {
            Optional<SirixDeweyID> deweyID = Optional.<SirixDeweyID>empty();
            if (isAttribute()) {
                final long attNodeKey = mNodeReader.getNodeKey();
                if (attributeNr == 0) {
                    deweyID = Optional.of(mNodeReader.getParentDeweyID().get().getNewAttributeID());
                } else {
                    mNodeReader.moveTo(attributeNr - 1);
                    deweyID = Optional.of(SirixDeweyID.newBetween(mNodeReader.getNode().getDeweyID().get(), null));
                }
                mNodeReader.moveTo(attNodeKey);
                attributeNr++;
            } else if (isNamespace()) {
                final long nspNodeKey = mNodeReader.getNodeKey();
                if (nspNr == 0) {
                    deweyID = Optional.of(mNodeReader.getParentDeweyID().get().getNewNamespaceID());
                } else {
                    mNodeReader.moveTo(nspNr - 1);
                    deweyID = Optional.of(SirixDeweyID.newBetween(mNodeReader.getNode().getDeweyID().get(), null));
                }
                mNodeReader.moveTo(nspNodeKey);
                nspNr++;
            } else {
                attributeNr = 0;
                nspNr = 0;
                if (previousLevel + 1 == getDeweyID().get().getLevel()) {
                    if (mNodeReader.hasLeftSibling()) {
                        deweyID = Optional.of(SirixDeweyID.newBetween(getLeftSiblingDeweyID().get(), null));
                    } else {
                        deweyID = Optional.of(getParentDeweyID().get().getNewChildID());
                    }
                } else {
                    previousLevel++;
                    deweyID = Optional.of(getParentDeweyID().get().getNewChildID());
                }
            }
            final Node node = (Node) getPageTransaction().prepareEntryForModification(mNodeReader.getCurrentNode().getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
            node.setDeweyID(deweyID);
        }
        mNodeReader.moveTo(nodeKey);
    }
}
Also used : TextNode(org.sirix.node.TextNode) CommentNode(org.sirix.node.CommentNode) PINode(org.sirix.node.PINode) Node(org.sirix.node.interfaces.Node) ValueNode(org.sirix.node.interfaces.ValueNode) AttributeNode(org.sirix.node.AttributeNode) ImmutableNode(org.sirix.node.interfaces.immutable.ImmutableNode) StructNode(org.sirix.node.interfaces.StructNode) ElementNode(org.sirix.node.ElementNode) NamespaceNode(org.sirix.node.NamespaceNode) NameNode(org.sirix.node.interfaces.NameNode) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixDeweyID(org.sirix.node.SirixDeweyID) StructNode(org.sirix.node.interfaces.StructNode)

Aggregations

UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)42 StructNode (org.sirix.node.interfaces.StructNode)14 ElementNode (org.sirix.node.ElementNode)12 NameNode (org.sirix.node.interfaces.NameNode)11 Node (org.sirix.node.interfaces.Node)11 AttributeNode (org.sirix.node.AttributeNode)9 CommentNode (org.sirix.node.CommentNode)9 NamespaceNode (org.sirix.node.NamespaceNode)9 PINode (org.sirix.node.PINode)9 TextNode (org.sirix.node.TextNode)9 NodeDelegate (org.sirix.node.delegates.NodeDelegate)9 ValueNode (org.sirix.node.interfaces.ValueNode)9 ImmutableNode (org.sirix.node.interfaces.immutable.ImmutableNode)9 Record (org.sirix.node.interfaces.Record)8 NameNodeDelegate (org.sirix.node.delegates.NameNodeDelegate)7 StructNodeDelegate (org.sirix.node.delegates.StructNodeDelegate)7 ValNodeDelegate (org.sirix.node.delegates.ValNodeDelegate)7 Axis (org.sirix.api.Axis)6 DescendantAxis (org.sirix.axis.DescendantAxis)6 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)6