Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
(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("id").is("1") .execute(textHandler);
where textHandler is:
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; } }
the QueryResultHandler should simplify reducing redundant query handling code, improving reusability.