You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Simone Tripodi (JIRA)" <ji...@apache.org> on 2012/12/17 21:08:13 UTC
[jira] [Created] (JCR-3487) Provide a utility to run JCR queries
adopting a fluent-interfaces approach
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:
{code}
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();
}
{code}
users could write the same sentence using a shortcut like
{code}
String text = on(qm)
.sql2Query("select text from [nt:base] where id = $id")
.where("id").is("1")
.execute(textHandler);
{code}
where {{textHandler}} is:
{code}
QueryResultHandler<String> textHandler = new QueryResultHandler<String> {
@Override
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;
}
}
{code}
the {{QueryResultHandler}} should simplify reducing redundant query handling code, improving reusability.
--
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