Search in sources :

Example 6 with NameNode

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

the class NameIndexListener method listen.

@Override
public void listen(ChangeType type, @Nonnull ImmutableNode node, long pathNodeKey) throws SirixIOException {
    if (node instanceof NameNode) {
        final NameNode nameNode = (NameNode) node;
        final QNm name = nameNode.getName();
        final boolean included = (mIncludes.isEmpty() || mIncludes.contains(name));
        final boolean excluded = (!mExcludes.isEmpty() && mExcludes.contains(name));
        if (!included || excluded) {
            return;
        }
        switch(type) {
            case INSERT:
                final Optional<NodeReferences> textReferences = mAVLTreeWriter.get(name, SearchMode.EQUAL);
                if (textReferences.isPresent()) {
                    setNodeReferences(node, textReferences.get(), name);
                } else {
                    setNodeReferences(node, new NodeReferences(), name);
                }
                break;
            case DELETE:
                mAVLTreeWriter.remove(name, node.getNodeKey());
                break;
            default:
        }
    }
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) QNm(org.brackit.xquery.atomic.QNm) NodeReferences(org.sirix.index.avltree.keyvalue.NodeReferences)

Example 7 with NameNode

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

the class XdmNodeWriterTrxImpl method moveSubtreeToFirstChild.

@Override
public XdmNodeWriteTrx moveSubtreeToFirstChild(@Nonnegative final long fromKey) throws SirixException, IllegalArgumentException {
    acquireLock();
    try {
        Preconditions.checkArgument(fromKey >= 0 && fromKey <= getMaxNodeKey(), "Argument must be a valid node key!");
        Preconditions.checkArgument(fromKey != getCurrentNode().getNodeKey(), "Can't move itself to right sibling of itself!");
        @SuppressWarnings("unchecked") final Optional<? extends Node> node = (Optional<? extends Node>) getPageTransaction().getRecord(fromKey, PageKind.RECORDPAGE, -1);
        if (!node.isPresent()) {
            throw new IllegalStateException("Node to move must exist!");
        }
        final Node nodeToMove = node.get();
        if (nodeToMove instanceof StructNode && getCurrentNode().getKind() == Kind.ELEMENT) {
            // Safe to cast (because IStructNode is a subtype of INode).
            checkAncestors(nodeToMove);
            checkAccessAndCommit();
            final ElementNode nodeAnchor = (ElementNode) getCurrentNode();
            // Check that it's not already the first child.
            if (nodeAnchor.getFirstChildKey() != nodeToMove.getNodeKey()) {
                final StructNode toMove = (StructNode) nodeToMove;
                // Adapt index-structures (before move).
                adaptSubtreeForMove(toMove, ChangeType.DELETE);
                // Adapt hashes.
                adaptHashesForMove(toMove);
                // Adapt pointers and merge sibling text nodes.
                adaptForMove(toMove, nodeAnchor, InsertPos.ASFIRSTCHILD);
                mNodeReader.moveTo(toMove.getNodeKey());
                adaptHashesWithAdd();
                // Adapt path summary.
                if (mBuildPathSummary && toMove instanceof NameNode) {
                    final NameNode moved = (NameNode) toMove;
                    mPathSummaryWriter.adaptPathForChangedNode(moved, getName(), moved.getURIKey(), moved.getPrefixKey(), moved.getLocalNameKey(), OPType.MOVED);
                }
                // Adapt index-structures (after move).
                adaptSubtreeForMove(toMove, ChangeType.INSERT);
                // Compute and assign new DeweyIDs.
                if (mDeweyIDsStored) {
                    computeNewDeweyIDs();
                }
            }
            return this;
        } else {
            throw new SirixUsageException("Move is not allowed if moved node is not an ElementNode and the node isn't inserted at an element node!");
        }
    } finally {
        unLock();
    }
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) Optional(java.util.Optional) 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) ElementNode(org.sirix.node.ElementNode) SirixUsageException(org.sirix.exception.SirixUsageException) StructNode(org.sirix.node.interfaces.StructNode)

Example 8 with NameNode

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

the class XdmNodeWriterTrxImpl method removeName.

/**
 * Remove a name from the {@link NamePage} reference and the path summary if needed.
 *
 * @throws SirixException if Sirix fails
 */
private void removeName() throws SirixException {
    if (getCurrentNode() instanceof NameNode) {
        final NameNode node = ((NameNode) getCurrentNode());
        final Kind nodeKind = node.getKind();
        final NamePage page = ((NamePage) getPageTransaction().getActualRevisionRootPage().getNamePageReference().getPage());
        page.removeName(node.getPrefixKey(), nodeKind);
        page.removeName(node.getLocalNameKey(), nodeKind);
        page.removeName(node.getURIKey(), Kind.NAMESPACE);
        assert nodeKind != Kind.DOCUMENT;
        if (mBuildPathSummary) {
            mPathSummaryWriter.remove(node, nodeKind, page);
        }
    }
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) NamePage(org.sirix.page.NamePage)

Example 9 with NameNode

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

the class XdmNodeWriterTrxImpl method moveSubtreeToRightSibling.

@Override
public XdmNodeWriteTrx moveSubtreeToRightSibling(@Nonnegative final long fromKey) throws SirixException {
    acquireLock();
    try {
        if (fromKey < 0 || fromKey > getMaxNodeKey()) {
            throw new IllegalArgumentException("Argument must be a valid node key!");
        }
        if (fromKey == getCurrentNode().getNodeKey()) {
            throw new IllegalArgumentException("Can't move itself to first child of itself!");
        }
        // Save: Every node in the "usual" node page is of type Node.
        @SuppressWarnings("unchecked") final Optional<? extends Node> node = (Optional<? extends Node>) getPageTransaction().getRecord(fromKey, PageKind.RECORDPAGE, -1);
        if (!node.isPresent()) {
            throw new IllegalStateException("Node to move must exist!");
        }
        final Node nodeToMove = node.get();
        if (nodeToMove instanceof StructNode && getCurrentNode() instanceof StructNode) {
            final StructNode toMove = (StructNode) nodeToMove;
            checkAncestors(toMove);
            checkAccessAndCommit();
            final StructNode nodeAnchor = (StructNode) getCurrentNode();
            if (nodeAnchor.getRightSiblingKey() != nodeToMove.getNodeKey()) {
                final long parentKey = toMove.getParentKey();
                // Adapt hashes.
                adaptHashesForMove(toMove);
                // Adapt pointers and merge sibling text nodes.
                adaptForMove(toMove, nodeAnchor, InsertPos.ASRIGHTSIBLING);
                mNodeReader.moveTo(toMove.getNodeKey());
                adaptHashesWithAdd();
                // Adapt path summary.
                if (mBuildPathSummary && toMove instanceof NameNode) {
                    final NameNode moved = (NameNode) toMove;
                    final OPType type = moved.getParentKey() == parentKey ? OPType.MOVEDSAMELEVEL : OPType.MOVED;
                    mPathSummaryWriter.adaptPathForChangedNode(moved, getName(), moved.getURIKey(), moved.getPrefixKey(), moved.getLocalNameKey(), type);
                }
                // Recompute DeweyIDs if they are used.
                if (mDeweyIDsStored) {
                    computeNewDeweyIDs();
                }
            }
            return this;
        } else {
            throw new SirixUsageException("Move is not allowed if moved node is not an ElementNode or TextNode and the node isn't inserted at an ElementNode or TextNode!");
        }
    } finally {
        unLock();
    }
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) Optional(java.util.Optional) OPType(org.sirix.index.path.summary.PathSummaryWriter.OPType) 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) SirixUsageException(org.sirix.exception.SirixUsageException) StructNode(org.sirix.node.interfaces.StructNode)

Aggregations

NameNode (org.sirix.node.interfaces.NameNode)9 Axis (org.sirix.api.Axis)3 DescendantAxis (org.sirix.axis.DescendantAxis)3 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)3 PostOrderAxis (org.sirix.axis.PostOrderAxis)3 SirixUsageException (org.sirix.exception.SirixUsageException)3 ElementNode (org.sirix.node.ElementNode)3 ValueNode (org.sirix.node.interfaces.ValueNode)3 ImmutableNameNode (org.sirix.node.interfaces.immutable.ImmutableNameNode)3 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)3 Optional (java.util.Optional)2 ChildAxis (org.sirix.axis.ChildAxis)2 FilterAxis (org.sirix.axis.filter.FilterAxis)2 NameFilter (org.sirix.axis.filter.NameFilter)2 PathKindFilter (org.sirix.axis.filter.PathKindFilter)2 PathLevelFilter (org.sirix.axis.filter.PathLevelFilter)2 AttributeNode (org.sirix.node.AttributeNode)2 CommentNode (org.sirix.node.CommentNode)2 Kind (org.sirix.node.Kind)2 NamespaceNode (org.sirix.node.NamespaceNode)2