Search in sources :

Example 51 with QueryResult

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

the class SelectClauseTest method testSameNameSiblingSQL.

public void testSameNameSiblingSQL() throws RepositoryException {
    Node n = testRootNode.addNode("node");
    n.setProperty("myvalue", "foo");
    n = testRootNode.addNode("node");
    n.setProperty("myvalue", "bar");
    n = testRootNode.addNode("node");
    n.setProperty("yourvalue", "foo");
    testRootNode.save();
    String sql = "SELECT myvalue FROM " + ntBase + " WHERE " + "jcr:path LIKE '" + testRoot + "/node[%]' AND myvalue IS NOT NULL";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 2, 2);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 52 with QueryResult

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

the class SQL2OrderByTest method testOrderByVal.

public void testOrderByVal() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("value", 3);
    n2.setProperty("value", 1);
    n3.setProperty("value", 2);
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY [value]");
    checkSeq(qr, new Node[] { n2, n3, n1 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node)

Example 53 with QueryResult

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

the class SQL2OrderByTest method testOrderByValMultMix.

public void testOrderByValMultMix() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("value", 2);
    n1.setProperty("text", "b");
    n2.setProperty("value", 1);
    n2.setProperty("text", "x");
    n3.setProperty("value", 2);
    n3.setProperty("text", "a");
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY [value], [text] desc");
    checkSeq(qr, new Node[] { n2, n1, n3 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node)

Example 54 with QueryResult

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

the class SQL2OrderByTest method testOrderByValMultDesc.

public void testOrderByValMultDesc() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("value", 2);
    n1.setProperty("text", "b");
    n2.setProperty("value", 1);
    n2.setProperty("text", "x");
    n3.setProperty("value", 2);
    n3.setProperty("text", "a");
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY [value] desc, [text] desc");
    checkSeq(qr, new Node[] { n1, n3, n2 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node)

Example 55 with QueryResult

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

the class SQL2OrderByTest method testOrderByScore.

public void testOrderByScore() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("text", "aaa");
    n1.setProperty("value", 3);
    testRootNode.getSession().save();
    n2.setProperty("text", "bbb");
    n2.setProperty("value", 2);
    testRootNode.getSession().save();
    n3.setProperty("text", "ccc");
    n3.setProperty("value", 2);
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY SCORE()");
    RowIterator rows = qr.getRows();
    long size = rows.getSize();
    assertTrue(size == 3 || size == -1);
    size = 0;
    double score = Double.MIN_VALUE;
    while (rows.hasNext()) {
        double nextScore = rows.nextRow().getScore();
        assertTrue(nextScore >= score);
        score = nextScore;
        size++;
    }
    assertEquals(3, size);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator)

Aggregations

QueryResult (javax.jcr.query.QueryResult)202 Node (javax.jcr.Node)109 Query (javax.jcr.query.Query)98 QueryManager (javax.jcr.query.QueryManager)55 NodeIterator (javax.jcr.NodeIterator)52 RowIterator (javax.jcr.query.RowIterator)46 Session (javax.jcr.Session)36 Test (org.junit.Test)32 Row (javax.jcr.query.Row)21 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)21 RepositoryException (javax.jcr.RepositoryException)15 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 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