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 Commerce Platform 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 |
---|---|
|
Creates an association in the |
|
Gets the |
|
Returns the names of all Named Queries that this |
|
Returns a |
|
Returns the name of the given |
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
.