Repository Query Language
RQL
generic language for formulating queries that map to any repository implementation, such as SQL or LDAP.
Multi-Valued Property Queries
interests INCLUDES "biking
interests INCLUDES ANY { "biking", "swimming" } interests INCLUDES ALL { "biking", "swimming" }
addresses INCLUDES ITEM (zip = "48322" AND state = "MI")
RQL RANGE
age > 30 RANGE +10
age > 30 RANGE 10+ age > 30 RANGE 40+10
[Link]
defines the available query operations
build Query objects
ComparisonQuery
RepositoryView userView = getRepository().getItemDescriptor(USER).getRepositoryView();
QueryBuilder userBuilder = [Link](); QueryExpression userType = [Link](USER_TYPE); QueryExpression two = [Link](USER_TYPE_2); Query userTypeIsTwo = [Link](userType, two, [Link]); RepositoryItem[] answer = [Link](userTypeIsTwo);
PatternMatchQuery
RepositoryView employeeView = getRepository().getView(USER);
QueryBuilder queryBuilder = [Link]();
QueryExpression propertyExpression = [Link](login);
QueryExpression valueExpression = [Link](name); Query accountQuery = [Link](propertyExpression, valueExpression, [Link]); RepositoryItem[] repositoryItems = [Link](accountQuery);
IncludesQuery
RepositoryView employeeView = getRepository().getView(USER);
QueryBuilder queryBuilder = [Link](); QueryExpression propertyExpression = [Link]("user_id"); QueryExpression valueExpression = [Link](ids); Query employeeQuery = [Link](valueExpression, propertyExpression); RepositoryItem[] repositoryItems = [Link](employeeQuery);
Complex Query
RepositoryView userView = getRepository().getItemDescriptor(USER).getRepositoryView(); QueryBuilder userBuilder = [Link](); QueryExpression userType = [Link]("userType"); QueryExpression two = [Link](2); Query userTypeLTTwo = [Link](userType, two, QueryBuilder.LESS_THAN); QueryExpression login = [Link]("login"); QueryExpression j = [Link]("j"); Query startsWithJ = [Link](login, j, QueryBuilder.STARTS_WITH); Query[] pieces = { userTypeLTTwo, startsWithJ }; Query andQuery = [Link](pieces); RepositoryItem[] answer = [Link](andQuery);
[Link]
let you limit the size of the result set, direct how the result set should be sorted,
precache specified properties
QueryOptions
RepositoryView view = getRepository().getView(USER);
Query query = [Link]().createUnconstrainedQuery(); String[] precachedPropertyNames = { "login", "password" };
SortDirectives sortDirectives = new SortDirectives();
[Link](new SortDirective( "login", SortDirective.DIR_ASCENDING));
RepositoryItem[] items = [Link](query, new QueryOptions(0, 5, sortDirectives, precachedPropertyNames));
[Link]
RepositoryView view = getRepository().getView(USER);
RqlStatement statement = [Link]("lastName STARTS WITH ?0"); Object params[] = { new String("m") }; RepositoryItem items[] = [Link](view, params);
Operation tags
<add-item>
<update-item>
<remove-item> <export-items> <import-items> <print-item> <transaction>
to add or update or remove items
to export and import items to print item to maintain transactions while adding or removing items.
Generate DDL
<print-ddl/>
startSQLRepository bin\startSQLRepository -m <module-name> repository /atg/commerce/catalog/ProductCatalog -outputSQLFile product_catalog.sql
To check what items are in cache
<dump-caches item-descriptors="skuSpecialPriceRules" dumptype="both"/>
Querying using date or timestamp by using RQL
date
<query-items item-descriptor="order"> creationDate> date("2011-10-10") and state="SUBMITTED" </query-items>
<query-items item-descriptor="order"> creationDate> date("2011-10-10 10:00:00 EST") and state="SUBMITTED" </query-items>
Timestamp
How to get sysdate in RQL named query?
Repository filtering
Use the <rql-filter> tag in the definition file for an item descriptor.
Set the filterQuery property of the item descriptor to a Query object. Set the rqlFilterString property of the item descriptor to an RQL string, which is compiled into the Query object that defines the filter.
<rql-filter>
<item-descriptor name="article">
<rql-filter> <rql>name starts with ?0 or availabilityDate < ?1</rql> <param value="n"></param> <param bean="/[Link]"></param> </rql-filter> <table name="article" id-column-names="article_id"> <property name="name" /> <property name="date" /> </table> </item-descriptor>