Search in sources :

Example 16 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class XPathParser method parseRelativePathExpr.

/**
 * Parses the the rule RelativePathExpr according to the following production rule:
 * <p>
 * [26] RelativePathExpr ::= StepExpr (("/" | "//") StepExpr)* .
 * </p>
 *
 * @throws SirixXPathException
 */
private void parseRelativePathExpr() throws SirixXPathException {
    parseStepExpr();
    while (mToken.getType() == TokenType.SLASH || mToken.getType() == TokenType.DESC_STEP) {
        if (is(TokenType.DESC_STEP, true)) {
            final Axis axis = new DescendantAxis(getTransaction(), IncludeSelf.YES);
            mPipeBuilder.addStep(axis);
        } else {
            // in this case the slash is just a separator
            consume(TokenType.SLASH, true);
        }
        parseStepExpr();
    }
}
Also used : DescendantAxis(org.sirix.axis.DescendantAxis) PrecedingAxis(org.sirix.axis.PrecedingAxis) Axis(org.sirix.api.Axis) DocumentNodeAxis(org.sirix.service.xml.xpath.filter.DocumentNodeAxis) FollowingAxis(org.sirix.axis.FollowingAxis) AbstractAxis(org.sirix.axis.AbstractAxis) AncestorAxis(org.sirix.axis.AncestorAxis) ChildAxis(org.sirix.axis.ChildAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) SelfAxis(org.sirix.axis.SelfAxis) DescendantAxis(org.sirix.axis.DescendantAxis) ParentAxis(org.sirix.axis.ParentAxis) AttributeAxis(org.sirix.axis.AttributeAxis) PrecedingSiblingAxis(org.sirix.axis.PrecedingSiblingAxis)

Example 17 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class MultipleCommitTest method testAttributeRemove.

@Test
public void testAttributeRemove() throws SirixException {
    DocumentCreater.create(holder.getWriter());
    holder.getWriter().commit();
    holder.getWriter().moveToDocumentRoot();
    final AbstractAxis postorderAxis = new PostOrderAxis(holder.getWriter());
    while (postorderAxis.hasNext()) {
        postorderAxis.next();
        if (holder.getWriter().getKind() == Kind.ELEMENT && holder.getWriter().getAttributeCount() > 0) {
            for (int i = 0, attrCount = holder.getWriter().getAttributeCount(); i < attrCount; i++) {
                holder.getWriter().moveToAttribute(i);
                holder.getWriter().remove();
            }
        }
    }
    holder.getWriter().commit();
    holder.getWriter().moveToDocumentRoot();
    int attrTouch = 0;
    final Axis descAxis = new DescendantAxis(holder.getWriter());
    while (descAxis.hasNext()) {
        descAxis.next();
        if (holder.getWriter().getKind() == Kind.ELEMENT) {
            for (int i = 0, attrCount = holder.getWriter().getAttributeCount(); i < attrCount; i++) {
                if (holder.getWriter().moveToAttribute(i).hasMoved()) {
                    attrTouch++;
                } else {
                    throw new IllegalStateException("Should never occur!");
                }
            }
        }
    }
    assertEquals(0, attrTouch);
}
Also used : PostOrderAxis(org.sirix.axis.PostOrderAxis) AbstractAxis(org.sirix.axis.AbstractAxis) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) PostOrderAxis(org.sirix.axis.PostOrderAxis) DescendantAxis(org.sirix.axis.DescendantAxis) AbstractAxis(org.sirix.axis.AbstractAxis) Test(org.junit.Test)

Example 18 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class ConcurrentAxisTest method testPartConcurrentDescAxis2.

/**
 * Test concurrent.
 *
 * @throws SirixXPathException
 */
// @Bench
@Test
public void testPartConcurrentDescAxis2() throws Exception {
    /* query: //regions/africa//location */
    final int resultNumber = 55;
    final XdmNodeReadTrx firstConcurrRtx = holder.getResourceManager().beginNodeReadTrx();
    final Axis axis = new NestedAxis(new NestedAxis(new FilterAxis(new DescendantAxis(firstConcurrRtx, IncludeSelf.YES), new NameFilter(firstConcurrRtx, "regions")), new FilterAxis(new ChildAxis(firstConcurrRtx), new NameFilter(firstConcurrRtx, "africa"))), new ConcurrentAxis(firstConcurrRtx, new FilterAxis(new DescendantAxis(holder.getReader(), IncludeSelf.YES), new NameFilter(holder.getReader(), "location"))));
    for (int i = 0; i < resultNumber; i++) {
        assertEquals(true, axis.hasNext());
        axis.next();
    }
    assertEquals(axis.hasNext(), false);
}
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 19 with DescendantAxis

use of org.sirix.axis.DescendantAxis 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 20 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class ElementFilterTest method testFluentIterable.

@Test
public void testFluentIterable() throws SirixException {
    final XdmNodeReadTrx rtx = holder.getReader();
    final Iterator<Long> results = FluentIterable.from(new DescendantAxis(rtx)).filter(new ElementFilter(rtx)).limit(2).iterator();
    AbsAxisTest.testIterable(results, new long[] { 1, 5 });
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Aggregations

DescendantAxis (org.sirix.axis.DescendantAxis)44 Axis (org.sirix.api.Axis)27 Test (org.junit.Test)18 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)17 FilterAxis (org.sirix.axis.filter.FilterAxis)16 ChildAxis (org.sirix.axis.ChildAxis)14 QNm (org.brackit.xquery.atomic.QNm)7 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)7 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)7 NameFilter (org.sirix.axis.filter.NameFilter)7 NestedAxis (org.sirix.axis.NestedAxis)6 PostOrderAxis (org.sirix.axis.PostOrderAxis)6 PathSummaryReader (org.sirix.index.path.summary.PathSummaryReader)6 AbstractAxis (org.sirix.axis.AbstractAxis)5 AncestorAxis (org.sirix.axis.AncestorAxis)5 FollowingAxis (org.sirix.axis.FollowingAxis)5 FollowingSiblingAxis (org.sirix.axis.FollowingSiblingAxis)5 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)5 ParentAxis (org.sirix.axis.ParentAxis)5 PrecedingAxis (org.sirix.axis.PrecedingAxis)5