Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

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

Avatar

Level 2

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:

BobNoelle_0-1664994414262.png

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?

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

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

View solution in original post

2 Replies

Avatar

Employee Advisor

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. 

 

Avatar

Correct answer by
Level 2

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