Service Registry 3.1 Update 1 Developer's Guide

Using Federated Queries

If the registry you are querying is part of one or more registry federations (see About Registries and Repositories), you can perform declarative queries on all registries in all federations of which your registry is a member, or on all the registries in one federation.

To perform a query on all registries in all federations of which your registry is a member, call the implementation-specific setFederated method on a QueryImpl object. The method has the following signature:

public void setFederated(boolean federated)
    throws JAXRException

You call the method as follows:

QueryImpl query = (QueryImpl)
    dqm.createQuery(Query.QUERY_TYPE_SQL, qString);
query.setFederated(true);

If you know that your registry is a member of only one federation, this method is the only one you need to call before you execute the query.

To limit your query to the registries in one federation, you need to call an additional implementation-specific method, setFederation. This method takes as its argument the unique identifier of the federation you want to query:

public void setFederation(java.lang.String federationId)
    throws JAXRException

Therefore, before you can call this method, you must obtain the unique identifier value. Normally, this value is well-known.

Next, create the query, call setFederated and setFederation, and execute the query:

QueryImpl query = (QueryImpl)
    dqm.createQuery(Query.QUERY_TYPE_SQL, qString);
query.setFederated(true);
query.setFederation(fedId);
response = dqm.executeQuery(query);

Using Federated Queries: Example

For an example of the use of a federated query, see JAXRQueryFederation.java in the directory install/registry-samples/query-federation/src. This example performs two queries, a declarative query and a stored query, on every federation it finds (the database provided with the Registry contains only one). Because the federation stored in the Registry database does not have a well-known identifier value, the example uses findObjects to locate the federation.

The declarative query is the query that is performed in Using Declarative Queries: Example. The stored query is the FindAllMyObjects query.

Because the federation in the Registry database has no members, this example cannot perform the queries.

ProcedureTo Run the JAXRQueryFederationExample

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

  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 manager
         [java] Federation name: freebXMLRegistryFederation
         [java] Federation description: freebXML Registry Federation
         [java] Federation key id: urn:uuid:cb5039c1-85b2-4512-839a-893cb882c981
         [java] Federation has no members
         [java] Cannot perform query