You can create a repository filter with the <rql-filter>
tag in the definition file for an item descriptor. The <rql-filter>
tag encloses an RQL statement, as in the following example:
<item-descriptor name="article"> <rql-filter> <rql>name starts with "n"</rql> </rql-filter> <table name="article" id-column-names="article_id"> <property name="name"/> <property name="date"/> </table> </item-descriptor>
This setting causes queries and item lookups for this item descriptor to return only items whose name
property starts with n
. The SQL repository issues SQL in the form of an extra WHERE clause condition to implement filtering so any given query or item lookup should be no slower with a reasonable filter tacked on.
You can also use RQL substitution parameters in your filter query. For example:
<item-descriptor name="article"> <rql-filter> <rql>name starts with ?0 or availabilityDate < ?1</rql> <param value="n"></param> <param bean="/myApp.IssueDate"></param> </rql-filter> <table name="article" id-column-names="article_id"> <property name="name"/> <property name="availabilityDate" data-type="timestamp"/> </table> </item-descriptor>
In this example, the RQL parameters are substituted into the query:
The first parameter is a simple constant value. Typically it is not necessarily to substitute constant values as they can be inlined in the RQL query string.
The second parameter is a Nucleus component. If an object of type
atg.service.util.CurrentDate
is used as a parameter (as in this example), the filtering logic callsgetTimeAsTimeStamp()
on that object and uses that as the value of the parameter. This lets you have aCurrentDate
service used in a filter. Also note, as in this example, that the “less than” symbol (<
) is a markup character and must be escaped in your XML file as<
.
For information about RQL, see the Repository Query Language section in the Repository Queries chapter.