Search in sources :

Example 71 with XdmNodeReadTrx

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

the class TemporalFilterAxis method computeNext.

@Override
protected XdmNodeReadTrx computeNext() {
    while (mAxis.hasNext()) {
        final XdmNodeReadTrx rtx = mAxis.next();
        boolean filterResult = true;
        for (final Filter filter : mAxisFilter) {
            filter.setTrx(rtx);
            filterResult = filterResult && filter.filter();
            if (!filterResult) {
                break;
            }
        }
        if (filterResult) {
            return mAxis.getTrx();
        }
    }
    return endOfData();
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Filter(org.sirix.api.Filter)

Example 72 with XdmNodeReadTrx

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

the class LevelOrderAxis method nextKey.

@Override
protected long nextKey() {
    final XdmNodeReadTrx rtx = getTrx();
    // Determines if it's the first call to hasNext().
    if (mFirst) {
        mFirst = false;
        if (rtx.getKind() == Kind.ATTRIBUTE || rtx.getKind() == Kind.NAMESPACE) {
            return done();
        }
        if (isSelfIncluded() == IncludeSelf.YES) {
            return rtx.getNodeKey();
        } else {
            if (rtx.hasRightSibling()) {
                return rtx.getRightSiblingKey();
            } else if (rtx.hasFirstChild()) {
                return rtx.getFirstChildKey();
            } else {
                return done();
            }
        }
    }
    // Follow right sibling if there is one.
    if (rtx.hasRightSibling()) {
        processElement();
        // Add first child to queue.
        if (rtx.hasFirstChild()) {
            mFirstChilds.add(rtx.getFirstChildKey());
        }
        return rtx.getRightSiblingKey();
    }
    // Add first child to queue.
    processElement();
    if (rtx.hasFirstChild()) {
        mFirstChilds.add(rtx.getFirstChildKey());
    }
    // Then follow first child on stack.
    if (!mFirstChilds.isEmpty()) {
        mLevel++;
        // End traversal if level is reached.
        if (mLevel > mFilterLevel) {
            return done();
        }
        return mFirstChilds.pollFirst();
    }
    // Then follow first child if there is one.
    if (getTrx().hasFirstChild()) {
        mLevel++;
        // End traversal if level is reached.
        if (mLevel > mFilterLevel) {
            return done();
        }
        return getTrx().getFirstChildKey();
    }
    return done();
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx)

Example 73 with XdmNodeReadTrx

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

the class VersioningTest method test1.

/**
 * Test revisioning.
 *
 * @throws SirixException if anything in Sirix fails
 */
public void test1() throws SirixException {
    try (final ResourceManager manager = mDatabase.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build())) {
        XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
        for (int i = 0; i < Constants.NDP_NODE_COUNT - 1; i++) {
            wtx.insertElementAsFirstChild(new QNm("foo"));
        }
        wtx.commit();
        assertTrue(wtx.getNodeKey() == Constants.NDP_NODE_COUNT - 1);
        wtx.close();
        wtx = manager.beginNodeWriteTrx();
        setBaaaz(wtx);
        setFooBar(wtx);
        setFoooo(wtx);
        wtx.moveTo(Constants.NDP_NODE_COUNT - 1);
        fillNodePage(wtx);
        wtx.commit();
        wtx.close();
        wtx = manager.beginNodeWriteTrx();
        wtx.moveTo((Constants.NDP_NODE_COUNT << 1) - 1);
        fillNodePage(wtx);
        wtx.commit();
        wtx.close();
        wtx = manager.beginNodeWriteTrx();
        wtx.moveTo((Constants.NDP_NODE_COUNT * 3) - 1);
        fillNodePage(wtx);
        wtx.commit();
        wtx.close();
        wtx = manager.beginNodeWriteTrx();
        wtx.moveTo((Constants.NDP_NODE_COUNT << 2) - 1);
        fillNodePage(wtx);
        wtx.commit();
        wtx.close();
        try (final XdmNodeReadTrx rtx = manager.beginNodeReadTrx()) {
            assertTrue(rtx.moveToFirstChild().hasMoved());
            assertEquals(new QNm("foobar"), rtx.getName());
            assertTrue(rtx.moveToFirstChild().hasMoved());
            assertEquals(new QNm("foooo"), rtx.getName());
            for (int i = 0; i < Constants.NDP_NODE_COUNT - 4; i++) {
                assertTrue(rtx.moveToFirstChild().hasMoved());
            }
            assertEquals(new QNm("baaaz"), rtx.getName());
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) QNm(org.brackit.xquery.atomic.QNm) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) ResourceManager(org.sirix.api.ResourceManager)

Example 74 with XdmNodeReadTrx

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

the class VersioningTest method test.

/**
 * Test revisioning.
 *
 * @throws SirixException if anything in Sirix fails
 */
public void test() throws SirixException {
    try (final ResourceManager manager = mDatabase.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build())) {
        try (final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx()) {
            for (int i = 0; i < Constants.NDP_NODE_COUNT - 1; i++) {
                wtx.insertElementAsFirstChild(new QNm("foo"));
            }
            wtx.commit();
            assertTrue(wtx.getNodeKey() == Constants.NDP_NODE_COUNT - 1);
            fillNodePage(wtx);
            wtx.commit();
            assertTrue(wtx.getNodeKey() == (Constants.NDP_NODE_COUNT << 1) - 1);
            fillNodePage(wtx);
            wtx.commit();
            assertTrue(wtx.getNodeKey() == (Constants.NDP_NODE_COUNT * 3) - 1);
            fillNodePage(wtx);
            wtx.commit();
            assertTrue(wtx.getNodeKey() == (Constants.NDP_NODE_COUNT << 2) - 1);
            fillNodePage(wtx);
            wtx.commit();
            assertTrue(wtx.getNodeKey() == (Constants.NDP_NODE_COUNT * 5) - 1);
            try (final XdmNodeReadTrx rtx = manager.beginNodeReadTrx()) {
                for (int i = 0; i < Constants.NDP_NODE_COUNT - 1; i++) {
                    assertTrue(rtx.moveToFirstChild().hasMoved());
                }
                move(rtx);
                move(rtx);
                move(rtx);
                move(rtx);
            }
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) QNm(org.brackit.xquery.atomic.QNm) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) ResourceManager(org.sirix.api.ResourceManager)

Example 75 with XdmNodeReadTrx

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

the class TypeFilterTest method testFilterConvetions.

@Test
public void testFilterConvetions() throws Exception {
    final AbstractAxis axis = new XPathAxis(holder.getReader(), "a");
    final XdmNodeReadTrx xtx = ((XdmNodeReadTrx) axis.getTrx());
    xtx.moveTo(9L);
    FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:untyped"), true);
    FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:long"), false);
    xtx.moveTo(4L);
    FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:untyped"), true);
    FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:double"), false);
    xtx.moveTo(1L);
    xtx.moveToAttribute(0);
    FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:untyped"), true);
    FilterTest.testFilterConventions(new TypeFilter(xtx, "xs:anyType"), false);
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) TypeFilter(org.sirix.axis.filter.TypeFilter) FilterTest(org.sirix.axis.filter.FilterTest) Test(org.junit.Test)

Aggregations

XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)150 Test (org.junit.Test)93 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)48 QNm (org.brackit.xquery.atomic.QNm)20 DescendantAxis (org.sirix.axis.DescendantAxis)17 Iterator (java.util.Iterator)16 ResourceManager (org.sirix.api.ResourceManager)14 Axis (org.sirix.api.Axis)13 DBNode (org.sirix.xquery.node.DBNode)12 QueryException (org.brackit.xquery.QueryException)11 FilterAxis (org.sirix.axis.filter.FilterAxis)11 IndexController (org.sirix.access.IndexController)10 IndexDef (org.sirix.index.IndexDef)10 Item (org.brackit.xquery.xdm.Item)7 Database (org.sirix.api.Database)7 SirixException (org.sirix.exception.SirixException)6 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)5 SirixDeweyID (org.sirix.node.SirixDeweyID)5 Path (java.nio.file.Path)4 AbsAxisTest (org.sirix.axis.AbsAxisTest)4