Service Registry 3 2005Q4 Developer's Guide

Invoking Stored Queries

The implementation-specific AdhocQueryImpl class, which extends RegistryObjectImpl, allows you to invoke queries that are stored in the Registry. The Registry has several default AdhocQueryImpl objects that you can invoke. The most useful are named FindAllMyObjects and GetCallersUser:

The simplest way to find a stored query is to look the query up by its unique identifier. The GetCallersUser query has a canonical constant defined for it (see Constant for Stored Query). You can use the string value of the unique identifier to locate queries that do not have canonical constants.

String queryId = 
    CanonicalConstants.CANONICAL_QUERY_GetCallersUser;
AdhocQueryImpl aq = 
    (AdhocQueryImpl) bqm.getRegistryObject(queryId);

Then find the query string associated with the AdhocQuery and use the string to create and execute a query, this time by using DeclarativeQueryManager methods.

if (aq != null) {
        int qType = aq.getType();
    String qString = aq.toString();
    Query query = dqm.createQuery(qType, qString);

    BulkResponse br = dqm.executeQuery(query);
    Collection objects = br.getCollection();
    ...

Invoking Stored Queries: Example

For an example of the use of a stored query, see JAXRQueryStored.java in the directory <INSTALL>/registry/samples/query-stored/src. This example authenticates the user, so it returns the user’s registry login name.

ProcedureTo Run the JAXRQueryStoredExample

Steps
  1. Go to the directory <INSTALL>/registry/samples/query-stored.

  2. Type the following command:


    asant run