The following Java code can access and execute any parameterized SQL named query:

import atg.repository.*;
...

// somehow get item descriptor
RepositoryView view = itemDesc.getRepositoryView();
...

try {
  if(!(view instanceof NamedQueryView))
    throw new ServletException
      ("view " + view.getViewName() + " is not a NamedQueryView");
  NamedQueryView nView = (NamedQueryView)view;
  Query namedQuery = nView.getNamedQuery(queryName);

  ...

  if(!(view instanceof ParameterSupportView))
    throw new ServletException
      ("view " + view.getViewName() + " is not a ParameterSupportView");
  return ((ParameterSupportView)view).executeQuery(namedQuery, args);
}

catch (RepositoryException re) {
  if (pServlet.isLoggingError())
    pServlet.logError("unable to execute query due to RepositoryException",re);
  throw re;
}

Any repository that extends atg.repository.RepositoryViewImpl can access the base NamedQuery feature.

The following sections describe the named query API:

NamedQueryView Interface

Interface atg.repository.NamedQueryView provides methods to create and access named queries. This interface extends atg.repository.RepositoryView. Oracle ATG Web Commerce provides an implementation: the class atg.repository.RepositoryViewImpl, which supports the use of named queries.

The NamedQueryView interface includes the methods described in the following table:

Method

Description

createNamedQuery

public void createNamedQuery(String pQueryName, Query pQuery)

Creates an association in the RepositoryView between a name and a Query object. After this association is created, you can call getNamedQuery to get the Query object to be used for execution. If this method is called with a pQueryName that is already assigned a Query, the existing Query is overwritten with the new Query

getNamedQuery

public Query getNamedQuery(String pQueryName)

Gets the Query object associated with the given name. If no such entry was created for the given String, null is returned.

getNamedQueryNames

public String[] getNamedQueryNames()

Returns the names of all Named Queries that this RepositoryView knows about, or null if there are none.

getQueryDescriptor

public QueryDescriptor getQueryDescriptor(String pQueryName)

Returns a QueryDescriptor object that describes aspects of the requested NamedQuery. If there is no named query by the given name, null is returned.

getQueryName

public String getQueryName(Query pQuery)

Returns the name of the given Query, if any exists. Otherwise, null is returned.

QueryDescriptor

Interface atg.repository.QueryDescriptor defines methods for an object that describes a Repository Query and associates a Repository Query object with a user-defined String. It defines the following methods:

public Query getQuery()
public String getQueryName()

The atg.repository.query.QueryDescriptorImpl class is the base implementation of the QueryDescriptor interface and the atg.adapter.gsa.query.GSAQueryDescriptor class is the SQL repository’s subclass of QueryDescriptorImpl.