Search in sources :

Example 1 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class AbstractComparator method hasNext.

@Override
public final boolean hasNext() {
    resetToLastKey();
    if (mIsFirst) {
        mIsFirst = false;
        // TODO: why?
        if (!(mOperand1 instanceof LiteralExpr)) {
            mOperand1.reset(getTrx().getNodeKey());
        }
        // TODO: why?
        if (!(mOperand2 instanceof LiteralExpr)) {
            mOperand2.reset(getTrx().getNodeKey());
        }
        /*
       * Evaluates the comparison. First atomizes both operands and then executes the comparison on
       * them. At the end, the transaction is set to the retrieved result item.
       */
        if (mOperand1.hasNext()) {
            mKey = mOperand1.next();
            try {
                // atomize operands
                final AtomicValue[] operandOne = atomize(mOperand1);
                if (mOperand2.hasNext()) {
                    mKey = mOperand2.next();
                    final AtomicValue[] operandTwo = atomize(mOperand2);
                    hook(operandOne, operandTwo);
                    try {
                        // get comparison result
                        final boolean resultValue = compare(operandOne, operandTwo);
                        final AtomicValue result = new AtomicValue(resultValue);
                        // add retrieved AtomicValue to item list
                        final int itemKey = getTrx().getItemList().addItem(result);
                        mKey = itemKey;
                    } catch (SirixXPathException e) {
                        throw new RuntimeException(e);
                    }
                    return true;
                }
            } catch (final SirixXPathException exc) {
                throw new RuntimeException(exc);
            }
        }
    }
    // return empty sequence or function called more than once
    resetToStartKey();
    return false;
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) LiteralExpr(org.sirix.service.xml.xpath.expr.LiteralExpr) AtomicValue(org.sirix.service.xml.xpath.AtomicValue)

Example 2 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class ConXPathAxisTest method testCount.

@Test
public void testCount() throws IOException {
    try {
        holder.getReader().moveTo(1L);
        XPathStringChecker.testIAxisConventions(new XPathAxis(holder.getReader(), "fn:count(//node())"), new String[] { "10" });
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 3 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class ConXPathAxisTest method testNodeTests.

@Test
public void testNodeTests() {
    try {
        // Find descendants starting from nodeKey 0L (root).
        holder.getReader().moveToDocumentRoot();
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "/p:a/node()"), new long[] { 4L, 5L, 8L, 9L, 13L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "p:a/text()"), new long[] { 4L, 8L, 13L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "/p:a/b/text()"), new long[] { 6L, 12L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "p:a/b/node()"), new long[] { 6L, 7L, 11L, 12L });
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 4 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class ConXPathAxisTest method testAncestor.

@Test
public void testAncestor() {
    try {
        // Find ancestor starting from nodeKey 8L.
        holder.getReader().moveTo(11L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "ancestor::p:a"), new long[] { 1L });
        holder.getReader().moveTo(13L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "ancestor::p:a"), new long[] { 1L });
        holder.getReader().moveTo(11L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "ancestor::node()"), new long[] { 9L, 1L });
        holder.getReader().moveTo(11L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "ancestor-or-self::node()"), new long[] { 11L, 9L, 1L });
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Example 5 with SirixXPathException

use of org.sirix.exception.SirixXPathException in project sirix by sirixdb.

the class ConXPathAxisTest method testMultiExpr.

@Test
public void testMultiExpr() {
    try {
        holder.getReader().moveTo(1L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b, b, b"), new long[] { 5L, 9L, 5L, 9L, 5L, 9L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b/c, ., //c"), new long[] { 7L, 11L, 1L, 7L, 11L });
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "b/text(), //text(), descendant-or-self::element()"), new long[] { 6L, 12L, 4L, 8L, 13L, 6L, 12L, 1L, 5L, 7L, 9L, 11L });
        holder.getReader().moveTo(5L);
        AbsAxisTest.testIAxisConventions(new XPathAxis(holder.getReader(), "/p:a/b/c, ., .., .//text()"), new long[] { 7L, 11L, 5L, 1L, 6L });
    } catch (final SirixXPathException mExp) {
        mExp.getStackTrace();
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) XPathAxis(org.sirix.service.xml.xpath.XPathAxis) Test(org.junit.Test) AbsAxisTest(org.sirix.axis.AbsAxisTest)

Aggregations

SirixXPathException (org.sirix.exception.SirixXPathException)16 Test (org.junit.Test)14 AbsAxisTest (org.sirix.axis.AbsAxisTest)12 XPathAxis (org.sirix.service.xml.xpath.XPathAxis)12 AtomicValue (org.sirix.service.xml.xpath.AtomicValue)3 LiteralExpr (org.sirix.service.xml.xpath.expr.LiteralExpr)2 Axis (org.sirix.api.Axis)1 DescendantAxis (org.sirix.axis.DescendantAxis)1 AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)1 SequenceAxis (org.sirix.service.xml.xpath.expr.SequenceAxis)1