jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simone Tripodi (JIRA)" <j...@apache.org>
Subject [jira] [Created] (JCR-3487) Provide a utility to run JCR queries adopting a fluent-interfaces approach
Date Mon, 17 Dec 2012 20:08:13 GMT
Simone Tripodi created JCR-3487:

             Summary: Provide a utility to run JCR queries adopting a fluent-interfaces approach
                 Key: JCR-3487
                 URL: https://issues.apache.org/jira/browse/JCR-3487
             Project: Jackrabbit Content Repository
          Issue Type: Improvement
          Components: jackrabbit-jcr-commons
            Reporter: Simone Tripodi
            Priority: Minor

(moving the discussion from OAK-529)

I propose an approach that, without altering the current codebase, but rather adding a new
package on top of existing APIs, tries to simplify the query building and execution, i.e.
rather than coding the following:

QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery("select text from [nt:base] where id = $id", Query.JCR_SQL2);
q.bindValue("id", vf.createValue("1"));
QueryResult r = q.execute();

String text = null;

RowIterator it = r.getRows();
if (it.hasNext()) {
    Row row = it.nextRow();
    text = row.getValue("text").getString();

users could write the same sentence using a shortcut like

String text = on(qm)
              .sql2Query("select text from [nt:base] where id = $id")

where {{textHandler}} is:

QueryResultHandler<String> textHandler = new QueryResultHandler<String> {

    public String handle(QueryResult queryResult)
            throws RepositoryException {

        RowIterator it = queryResult.getRows();
        if (it.hasNext()) {
            Row row = it.nextRow();
            return row.getValue("text").getString();

        return null;


the {{QueryResultHandler}} should simplify reducing redundant query handling code, improving

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

View raw message