SQL2 query in crx/de returning different results from Java execution | Community
Skip to main content
October 5, 2022
Solved

SQL2 query in crx/de returning different results from Java execution

  • October 5, 2022
  • 1 reply
  • 917 views

I have a tree structure of /content/yyyy/mm/dd where article pages reside under the dd directory.

If I execute this query in crx/de:

you can see it returns 196 nodes/pages.  If I execute the query using this block of code:

QueryManager queryManager;
QueryResult articleCollection;

queryManager = session.getWorkspace().getQueryManager();

javax.jcr.query.Query query;
query = queryManager.createQuery(sqlStatement, javax.jcr.query.Query.JCR_SQL2);
articleCollection = query.execute();

return
articleCollection;

then -1 articles are returned.  However, if I move all the articles to a single day, say 2022/9/1 and specify '/content/2022/9/1' as the root then the Java query will return 196 results.

It appears the Java version of the query isn't actually descending and picking up child nodes.  Am I missing something?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by BobNoelle

Well I feel a little foolish, getSize() returns -1 but the collection is actually complete.  Thanks for your help 🙂

1 reply

joerghoh
Adobe Employee
Adobe Employee
October 6, 2022

There is not difference.

The JCR Query API is lazy; that means that the result set is only resolved when it's requested. In other words: It is not known upfront how many results you have until you have iterated through the complete result set, because the resolution is a complex operation, and doing all that work just to get the size is a massive overhead.

 

CRX DE does that for you (and it can be really slow because of that!), but not the raw JCR API. 

 

BobNoelleAuthorAccepted solution
October 6, 2022

Well I feel a little foolish, getSize() returns -1 but the collection is actually complete.  Thanks for your help 🙂