Any repository that extends atg.repository.RepositoryViewImpl can have access to the base NamedQuery feature. Here is a code sample that indicates how you might create and use a named query with the Query and NamedQuery APIs.

import atg.repository.*;
public void sampleQueryTest() {
  // Get a hold of your repository somehow
  Repository rep = getRepository();
  RepositoryItemDescriptor desc = rep.getItemDescriptor("user");
  RepositoryView view = desc.getRepositoryView();
  QueryBuilder builder = view.getQueryBuilder();

  try {
    // Create your query
    QueryExpression prop = builder.createPropertyQueryExpression("firstName");
    QueryExpression constant = builder.createConstantQueryExpression("Adam");
    Query query = builder.createComparisonQuery(prop, constant,

    //See if we have a NamedQueryView to work with...
    if(view instanceof NamedQueryView) {
      NamedQueryView nameView = (NamedQueryView)view;
      String queryName = "firstNameQuery";
      // Create our named query
      nameView.createNamedQuery(queryName, query);
      // And execute it (normally you wouldn't do this all in the same method
      // since the purpose is really to have access to the Query for later)
      Query namedQuery = nameView.getNamedQuery(queryName);
      RepositoryItem[] results = nameView.executeQuery(namedQuery);
  catch(RepositoryException exc) {

Note that named queries can also be parameterized. For an example of using parameterized queries in Java code, see Parameterized Query Example.

loading table of contents...