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 precache specified properties:

Property Name



The index of the first element of a query result set that should actually be returned. By setting startingIndex and endingIndex, you can limit the size of the query’s result set.


The items beginning with the endingIndex element of the query result set are not returned. In other words, the total number of items returned is endingIndex - startIndex. A value of -1 indicates that there is no limit to the number of items returned.


Specifies the sort order of a query’s result set.


A list of properties that should be precached for each item in a query’s result set at the time the query is run.

The following example contains the following steps:

// 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(
RepositoryView view = repository.getView("user");
Query query = view.getQueryBuilder().createUnconstrainedQuery();
String [] precachedPropertyNames = {"login", "password"};
SortDirectives sortDirectives = new SortDirectives();
sortDirectives.addDirective(new SortDirective(
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"));