Search in sources :

Example 1 with NestedAxis

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

the class ExpressionSingle method add.

/**
 * Adds a new Axis to the expression chain. The first axis that is added has to be stored till a
 * second axis is added. When the second axis is added, it is nested with the first one and builds
 * the execution chain.
 *
 * @param pAx the axis to add
 */
public void add(final Axis pAx) {
    Axis axis = pAx;
    if (isDupOrd(axis)) {
        axis = new DupFilterAxis(axis.getTrx(), axis);
        DupState.nodup = true;
    }
    switch(mNumber) {
        case 0:
            mFirstAxis = axis;
            mNumber++;
            break;
        case 1:
            mExpr = new NestedAxis(mFirstAxis, axis);
            mNumber++;
            break;
        default:
            final Axis cache = mExpr;
            mExpr = new NestedAxis(cache, axis);
    }
}
Also used : DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) NestedAxis(org.sirix.axis.NestedAxis) AncestorAxis(org.sirix.axis.AncestorAxis) PrecedingAxis(org.sirix.axis.PrecedingAxis) Axis(org.sirix.api.Axis) NestedAxis(org.sirix.axis.NestedAxis) ChildAxis(org.sirix.axis.ChildAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) UnionAxis(org.sirix.service.xml.xpath.expr.UnionAxis) FollowingAxis(org.sirix.axis.FollowingAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) ParentAxis(org.sirix.axis.ParentAxis) DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) PrecedingSiblingAxis(org.sirix.axis.PrecedingSiblingAxis)

Example 2 with NestedAxis

use of org.sirix.axis.NestedAxis 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 3 with NestedAxis

use of org.sirix.axis.NestedAxis 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 4 with NestedAxis

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

the class ExpressionSingleTest method testDup.

@Test
public void testDup() throws SirixException {
    ExpressionSingle builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    assertTrue(builder.getExpr() instanceof NestedAxis);
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    assertEquals(true, builder.isOrdered());
    assertTrue(builder.getExpr() instanceof NestedAxis);
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new ChildAxis(holder.getReader()));
    assertEquals(false, builder.isOrdered());
    builder = new ExpressionSingle();
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new ParentAxis(holder.getReader()));
    assertEquals(true, builder.isOrdered());
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new FollowingSiblingAxis(holder.getReader()));
    assertEquals(false, builder.isOrdered());
    builder = new ExpressionSingle();
    builder.add(new UnionAxis(holder.getReader(), new DescendantAxis(holder.getReader()), new ParentAxis(holder.getReader())));
    assertEquals(false, builder.isOrdered());
    assertTrue(builder.getExpr() instanceof DupFilterAxis);
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) ParentAxis(org.sirix.axis.ParentAxis) NestedAxis(org.sirix.axis.NestedAxis) DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) UnionAxis(org.sirix.service.xml.xpath.expr.UnionAxis) Test(org.junit.Test)

Example 5 with NestedAxis

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

the class ExpressionSingleTest method testAdd.

@Test
public void testAdd() throws SirixException {
    // Verify.
    final ExpressionSingle builder = new ExpressionSingle();
    // test one axis
    AbstractAxis self = new SelfAxis(holder.getReader());
    builder.add(self);
    assertEquals(builder.getExpr(), self);
    // test 2 axis
    AbstractAxis axis1 = new SelfAxis(holder.getReader());
    AbstractAxis axis2 = new SelfAxis(holder.getReader());
    builder.add(axis1);
    builder.add(axis2);
    assertTrue(builder.getExpr() instanceof NestedAxis);
}
Also used : SelfAxis(org.sirix.axis.SelfAxis) AbstractAxis(org.sirix.axis.AbstractAxis) NestedAxis(org.sirix.axis.NestedAxis) Test(org.junit.Test)

Aggregations

NestedAxis (org.sirix.axis.NestedAxis)7 Test (org.junit.Test)6 ChildAxis (org.sirix.axis.ChildAxis)6 DescendantAxis (org.sirix.axis.DescendantAxis)6 Axis (org.sirix.api.Axis)5 FilterAxis (org.sirix.axis.filter.FilterAxis)5 NameFilter (org.sirix.axis.filter.NameFilter)4 XPathAxis (org.sirix.service.xml.xpath.XPathAxis)4 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)3 FollowingSiblingAxis (org.sirix.axis.FollowingSiblingAxis)2 ParentAxis (org.sirix.axis.ParentAxis)2 UnionAxis (org.sirix.service.xml.xpath.expr.UnionAxis)2 DupFilterAxis (org.sirix.service.xml.xpath.filter.DupFilterAxis)2 AbstractAxis (org.sirix.axis.AbstractAxis)1 AncestorAxis (org.sirix.axis.AncestorAxis)1 FollowingAxis (org.sirix.axis.FollowingAxis)1 PrecedingAxis (org.sirix.axis.PrecedingAxis)1 PrecedingSiblingAxis (org.sirix.axis.PrecedingSiblingAxis)1 SelfAxis (org.sirix.axis.SelfAxis)1