You can use the atg.repository.QueryOptions class to specify ways that a query may be modified. You can set the QueryOptions properties, and then 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

startingIndex

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.

endingIndex

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.

sortDirectives

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

precachedPropertyNames

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.

In the following example, we:

  // 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"));
 
loading table of contents...