Search in sources :

Example 11 with QueryResult

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

the class LimitAndOffsetTest method testLimit.

public void testLimit() throws Exception {
    query.setLimit(1);
    QueryResult result = query.execute();
    checkResult(result, new Node[] { node1 });
    query.setLimit(2);
    result = query.execute();
    checkResult(result, new Node[] { node1, node2 });
    query.setLimit(3);
    result = query.execute();
    checkResult(result, new Node[] { node1, node2, node3 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

Example 12 with QueryResult

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

the class AbstractQueryTest method executeSQLQuery.

/**
     * Executes the <code>sql</code> query and checks the results against
     * the specified <code>nodes</code>.
     * @param sql the sql query.
     * @param nodes the expected result nodes.
     * @throws RepositoryException if an error occurs while executing the query
     *                             or checking the result.
     */
protected void executeSQLQuery(String sql, Node[] nodes) throws RepositoryException {
    QueryResult res = qm.createQuery(sql, Query.SQL).execute();
    checkResult(res, nodes);
}
Also used : QueryResult(javax.jcr.query.QueryResult)

Example 13 with QueryResult

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

the class FulltextQueryTest method testFulltextOrSQL.

public void testFulltextOrSQL() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("title", new String[] { "test text" });
    n.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    n = testRootNode.addNode("node2");
    n.setProperty("title", new String[] { "other text" });
    n.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured" + " WHERE \"jcr:path\" LIKE '" + testRoot + "/%" + "' AND CONTAINS(., '''fox jumps'' test OR other')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 2);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 14 with QueryResult

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

the class FulltextQueryTest method testFulltextPhraseSQL.

public void testFulltextPhraseSQL() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("title", new String[] { "test text" });
    n.setProperty("mytext", new String[] { "the quick brown jumps fox over the lazy dog." });
    n = testRootNode.addNode("node2");
    n.setProperty("title", new String[] { "other text" });
    n.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured" + " WHERE \"jcr:path\" LIKE '" + testRoot + "/%" + "' AND CONTAINS(., 'text \"fox jumps\"')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 1);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 15 with QueryResult

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

the class FulltextQueryTest method testFulltextIntercapSQL.

public void testFulltextIntercapSQL() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("title", new String[] { "tEst text" });
    n.setProperty("mytext", new String[] { "The quick brown Fox jumps over the lazy dog." });
    n = testRootNode.addNode("node2");
    n.setProperty("title", new String[] { "Other text" });
    n.setProperty("mytext", new String[] { "the quick brown FOX jumPs over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured" + " WHERE \"jcr:path\" LIKE '" + testRoot + "/%" + "' AND CONTAINS(., '''fox juMps'' Test OR otheR')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 2);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) 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