Search in sources :

Example 56 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class ColumnTest method testMultiColumn.

public void testMultiColumn() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.setProperty(propertyName1, TEST_VALUE);
    superuser.save();
    final String columnName1 = SELECTOR_1 + "." + propertyName1;
    final String columnName2 = SELECTOR_2 + "." + propertyName1;
    QueryObjectModel qom = qf.createQuery(qf.join(qf.selector(testNodeType, SELECTOR_1), qf.selector(testNodeType, SELECTOR_2), QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, qf.equiJoinCondition(SELECTOR_1, propertyName1, SELECTOR_2, propertyName1)), qf.descendantNode(SELECTOR_1, testRoot), null, new Column[] { qf.column(SELECTOR_1, propertyName1, columnName1), qf.column(SELECTOR_2, propertyName1, columnName2) });
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            RowIterator rows = query.execute().getRows();
            assertTrue("empty result", rows.hasNext());
            Row r = rows.nextRow();
            assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName1).getString());
            assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName2).getString());
            return null;
        }
    });
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException) Row(javax.jcr.query.Row)

Example 57 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class AbstractQOMTest method checkResult.

protected void checkResult(QueryResult result, String[] selectorNames, Node[][] nodes) throws RepositoryException {
    // collect rows
    Set<String> expectedPaths = new HashSet<String>();
    log.println("expected:");
    for (int i = 0; i < nodes.length; i++) {
        StringBuffer aggregatedPaths = new StringBuffer();
        for (int j = 0; j < nodes[i].length; j++) {
            aggregatedPaths.append(getPath(nodes[i][j]));
            aggregatedPaths.append("|");
        }
        expectedPaths.add(aggregatedPaths.toString());
        log.println(aggregatedPaths.toString());
    }
    Set<String> resultPaths = new HashSet<String>();
    log.println("result:");
    for (RowIterator it = result.getRows(); it.hasNext(); ) {
        Row r = it.nextRow();
        StringBuffer aggregatedPaths = new StringBuffer();
        for (int i = 0; i < selectorNames.length; i++) {
            aggregatedPaths.append(getPath(r.getNode(selectorNames[i])));
            aggregatedPaths.append("|");
        }
        resultPaths.add(aggregatedPaths.toString());
        log.println(aggregatedPaths.toString());
    }
    // check if all expected are in result
    for (Iterator<String> it = expectedPaths.iterator(); it.hasNext(); ) {
        String path = it.next();
        assertTrue(path + " is not part of the result set", resultPaths.contains(path));
    }
    // check result does not contain more than expected
    for (Iterator<String> it = resultPaths.iterator(); it.hasNext(); ) {
        String path = it.next();
        assertTrue(path + " is not expected to be part of the result set", expectedPaths.contains(path));
    }
}
Also used : RowIterator(javax.jcr.query.RowIterator) Row(javax.jcr.query.Row) HashSet(java.util.HashSet)

Example 58 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class AbstractQOMTest method checkResultOrder.

protected void checkResultOrder(QueryResult result, String[] selectorNames, Node[][] nodes) throws RepositoryException {
    // collect rows
    List<String> expectedPaths = new ArrayList<String>();
    log.println("expected:");
    for (int i = 0; i < nodes.length; i++) {
        StringBuffer aggregatedPaths = new StringBuffer();
        for (int j = 0; j < nodes[i].length; j++) {
            aggregatedPaths.append(getPath(nodes[i][j]));
            aggregatedPaths.append("|");
        }
        expectedPaths.add(aggregatedPaths.toString());
        log.println(aggregatedPaths.toString());
    }
    List<String> resultPaths = new ArrayList<String>();
    log.println("result:");
    for (RowIterator it = result.getRows(); it.hasNext(); ) {
        Row r = it.nextRow();
        StringBuffer aggregatedPaths = new StringBuffer();
        for (int i = 0; i < selectorNames.length; i++) {
            aggregatedPaths.append(getPath(r.getNode(selectorNames[i])));
            aggregatedPaths.append("|");
        }
        resultPaths.add(aggregatedPaths.toString());
        log.println(aggregatedPaths.toString());
    }
    assertEquals("wrong result order", expectedPaths, resultPaths);
}
Also used : RowIterator(javax.jcr.query.RowIterator) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row)

Example 59 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class FullTextSearchScoreTest method testConstraint.

public void testConstraint() throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.and(qf.fullTextSearch("s", null, qf.literal(vf.createValue("fox"))), qf.comparison(qf.fullTextSearchScore("s"), QueryObjectModelFactory.JCR_OPERATOR_GREATER_THAN, qf.literal(vf.createValue(Double.MIN_VALUE)))), qf.descendantNode("s", testRootNode.getPath())), new Ordering[] { qf.descending(qf.fullTextSearchScore("s")) }, null);
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            RowIterator rows = query.execute().getRows();
            while (rows.hasNext()) {
                double score = rows.nextRow().getScore("s");
                if (!Double.isNaN(score)) {
                    assertTrue("wrong full text search score", Double.MIN_VALUE < score);
                }
            }
            return null;
        }
    });
}
Also used : Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException)

Example 60 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class SQLQueryLevel2Test method testPathColumn.

/**
     * Test if the optional jcr:path pseudo property is contained in the query
     * result.
     * <p>
     * For configuration description see {@link #setUpFullTextTest()}.
     */
public void testPathColumn() throws Exception {
    setUpFullTextTest();
    QueryResult result = execute(getFullTextStatement());
    RowIterator rows = result.getRows();
    if (getSize(rows) < 1) {
        fail("Query result did not return any nodes");
    }
    // re-aquire rows
    rows = result.getRows();
    // test mere existence
    rows.nextRow().getValue(jcrPath);
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator)

Aggregations

RowIterator (javax.jcr.query.RowIterator)86 Node (javax.jcr.Node)48 QueryResult (javax.jcr.query.QueryResult)45 QueryManager (javax.jcr.query.QueryManager)27 Row (javax.jcr.query.Row)27 Query (javax.jcr.query.Query)25 Test (org.junit.Test)20 Session (javax.jcr.Session)17 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)15 RepositoryException (javax.jcr.RepositoryException)12 Value (javax.jcr.Value)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)8 ValueFactory (javax.jcr.ValueFactory)7 ArrayList (java.util.ArrayList)5 NodeIterator (javax.jcr.NodeIterator)5 NoSuchElementException (java.util.NoSuchElementException)4 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)4 RowIteratorAdapter (org.apache.jackrabbit.commons.iterator.RowIteratorAdapter)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3