April 7, 2020
Estimated Post Reading Time ~

JCR Java Query Object Model (JQOM) – Adobe AEM Query




JQOM (Java Query Object Model) is the new Query language that has been support by AEM from its latest version 6.x for its latest repository Jackrabbit Oak. This post aims at introducing to the JQOM APIs with an example. JQOM is like a ‘prepared statements’ and SQL2 is like ‘statements’ in our JDBC queries.

Usecase:
Let us take an usecase to Get all the nodes from ‘Geometrixx’ which has the property ‘pageTitle’ and see how to write 

QueryObjectModelFactory qf = currentNode.getSession().getWorkspace().getQueryManager().getQOMFactory();
Selector selector = qf.selector("cq:PageContent", "s");
Constraint constriant = qf.descendantNode("s", "/content/geometrixx");
constriant = qf.and(constriant, qf.propertyExistence("s", "pageTitle"));
QueryObjectModel qm = qf.createQuery(selector, constriant, null, null);

QueryObjectModelFactory get the instance of the JCR Object Model.

Selector is used to set the type of node that the query needs to look at

Constraint is used to add all the constraints which is like where condition into the query model

Finally we need to create a query with these selector and constraint and capture the response as a QueryObjectModel

Servlet has been created for the same which can be downloaded from github. Once you install the project hit the servlet url (localhost:4502/services/query) to see the output



Play around in changing the query model and check the output.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.