Search in sources :

Example 61 with QueryResult

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

the class SimpleQueryTest method testLikePatternEnd.

public void testLikePatternEnd() throws Exception {
    Node n = testRootNode.addNode("node1");
    n.setProperty("value", new String[] { "bli" });
    n = testRootNode.addNode("node2");
    n.setProperty("value", new String[] { "bla" });
    n = testRootNode.addNode("node3");
    n.setProperty("value", new String[] { "blub" });
    testRootNode.save();
    String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'bli'";
    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 'bl_'";
    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 'bl%'";
    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 62 with QueryResult

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

the class ParentNodeTest method testParentInAttribute4.

public void testParentInAttribute4() throws RepositoryException {
    String stmt = testPath + "//child[../@foo1 = 'bar1']";
    QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
    assertTrue("Wrong size of NodeIterator in result", result.getNodes().getSize() > 0);
    assertEquals("child", result.getNodes().nextNode().getName());
}
Also used : QueryResult(javax.jcr.query.QueryResult)

Example 63 with QueryResult

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

the class SearchResourceImpl method search.

/**
     * Execute the query defined by the given <code>sInfo</code>.
     *
     * @see SearchResource#search(org.apache.jackrabbit.webdav.search.SearchInfo)
     */
public MultiStatus search(SearchInfo sInfo) throws DavException {
    try {
        QueryResult result = getQuery(sInfo).execute();
        MultiStatus ms = new MultiStatus();
        if (ItemResourceConstants.NAMESPACE.equals(sInfo.getLanguageNameSpace())) {
            ms.setResponseDescription("Columns: " + encode(result.getColumnNames()) + "\nSelectors: " + encode(result.getSelectorNames()));
        } else {
            ms.setResponseDescription(encode(result.getColumnNames()));
        }
        queryResultToMultiStatus(result, ms);
        return ms;
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) QueryResult(javax.jcr.query.QueryResult) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException)

Example 64 with QueryResult

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

the class AbstractQuery method execute.

/**
     * {@inheritDoc}
     */
public final boolean execute(Context ctx) throws Exception {
    String statement = (String) ctx.get(this.statementKey);
    Session session = CommandHelper.getSession(ctx);
    Query query = session.getWorkspace().getQueryManager().createQuery(statement, this.getLanguage());
    QueryResult result = query.execute();
    ctx.put(destKey, result.getNodes());
    return false;
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Session(javax.jcr.Session)

Example 65 with QueryResult

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

the class FulltextSQL2QueryTest method testFulltextSimpleSQL.

public void testFulltextSimpleSQL() throws Exception {
    Node foo = testRootNode.addNode("foo");
    foo.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
    testRootNode.save();
    String sql = "SELECT * FROM [nt:unstructured]" + " WHERE ISCHILDNODE([" + testRoot + "])" + " AND CONTAINS(mytext, 'fox')";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
    QueryResult 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