February 04, 2006 01:27
Java, ATG Dynamo
The named query feature in ATG 7.0 is very useful. However, it's actually confusing to use, because it's not clear how to use it.

You start off by creating the query in the XML:

  <item-descriptor name="person">
     <named-query>
        <rql-query query-name="myQuery">
           <rql>name = ?0.name AND age = ?1.age</rql>
        </rql-query>
     </named-query>
  </item-descriptor>

And this exposes a NamedQueryView to the repository. However, it doesn't show how you execute the query with parameters, which is what you used to be able to do with rqlStatement.executeQuery(view, params). This is actually covered in the section before, concerning Parameterized Queries... but you need to put the two chapters together before it makes sense.

RepositoryItem steve, bill; // assume these get initialized correctly
Repository r = getRepository();
RepositoryView view = r.getView("foo");
NamedQueryView namedQueryView = (NamedQueryView) view;
ParameterSupportView parameterSupportView = (ParameterSupportView) view;
Query myQuery = namedQueryView.getNamedQuery("myQuery");
Object[] parameters = { steve, bill };
// Returns an array of person items.
RepositoryItem[] items = parameterSupportView.executeQuery(myQuery, parameters);

And there you go.

« Time tracking for programmers | Home | ATG Security »

name
url