Expand my Community achievements bar.

SOLVED

Best optimum query for creating reports in AEM?

Avatar

Level 4

Hi All,

I want to create a custom report something like OOTB component report of AEM. I was thinking of what logic I should implement to get all data related to the report. One simplest way would be to use NodeIterator and traverse through node and read related property, but i feel this would be really inefficient approach (performance issue may occur). Can you guys suggest any better approach to this problem? Should I use SQL query to get desired results or should I use Query Builder API, which would be more efficient approach? If possible please share what sample for this.

I have gone through the Adobe documentation (http://dev.day.com/docs/en/cq/current/developing/developing-reports.html#Creating%20Your%20Own%20Rep...)
 but it does not provide any inputs on how query should be written.

Thanks,

Shehjad

1 Accepted Solution

Avatar

Correct answer by
Level 10

I recommend using JCR API to query the AEM JCR.  However -- you can also use the QueryBuilder API. This API is a wrapper of the JCR API. Using either API  -- you can query for a result set and then process the result set and place the data in a report. 

There are plenty of community articles that talk about using the JCR API to query a JCR and show examples.

See:

http://docs.jboss.org/modeshape/2.5.0.Final/manuals/reference/html/jcr-query-and-search.html ( I really recommend this one)

http://dev.day.com/docs/en/crx/current/developing/searching_in_crx.html

http://cq-ops.tumblr.com/post/23544023402/how-to-query-cqs-jcr-with-sql-or-xpath

Here is an AEM community article that talks about 'How TO' query the AEM JCR using JCR SQL2 from within an OSGi bundle:

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

Likewise -- here is a community article that talks about 'How To' use the QueryBuilder API from within an OSGi bundle:

http://helpx.adobe.com/experience-manager/using/using-query-builder-api1.html

I personally like the JCR API; however, this is just my preference.  

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

I recommend using JCR API to query the AEM JCR.  However -- you can also use the QueryBuilder API. This API is a wrapper of the JCR API. Using either API  -- you can query for a result set and then process the result set and place the data in a report. 

There are plenty of community articles that talk about using the JCR API to query a JCR and show examples.

See:

http://docs.jboss.org/modeshape/2.5.0.Final/manuals/reference/html/jcr-query-and-search.html ( I really recommend this one)

http://dev.day.com/docs/en/crx/current/developing/searching_in_crx.html

http://cq-ops.tumblr.com/post/23544023402/how-to-query-cqs-jcr-with-sql-or-xpath

Here is an AEM community article that talks about 'How TO' query the AEM JCR using JCR SQL2 from within an OSGi bundle:

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

Likewise -- here is a community article that talks about 'How To' use the QueryBuilder API from within an OSGi bundle:

http://helpx.adobe.com/experience-manager/using/using-query-builder-api1.html

I personally like the JCR API; however, this is just my preference.  

Avatar

Former Community Member

Hi Smac,

"I recommend using JCR API to query the AEM JCR. The QueryBuilder API is a wrapper of the JCR API so using the JCR API is more efficient."

Is this the only point on which you are recommending using JCR API over QueryBuilder API? Or is there any other points like number of functionalities , performance improvement? How is the performance comparison when we use these different approaches?

Avatar

Level 10

That is just my preference - there are many developers whom like QueryBuilder over the JCR API. For example -- they like being able to write custom predicates that they use when using the QUeryBuilder API. By the way -- here is a good community article that talks about creating a custom predicate for use with the QueryBuilder API:

http://www.wemblog.com/2013/04/how-to-create-custom-query-predicate-in.html

Both ways will let you query the AEM JCR. I am going to talk to our performance team to see if they have executed performance tests using one over the other. 

Avatar

Level 4

 Thanks Smac and Maruthid, I would go through the documents links provided by you guys and try to understand which apporoach would be better for my use case :)