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();
}
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();
}
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());
}
}
}
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);
}
}
}
}
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);
}
Aggregations