Search in sources :

Example 26 with QueryResult

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

the class XPathJcrPathTest method testJcrPath.

/**
     * Verify that the jcr:path is present in the query result.
     */
public void testJcrPath() throws RepositoryException, NotExecutableException {
    String nodeTypeName = session.getRootNode().getPrimaryNodeType().getName();
    String queryStatement = "//element(*, " + nodeTypeName + ")";
    // execute the search query
    Query query = session.getWorkspace().getQueryManager().createQuery(queryStatement, qsXPATH);
    QueryResult result = query.execute();
    assertTrue("jcr:path must be present in query result row", Arrays.asList(result.getColumnNames()).contains(jcrPath));
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query)

Example 27 with QueryResult

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

the class XPathPosIndexTest method docOrderTest.

//-----------------------------< internal >---------------------------------
/**
     * Executes a statement, checks if the Result contains exactly one node with
     * <code>path</code>.
     *
     * @param stmt to be executed
     * @param path the path of the node in the query result.
     */
private void docOrderTest(Statement stmt, String path) throws RepositoryException, NotExecutableException {
    if (!isSupported(Repository.QUERY_XPATH_POS_INDEX)) {
        throw new NotExecutableException("Repository does not support document order on result set.");
    }
    int count = 0;
    // check precondition: at least 3 nodes
    for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); it.nextNode()) {
        count++;
    }
    if (count < 3) {
        throw new NotExecutableException("Workspace does not contain enough content under: " + testRoot + ". At least 3 nodes are required for this test.");
    }
    QueryResult result = execute(stmt);
    checkResult(result, 1);
    assertEquals("Wrong result node.", path, result.getNodes().nextNode().getPath());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 28 with QueryResult

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

the class XPathQueryLevel2Test method testPathColumn.

/**
     * Test if the jcr:path pseudo property is contained in 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)

Example 29 with QueryResult

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

the class LengthTest method executeQueries.

private QueryResult[] executeQueries(String propertyName, String operator, Value length) throws RepositoryException {
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.childNode("s", testRoot), qf.comparison(qf.length(qf.propertyValue("s", propertyName)), operator, qf.literal(length))), null, null);
    QueryResult[] results = new QueryResult[2];
    results[0] = qom.execute();
    results[1] = qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute();
    return results;
}
Also used : QueryResult(javax.jcr.query.QueryResult) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel)

Example 30 with QueryResult

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

the class AndConstraintTest method testAnd.

public void testAnd() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1, testNodeType);
    n1.setProperty(propertyName1, "foo");
    n1.setProperty(propertyName2, "bar");
    Node n2 = testRootNode.addNode(nodeName2, testNodeType);
    n2.setProperty(propertyName2, "bar");
    superuser.save();
    QueryResult result = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.descendantNode("s", testRootNode.getPath()), qf.and(qf.propertyExistence("s", propertyName1), qf.propertyExistence("s", propertyName2))), null, null).execute();
    checkResult(result, new Node[] { n1 });
    String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISDESCENDANTNODE(s, [" + testRootNode.getPath() + "]) " + "AND s.[" + propertyName1 + "] IS NOT NULL " + "AND s.[" + propertyName2 + "] IS NOT NULL";
    result = qm.createQuery(stmt, Query.JCR_SQL2).execute();
    checkResult(result, new Node[] { n1 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node)

Aggregations

QueryResult (javax.jcr.query.QueryResult)200 Node (javax.jcr.Node)108 Query (javax.jcr.query.Query)97 QueryManager (javax.jcr.query.QueryManager)54 NodeIterator (javax.jcr.NodeIterator)52 RowIterator (javax.jcr.query.RowIterator)46 Session (javax.jcr.Session)35 Test (org.junit.Test)32 Row (javax.jcr.query.Row)21 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)21 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 RepositoryException (javax.jcr.RepositoryException)14 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 Value (javax.jcr.Value)8 NoSuchElementException (java.util.NoSuchElementException)7 ArrayList (java.util.ArrayList)6 ValueFactory (javax.jcr.ValueFactory)6 InvalidItemStateException (javax.jcr.InvalidItemStateException)5 JackrabbitQueryResult (org.apache.jackrabbit.api.query.JackrabbitQueryResult)5 TreeSet (java.util.TreeSet)4