Service Registry 3.1 Update 1 Developer's Guide

Using Stored Queries

It is possible to invoke queries that are stored in the Registry. A number of predefined queries are already stored in the Registry as AdhocQuery objects. To find them, search for objects of that type. Most of these queries are provided in the Web Console. See Chapter 2, Searching the Registry, in Service Registry 3.1 Update 1 User’s Guide for information on how to invoke these queries through the Web Console.

To invoke stored queries through JAXR, you need to know the following:

For example, suppose you wanted to invoke the stored query named Basic Query to search by object type for all organizations in the Registry. If you look at this query in the Web Console, you can see that it takes a parameter named $objectTypePath. This means that you specify the classification scheme node as a path structure instead of specifying the concept for the object type directly. The following code first retrieves the constant for the query identifier, then specifies the object type path. The actual String value of the object type path is /urn:oasis:names:tc:ebxml-regrep:classificationScheme:ObjectType/RegistryObject/Organization.

String queryId = 
    CanonicalConstants.CANONICAL_QUERY_BasicQuery;
String objectType = 
    CanonicalConstants.CANONICAL_CLASSIFICATION_SCHEME_ID_ObjectType;
String objectTypePath = 
    "/" + objectType + "/RegistryObject/Organization";

Once you have the values for the query identifier and the parameters, you create a HashMap to pass these values. First put the parameters in the HashMap, and finally the query identifier, using the constant CANONICAL_SLOT_QUERY_ID to specify the parameter name. Then you call an implementation-specific form of the DeclarativeQueryManager.createQuery method to create the query. Finally, you call an implementation-specific form of the DeclarativeQueryManager.executeQuery method to execute the parameterized query.

Map parameters = new HashMap();
parameters.put("$objectTypePath", objectTypePath);
parameters.put(CanonicalConstants.CANONICAL_SLOT_QUERY_ID, queryId);
Query query = dqm.createQuery(Query.QUERY_TYPE_SQL);

BulkResponse br = dqm.executeQuery(query, parameters);

The signatures of the implementation-specific forms of the createQuery and executeQuery methods are as follows:

public Query createQuery(int queryType)
    throws InvalidRequestException, JAXRException

public BulkResponse executeQuery(Query query, java.util.Map queryParams)
    throws JAXRException

Using 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 returns all organizations stored in the Registry.

ProcedureTo Run the JAXRQueryStored Example

  1. Go to the directory install/registry-samples/query-stored.

  2. Type the following command:


    Ant-base/ant run
    

    The output of the run target looks something like this:


    run:
         [java] Query URL is http://localhost:6480/soar/registry/soap
         [java] Created connection to registry
         [java] Got registry service and query managers
         [java] Query ID is urn:freebxml:registry:query:BusinessQuery
         [java] Object type path is 
    /urn:oasis:names:tc:ebxml-regrep:classificationScheme:ObjectType/RegistryObject/Organization
         [java] Object type is Organization
         [java] Object name is freebXMLRegistry
         [java] Object description is freebXML Registry
         [java]  --- 
         [java] Object type is Organization
         [java] Object name is GenericOrg
         [java] Object description is Generic organization
         [java]  ---