Search in sources :

Example 6 with SirixDeweyID

use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.

the class UpdateTest method testFirstMoveToFirstChild.

@Test
public void testFirstMoveToFirstChild() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.moveTo(7);
    wtx.moveSubtreeToFirstChild(6);
    testFirstMoveToFirstChild(wtx);
    wtx.commit();
    testFirstMoveToFirstChild(wtx);
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testFirstMoveToFirstChild(rtx);
    rtx.moveToDocumentRoot();
    final Builder<SirixDeweyID> builder = ImmutableSet.<SirixDeweyID>builder();
    final ImmutableSet<SirixDeweyID> ids = builder.add(new SirixDeweyID("1")).add(new SirixDeweyID("1.3")).add(new SirixDeweyID("1.3.0.3")).add(new SirixDeweyID("1.3.1.3")).add(new SirixDeweyID("1.3.3")).add(new SirixDeweyID("1.3.5")).add(new SirixDeweyID("1.3.5.5")).add(new SirixDeweyID("1.3.5.5.3")).add(new SirixDeweyID("1.3.7")).add(new SirixDeweyID("1.3.9")).add(new SirixDeweyID("1.3.9.1.3")).add(new SirixDeweyID("1.3.9.3")).add(new SirixDeweyID("1.3.9.5")).add(new SirixDeweyID("1.3.11")).build();
    test(ids.iterator(), new NonStructuralWrapperAxis(new DescendantAxis(rtx, IncludeSelf.YES)));
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) NonStructuralWrapperAxis(org.sirix.axis.NonStructuralWrapperAxis) SirixDeweyID(org.sirix.node.SirixDeweyID) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Example 7 with SirixDeweyID

use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.

the class UpdateTest method testFirstMoveSubtreeToRightSibling.

@Test
public void testFirstMoveSubtreeToRightSibling() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.moveToDocumentRoot();
    for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
        System.out.println(nodeKey + ": " + wtx.getDeweyID());
    }
    wtx.moveTo(7);
    wtx.moveSubtreeToRightSibling(6);
    testFirstMoveSubtreeToRightSibling(wtx);
    wtx.moveToDocumentRoot();
    for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
        System.out.println(nodeKey + ": " + wtx.getDeweyID());
    }
    wtx.commit();
    wtx.moveToDocumentRoot();
    for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
        System.out.println(nodeKey + ": " + wtx.getDeweyID());
    }
    testFirstMoveSubtreeToRightSibling(wtx);
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testFirstMoveSubtreeToRightSibling(rtx);
    rtx.moveToDocumentRoot();
    final Builder<SirixDeweyID> builder = ImmutableSet.<SirixDeweyID>builder();
    final ImmutableSet<SirixDeweyID> ids = builder.add(new SirixDeweyID("1")).add(new SirixDeweyID("1.3")).add(new SirixDeweyID("1.3.0.3")).add(new SirixDeweyID("1.3.1.3")).add(new SirixDeweyID("1.3.3")).add(new SirixDeweyID("1.3.5")).add(new SirixDeweyID("1.3.5.5")).add(new SirixDeweyID("1.3.5.7")).add(new SirixDeweyID("1.3.7")).add(new SirixDeweyID("1.3.9")).add(new SirixDeweyID("1.3.9.1.3")).add(new SirixDeweyID("1.3.9.3")).add(new SirixDeweyID("1.3.9.5")).add(new SirixDeweyID("1.3.11")).build();
    test(ids.iterator(), new NonStructuralWrapperAxis(new DescendantAxis(rtx, IncludeSelf.YES)));
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) NonStructuralWrapperAxis(org.sirix.axis.NonStructuralWrapperAxis) SirixDeweyID(org.sirix.node.SirixDeweyID) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Example 8 with SirixDeweyID

use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.

the class XdmNodeReadTrxImpl method getFirstChildDeweyID.

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

Example 9 with SirixDeweyID

use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.

the class XdmNodeReadTrxImpl method getLeftSiblingDeweyID.

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

Example 10 with SirixDeweyID

use of org.sirix.node.SirixDeweyID in project sirix by sirixdb.

the class XdmNodeWriterTrxImpl method insertTextAsFirstChild.

@Override
public XdmNodeWriteTrx insertTextAsFirstChild(final String value) throws SirixException {
    checkNotNull(value);
    acquireLock();
    try {
        if (getCurrentNode() instanceof StructNode && !value.isEmpty()) {
            checkAccessAndCommit();
            final long pathNodeKey = getCurrentNode().getNodeKey();
            final long parentKey = getCurrentNode().getNodeKey();
            final long leftSibKey = Fixed.NULL_NODE_KEY.getStandardProperty();
            final long rightSibKey = ((StructNode) getCurrentNode()).getFirstChildKey();
            // Update value in case of adjacent text nodes.
            if (hasNode(rightSibKey)) {
                moveTo(rightSibKey);
                if (getCurrentNode().getKind() == Kind.TEXT) {
                    setValue(new StringBuilder(value).append(getValue()).toString());
                    adaptHashedWithUpdate(getCurrentNode().getHash());
                    return this;
                }
                moveTo(parentKey);
            }
            // Insert new text node if no adjacent text nodes are found.
            final byte[] textValue = getBytes(value);
            final Optional<SirixDeweyID> id = newFirstChildID();
            final TextNode node = mNodeFactory.createTextNode(parentKey, leftSibKey, rightSibKey, textValue, mCompression, id);
            // Adapt local nodes and hashes.
            mNodeReader.setCurrentNode(node);
            adaptForInsert(node, InsertPos.ASFIRSTCHILD, PageKind.RECORDPAGE);
            mNodeReader.setCurrentNode(node);
            adaptHashesWithAdd();
            // Index text value.
            mIndexController.notifyChange(ChangeType.INSERT, node, pathNodeKey);
            return this;
        } else {
            throw new SirixUsageException("Insert is not allowed if current node is not an ElementNode or TextNode!");
        }
    } finally {
        unLock();
    }
}
Also used : TextNode(org.sirix.node.TextNode) SirixDeweyID(org.sirix.node.SirixDeweyID) SirixUsageException(org.sirix.exception.SirixUsageException) StructNode(org.sirix.node.interfaces.StructNode)

Aggregations

SirixDeweyID (org.sirix.node.SirixDeweyID)25 StructNode (org.sirix.node.interfaces.StructNode)14 SirixUsageException (org.sirix.exception.SirixUsageException)10 ElementNode (org.sirix.node.ElementNode)6 TextNode (org.sirix.node.TextNode)6 Test (org.junit.Test)5 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)5 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)5 DescendantAxis (org.sirix.axis.DescendantAxis)5 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)5 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)5 CommentNode (org.sirix.node.CommentNode)4 PINode (org.sirix.node.PINode)4 Node (org.sirix.node.interfaces.Node)4 QNm (org.brackit.xquery.atomic.QNm)3 AttributeNode (org.sirix.node.AttributeNode)3 NamespaceNode (org.sirix.node.NamespaceNode)3 NodeDelegate (org.sirix.node.delegates.NodeDelegate)3 NameNode (org.sirix.node.interfaces.NameNode)3 ValueNode (org.sirix.node.interfaces.ValueNode)3