Recently I had to write an ATG Repository Query (RQL) to load collection using “IN” query. I found the ATG API documents are not good enough to tell the story clearly. Below given example load all employees with give ids. The important API to understand is QueryBuilder.createIncludesQuery(QueryExpression valueExpression, QueryExpression propertyExpression); You would have noticed that the values needs to be passed in as the first argument.
ATG RQL includes query example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
package com.ourownjava.atg.repository; import atg.nucleus.GenericService; import atg.repository.Query; import atg.repository.QueryBuilder; import atg.repository.QueryExpression; import atg.repository.Repository; import atg.repository.RepositoryException; import atg.repository.RepositoryItem; import atg.repository.RepositoryView; /** * * @author ourownjava.com * */ public class EmployeeTools extends GenericService { private Repository repository; public void setRepository(Repository repository) { this.repository = repository; } public RepositoryItem[] findByIds(String[] ids) throws RepositoryException { final RepositoryView employeeView = repository.getView("EMPLOYEE"); final QueryBuilder queryBuilder = employeeView.getQueryBuilder(); final QueryExpression propertyExpression = queryBuilder.createPropertyQueryExpression("EMPLOYEE_ID"); final QueryExpression valueExpression = queryBuilder.createConstantQueryExpression(ids); final Query employeeQuery = queryBuilder.createIncludesQuery(valueExpression, propertyExpression); final RepositoryItem[] repositoryItems = employeeView.executeQuery(employeeQuery); return repositoryItems; } } |
Pingback: How to write ATG includes query (RQL)? | Clean Java
Good one.
Thanks Vico.