Service Registry 3.1 Update 1 Developer's Guide

Using Declarative Queries

Instead of the BusinessQueryManager interface, you can use the DeclarativeQueryManager interface to create and execute queries to the Registry. If you are familiar with SQL, you might prefer to use declarative queries. The DeclarativeQueryManager interface depends on another interface, Query.

The DeclarativeQueryManager interface has two methods, createQuery and executeQuery. The createQuery method takes two arguments, a query type and a string that contains the query. The following code fragment creates an SQL query that asks for a list of all Service objects in the Registry. Here, rs is a RegistryService object.

DeclarativeQueryManager qm = rs.getDeclarativeQueryManager();
String qString = "select s.* from Service s";
Query query = qm.createQuery(Query.QUERY_TYPE_SQL, qString);

After you create the query, you execute it as follows:

BulkResponse response = qm.executeQuery(query);
Collection objects = response.getCollection();

You then extract the objects from the response just as you do with ordinary queries.

For more information on SQL query syntax and for examples, see Chapter 6, “Query Management Protocols,” of the ebRS 3.0 specification, especially Section 6.6.

Using Declarative Queries: Example

For examples of the use of declarative queries, see JAXRQueryDeclarative.java and JAXRGetAllSchemes.java in the directory install/registry-samples/query-declarative/src. Both examples create and execute a SQL query. The query strings are defined in the JAXRExamples.properties file.

The SQL query string for JAXRQueryDeclarative is as follows (all on one line):


SELECT ro.* from RegistryObject ro, Name nm, Description d 
WHERE upper(nm.value) LIKE upper(’%free%’) AND upper(d.value) 
LIKE upper(’%free%’) AND (ro.id = nm.parent AND ro.id = d.parent)

This query finds all objects that have the string "free" in both the name and the description attributes.

The SQL query string for JAXRGetAllSchemes is as follows:


SELECT * FROM ClassScheme s order by s.id

This query finds all the classification schemes in the Registry.

ProcedureTo Run the JAXRQueryDeclarative Example

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

  2. To run the JAXRQueryDeclarative example, type the following command:


    Ant-base/ant get-free
    

    The output of the get-free target looks something like this:


    get-free:
         [java] Query URL is http://localhost:6480/soar/registry/soap
         [java] Query string is SELECT ro.* FROM RegistryObject ro, Name nm, Description d 
    WHERE upper(nm.value) LIKE upper('%free%') AND upper(d.value) LIKE upper('%free%') 
    AND (ro.id = nm.parent AND ro.id = d.parent)
         [java] Created connection to registry
         [java] Got registry service and query manager
         [java] Object type is Federation
         [java] Object name is freebXMLRegistryFederation
         [java] Object description is freebXML Registry Federation
         [java]  --- 
         [java] Object type is Organization
         [java] Object name is freebXMLRegistry
         [java] Object description is freebXML Registry
         [java]  --- 
         [java] Object type is Registry
         [java] Object name is freebXMLRegistry
         [java] Object description is freebXML Registry
         [java]  --- 
  3. To run the JAXRGetAllSchemes example, type the following command:


    Ant-base/ant get-schemes
    

    The output of the get-schemes target begins something like this:


    get-schemes:
         [java] Query URL is http://localhost:6480/soar/registry/soap
         [java] Created connection to registry
         [java] Got registry service and query manager
         [java] Query string is SELECT * FROM ClassScheme s ORDER BY s.id
         [java] All classification schemes and their URNs:
         [java] 1. NASDAQ -- urn:devguide:samples:ClassificationScheme:NASDAQ
         [java] 2. HL7 -- urn:freebxml:registry:demo:schemes:HL7
         [java] 3. iso-ch:3166:1999 -- urn:freebxml:registry:demo:schemes:iso-ch:3166:1999
         [java] 4. DUNS -- urn:freebxml:registry:demoDB:classificationScheme:DUNS
         [java] 5. NYSE Ticker -- urn:freebxml:registry:demoDB:classificationScheme:NYSETicker
         ...