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