Search in sources :

Example 56 with QueryResult

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

the class SimpleQueryTest method testNotEqual.

public void testNotEqual() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("value", new String[] { "foo" });
    n = testRootNode.addNode("node2");
    n.setProperty("value", new String[] { "bar" });
    n = testRootNode.addNode("node3");
    n.setProperty("value", new String[] { "foobar" });
    testRootNode.save();
    String jcrql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value <> 'bar'";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, 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 57 with QueryResult

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

the class SimpleQueryTest method testIsNull.

public void testIsNull() throws Exception {
    Node foo = testRootNode.addNode("foo");
    foo.setProperty("mytext", "the quick brown fox jumps over the lazy dog.");
    Node bar = testRootNode.addNode("bar");
    bar.setProperty("text", "the quick brown fox jumps over the lazy dog.");
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured WHERE mytext is null and jcr:path LIKE '" + testRoot + "/%'";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 1);
    String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured' and fn:not(@mytext)]";
    q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
    result = q.execute();
    checkResult(result, 1);
    xpath = "/jcr:root" + testRoot + "/*[@jcr:primaryType='nt:unstructured' and fn:not(@mytext)]";
    q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
    result = q.execute();
    checkResult(result, 1);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 58 with QueryResult

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

the class SimpleQueryTest method testLikePatternBetween.

public void testLikePatternBetween() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("value", new String[] { "ping" });
    n = testRootNode.addNode("node2");
    n.setProperty("value", new String[] { "pong" });
    n = testRootNode.addNode("node3");
    n.setProperty("value", new String[] { "puung" });
    testRootNode.save();
    String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'ping'";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 1);
    sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'p_ng'";
    q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    result = q.execute();
    checkResult(result, 2);
    sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'p%ng'";
    q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    result = q.execute();
    checkResult(result, 3);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 59 with QueryResult

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

the class SimpleQueryTest method testLikePattern.

public void testLikePattern() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("value", new String[] { "king" });
    n = testRootNode.addNode("node2");
    n.setProperty("value", new String[] { "ping" });
    n = testRootNode.addNode("node3");
    n.setProperty("value", new String[] { "ching" });
    testRootNode.save();
    String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'ping'";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 1);
    sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE '_ing'";
    q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    result = q.execute();
    checkResult(result, 2);
    sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE '%ing'";
    q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    result = q.execute();
    checkResult(result, 3);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 60 with QueryResult

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

the class SimpleQueryTest method testIsNotNull.

public void testIsNotNull() throws Exception {
    Node foo = testRootNode.addNode("foo");
    foo.setProperty("mytext", "the quick brown fox jumps over the lazy dog.");
    Node bar = testRootNode.addNode("bar");
    bar.setProperty("text", "the quick brown fox jumps over the lazy dog.");
    // documents which field name is not exactly "mytext" should not match (JCR-1051)
    bar.setProperty("mytextwhichstartswithmytext", "the quick brown fox jumps over the lazy dog.");
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured WHERE mytext is not null";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 1);
    String xpath = "//*[@jcr:primaryType='nt:unstructured' and @mytext]";
    q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
    result = q.execute();
    checkResult(result, 1);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

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