Search in sources :

Example 31 with Axis

use of org.sirix.api.Axis in project sirix by sirixdb.

the class ConcurrentAxisTest method testConcurrent.

/**
 * Test concurrent.
 *
 * @throws SirixException
 *
 * @throws SirixXPathException
 */
// @Bench
@Test
public void testConcurrent() throws Exception {
    /* query: //regions/africa//location */
    final int resultNumber = 55;
    final XdmNodeReadTrx firstConcurrRtx = holder.getResourceManager().beginNodeReadTrx();
    final XdmNodeReadTrx secondConcurrRtx = holder.getResourceManager().beginNodeReadTrx();
    final XdmNodeReadTrx thirdConcurrRtx = holder.getResourceManager().beginNodeReadTrx();
    final XdmNodeReadTrx firstRtx = holder.getResourceManager().beginNodeReadTrx();
    final XdmNodeReadTrx secondRtx = holder.getResourceManager().beginNodeReadTrx();
    final XdmNodeReadTrx thirdRtx = holder.getResourceManager().beginNodeReadTrx();
    final Axis axis = new NestedAxis(new NestedAxis(new ConcurrentAxis(firstConcurrRtx, new FilterAxis(new DescendantAxis(firstRtx, IncludeSelf.YES), new NameFilter(firstRtx, "regions"))), new ConcurrentAxis(secondConcurrRtx, new FilterAxis(new ChildAxis(secondRtx), new NameFilter(secondRtx, "africa")))), new ConcurrentAxis(thirdConcurrRtx, new FilterAxis(new DescendantAxis(thirdRtx, IncludeSelf.YES), new NameFilter(thirdRtx, "location"))));
    for (int i = 0; i < resultNumber; i++) {
        assertEquals(true, axis.hasNext());
        axis.next();
    }
    assertEquals(false, axis.hasNext());
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) NameFilter(org.sirix.axis.filter.NameFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) NestedAxis(org.sirix.axis.NestedAxis) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) NestedAxis(org.sirix.axis.NestedAxis) ChildAxis(org.sirix.axis.ChildAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) Test(org.junit.Test)

Example 32 with Axis

use of org.sirix.api.Axis in project sirix by sirixdb.

the class NestedAxisTest method testNestedAxisTest3.

@Test
public void testNestedAxisTest3() throws SirixException {
    final XdmNodeReadTrx rtx = holder.getReader();
    // Find desceFndants starting from nodeKey 0L (root).
    rtx.moveToDocumentRoot();
    // XPath expression p:a/node():
    // Part: /p:a
    final Axis childA = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "p:a"));
    // Part: /node()
    final Axis childNode = new FilterAxis(new ChildAxis(rtx), new NodeFilter(rtx));
    // Part: /p:a/node():
    final Axis axis = new NestedAxis(childA, childNode);
    AbsAxisTest.testIAxisConventions(axis, new long[] { 4L, 5L, 8L, 9L, 13L });
}
Also used : NameFilter(org.sirix.axis.filter.NameFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) FilterAxis(org.sirix.axis.filter.FilterAxis) Axis(org.sirix.api.Axis) FilterAxis(org.sirix.axis.filter.FilterAxis) NodeFilter(org.sirix.axis.filter.NodeFilter) Test(org.junit.Test)

Example 33 with Axis

use of org.sirix.api.Axis in project sirix by sirixdb.

the class NestedAxisTest method testNestedAxisTest2.

@Test
public void testNestedAxisTest2() throws SirixException {
    final XdmNodeReadTrx rtx = holder.getReader();
    // Find descendants starting from nodeKey 0L (root).
    rtx.moveToDocumentRoot();
    // XPath expression /[:a/b/@p:x]
    // Part: /p:a
    final Axis childA = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "p:a"));
    // Part: /b
    final Axis childB = new FilterAxis(new ChildAxis(rtx), new NameFilter(rtx, "b"));
    // Part: /@x
    final Axis attributeX = new FilterAxis(new AttributeAxis(rtx), new NameFilter(rtx, "p:x"));
    // Part: /p:a/b/@p:x
    final Axis axis = new NestedAxis(new NestedAxis(childA, childB), attributeX);
    AbsAxisTest.testIAxisConventions(axis, new long[] { 10L });
}
Also used : NameFilter(org.sirix.axis.filter.NameFilter) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) FilterAxis(org.sirix.axis.filter.FilterAxis) Axis(org.sirix.api.Axis) FilterAxis(org.sirix.axis.filter.FilterAxis) Test(org.junit.Test)

Example 34 with Axis

use of org.sirix.api.Axis in project sirix by sirixdb.

the class XdmNodeWriterTrxImpl method adaptSubtreeForMove.

/**
 * Adapt subtree regarding the index-structures.
 *
 * @param toMove node which is moved (either before the move, or after the move)
 * @param type the type of change (either deleted from the old position or inserted into the new
 *        position)
 * @throws SirixIOException if an I/O exception occurs
 */
private void adaptSubtreeForMove(final Node node, final ChangeType type) throws SirixIOException {
    assert type != null;
    final long beforeNodeKey = getNode().getNodeKey();
    moveTo(node.getNodeKey());
    final Axis axis = new DescendantAxis(this, IncludeSelf.YES);
    while (axis.hasNext()) {
        axis.next();
        for (int i = 0, attCount = getAttributeCount(); i < attCount; i++) {
            moveToAttribute(i);
            final ImmutableAttribute att = (ImmutableAttribute) getNode();
            mIndexController.notifyChange(type, att, att.getPathNodeKey());
            moveToParent();
        }
        for (int i = 0, nspCount = getNamespaceCount(); i < nspCount; i++) {
            moveToAttribute(i);
            final ImmutableNamespace nsp = (ImmutableNamespace) getNode();
            mIndexController.notifyChange(type, nsp, nsp.getPathNodeKey());
            moveToParent();
        }
        long pathNodeKey = -1;
        if (getNode() instanceof ValueNode && getNode().getParentKey() != Fixed.DOCUMENT_NODE_KEY.getStandardProperty()) {
            final long nodeKey = getNode().getNodeKey();
            pathNodeKey = moveToParent().get().getNameNode().getPathNodeKey();
            moveTo(nodeKey);
        } else if (getNode() instanceof NameNode) {
            pathNodeKey = getNameNode().getPathNodeKey();
        }
        mIndexController.notifyChange(type, getNode(), pathNodeKey);
    }
    moveTo(beforeNodeKey);
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) ValueNode(org.sirix.node.interfaces.ValueNode) ImmutableNamespace(org.sirix.node.immutable.ImmutableNamespace) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) LevelOrderAxis(org.sirix.axis.LevelOrderAxis) PostOrderAxis(org.sirix.axis.PostOrderAxis) DescendantAxis(org.sirix.axis.DescendantAxis) ImmutableAttribute(org.sirix.node.immutable.ImmutableAttribute)

Example 35 with Axis

use of org.sirix.api.Axis 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)

Aggregations

Axis (org.sirix.api.Axis)73 DescendantAxis (org.sirix.axis.DescendantAxis)39 FilterAxis (org.sirix.axis.filter.FilterAxis)38 ChildAxis (org.sirix.axis.ChildAxis)23 UnionAxis (org.sirix.service.xml.xpath.expr.UnionAxis)19 DupFilterAxis (org.sirix.service.xml.xpath.filter.DupFilterAxis)19 ForAxis (org.sirix.axis.ForAxis)17 PredicateFilterAxis (org.sirix.axis.filter.PredicateFilterAxis)17 ExceptAxis (org.sirix.service.xml.xpath.expr.ExceptAxis)17 IfAxis (org.sirix.service.xml.xpath.expr.IfAxis)17 IntersectAxis (org.sirix.service.xml.xpath.expr.IntersectAxis)17 RangeAxis (org.sirix.service.xml.xpath.expr.RangeAxis)17 SequenceAxis (org.sirix.service.xml.xpath.expr.SequenceAxis)17 VariableAxis (org.sirix.service.xml.xpath.expr.VariableAxis)17 AddOpAxis (org.sirix.service.xml.xpath.operators.AddOpAxis)17 DivOpAxis (org.sirix.service.xml.xpath.operators.DivOpAxis)17 IDivOpAxis (org.sirix.service.xml.xpath.operators.IDivOpAxis)17 ModOpAxis (org.sirix.service.xml.xpath.operators.ModOpAxis)17 MulOpAxis (org.sirix.service.xml.xpath.operators.MulOpAxis)17 SubOpAxis (org.sirix.service.xml.xpath.operators.SubOpAxis)17