Search in sources :

Example 21 with StructNode

use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.

the class XdmNodeWriterTrxImpl method remove.

@Override
public XdmNodeWriteTrx remove() throws SirixException {
    checkAccessAndCommit();
    acquireLock();
    try {
        if (getCurrentNode().getKind() == Kind.DOCUMENT) {
            throw new SirixUsageException("Document root can not be removed.");
        } else if (getCurrentNode() instanceof StructNode) {
            final StructNode node = (StructNode) mNodeReader.getCurrentNode();
            // Remove subtree.
            for (final Axis axis = new PostOrderAxis(this); axis.hasNext(); ) {
                axis.next();
                // Remove name.
                removeName();
                // Remove namespaces and attributes.
                removeNonStructural();
                // Remove text value.
                removeValue();
                // Then remove node.
                getPageTransaction().removeEntry(getCurrentNode().getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
            }
            // Adapt hashes and neighbour nodes as well as the name from the
            // NamePage mapping if it's not a text node.
            mNodeReader.setCurrentNode(node);
            adaptHashesWithRemove();
            adaptForRemove(node, PageKind.RECORDPAGE);
            mNodeReader.setCurrentNode(node);
            // Remove the name of subtree-root.
            if (node.getKind() == Kind.ELEMENT) {
                removeName();
            }
            // of text merges.
            if (mNodeReader.hasRightSibling() && moveTo(node.getRightSiblingKey()).hasMoved()) {
            } else if (node.hasLeftSibling()) {
                moveTo(node.getLeftSiblingKey());
            } else {
                moveTo(node.getParentKey());
            }
        } else if (getCurrentNode().getKind() == Kind.ATTRIBUTE) {
            final ImmutableNode node = mNodeReader.getCurrentNode();
            final ElementNode parent = (ElementNode) getPageTransaction().prepareEntryForModification(node.getParentKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
            parent.removeAttribute(node.getNodeKey());
            adaptHashesWithRemove();
            getPageTransaction().removeEntry(node.getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
            removeName();
            mIndexController.notifyChange(ChangeType.DELETE, getNode(), parent.getPathNodeKey());
            moveToParent();
        } else if (getCurrentNode().getKind() == Kind.NAMESPACE) {
            final ImmutableNode node = mNodeReader.getCurrentNode();
            final ElementNode parent = (ElementNode) getPageTransaction().prepareEntryForModification(node.getParentKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
            parent.removeNamespace(node.getNodeKey());
            adaptHashesWithRemove();
            getPageTransaction().removeEntry(node.getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
            removeName();
            moveToParent();
        }
        return this;
    } finally {
        unLock();
    }
}
Also used : PostOrderAxis(org.sirix.axis.PostOrderAxis) ImmutableNode(org.sirix.node.interfaces.immutable.ImmutableNode) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixUsageException(org.sirix.exception.SirixUsageException) ElementNode(org.sirix.node.ElementNode) Axis(org.sirix.api.Axis) LevelOrderAxis(org.sirix.axis.LevelOrderAxis) PostOrderAxis(org.sirix.axis.PostOrderAxis) DescendantAxis(org.sirix.axis.DescendantAxis) StructNode(org.sirix.node.interfaces.StructNode)

Example 22 with StructNode

use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.

the class PathSummaryReader method moveTo.

@Override
public Move<? extends PathSummaryReader> moveTo(final long nodeKey) {
    assertNotClosed();
    // Remember old node and fetch new one.
    final StructNode oldNode = mCurrentNode;
    Optional<? extends StructNode> newNode;
    try {
        // Immediately return node from item list if node key negative.
        @SuppressWarnings("unchecked") final Optional<? extends StructNode> node = (Optional<? extends StructNode>) mPageReadTrx.getRecord(nodeKey, PageKind.PATHSUMMARYPAGE, 0);
        newNode = node;
    } catch (final SirixIOException e) {
        newNode = Optional.empty();
    }
    if (newNode.isPresent()) {
        mCurrentNode = newNode.get();
        return Move.moved(this);
    } else {
        mCurrentNode = oldNode;
        return Move.notMoved();
    }
}
Also used : Optional(java.util.Optional) SirixIOException(org.sirix.exception.SirixIOException) StructNode(org.sirix.node.interfaces.StructNode)

Example 23 with StructNode

use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.

the class XdmNodeReadTrxImpl method getRightSiblingDeweyID.

@Override
public Optional<SirixDeweyID> getRightSiblingDeweyID() {
    if (mResourceManager.getResourceConfig().mDeweyIDsStored) {
        final StructNode node = getStructuralNode();
        final long nodeKey = node.getNodeKey();
        Optional<SirixDeweyID> deweyID = Optional.<SirixDeweyID>empty();
        if (node.hasRightSibling()) {
            // Right sibling node.
            deweyID = moveTo(node.getRightSiblingKey()).get().getDeweyID();
        }
        moveTo(nodeKey);
        return deweyID;
    }
    return Optional.<SirixDeweyID>empty();
}
Also used : SirixDeweyID(org.sirix.node.SirixDeweyID) StructNode(org.sirix.node.interfaces.StructNode)

Example 24 with StructNode

use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.

the class XdmNodeReadTrxImpl method getLastChildKind.

@Override
public Kind getLastChildKind() {
    assertNotClosed();
    if (mCurrentNode instanceof StructNode && hasLastChild()) {
        final long nodeKey = mCurrentNode.getNodeKey();
        moveToLastChild();
        final Kind lastChildKind = mCurrentNode.getKind();
        moveTo(nodeKey);
        return lastChildKind;
    }
    return Kind.UNKNOWN;
}
Also used : PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) StructNode(org.sirix.node.interfaces.StructNode)

Example 25 with StructNode

use of org.sirix.node.interfaces.StructNode in project sirix by sirixdb.

the class XdmNodeReadTrxImpl 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)

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