You can use the atg.repository.QueryOptions
class to specify ways that a query can be modified. You can set the QueryOptions
properties, and pass the QueryOptions
bean to the following executeQuery
method:
RepositoryItem[] executeQuery(Query pQuery, QueryOptions pQueryOptions);
The QueryOptions
properties let you limit the size of the result set, direct how the result set should be sorted, and pre-cache specified properties:
Property Name | Description |
---|---|
| The index of the first element of a query result set that should actually be returned. By setting |
| The items beginning with the |
| Specifies the sort order of a query’s result set. |
| A list of properties that should be pre-cached for each item in a query’s result set at the time the query is run. Use |
The following example contains the following steps:
Creates an unconstrained query against the Profile Repository.
Creates a
SortDirectives
that contains aSortDirective
, sorting the result set in ascending order by the login property. ASortDirective
can be ascending or descending and case-sensitive or case-insensitive (although not all data stores support case-insensitive sorting).Creates a
QueryOptions
with astartingIndex
of 0 and anendingIndex
of 5. This limits the number of profiles returned to at most 5. TheQueryOptions
incorporates theSortDirectives
.Executes the query with the
QueryOptions
.Outputs the results, displaying the
login
property.
// Creates an unconstrained query against the profile repository. // It returns at most the first 5 profiles. // Hints are used to precache login and password properties. // Results are sorted by the login property. Repository repository = (Repository)request.resolveName( "/atg/userprofiling/ProfileAdapterRepository"); RepositoryView view = repository.getView("user"); Query query = view.getQueryBuilder().createUnconstrainedQuery(); String [] precachedPropertyNames = {"login", "password"}; SortDirectives sortDirectives = new SortDirectives(); sortDirectives.addDirective(new SortDirective( "login",SortDirective.DIR_ASCENDING)); RepositoryItem [] items = view.executeQuery( query, new QueryOptions(0, 5, sortDirectives, precachedPropertyNames)); for (int i = 0; i < items.length; i++) out.print("<li>" + items[i].getPropertyValue("login"));