You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Simone Tripodi (JIRA)" <ji...@apache.org> on 2012/12/16 00:58:12 UTC
[jira] [Updated] (OAK-529) Provide a utility to run JCR queries
adopting a fluent-interfaces approach
[ https://issues.apache.org/jira/browse/OAK-529?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Simone Tripodi updated OAK-529:
-------------------------------
Attachment: OAK-529.patch
The proposed patch provides an implementation for the proposed addition.
Feedbacks, suggestions, ... are welcome :)
TIA!
> Provide a utility to run JCR queries adopting a fluent-interfaces approach
> --------------------------------------------------------------------------
>
> Key: OAK-529
> URL: https://issues.apache.org/jira/browse/OAK-529
> Project: Jackrabbit Oak
> Issue Type: New Feature
> Components: jcr
> Affects Versions: 0.5
> Reporter: Simone Tripodi
> Priority: Minor
> Fix For: 0.6
>
> Attachments: OAK-529.patch
>
>
> I propose an approach that, without altering the current codebase, but rather adding a new layer 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