Service Registry 3 2005Q4 Developer's Guide

Querying a Registry Federation

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. To do so, first call BusinessQueryManagerImpl.findObjects to locate the federation by name. In this code, you would substitute the actual name of the federation for the string "NameOfFederation".

Collection namePatterns = new ArrayList();
namePatterns.add("NameOfFederation");

// Find objects with name NameOfFederation
BulkResponse response =
    bqm.findObjects("Federation", null, namePatterns,
         null, null, null, null);

Then, iterate through the collection (which should have only one member) and retrieve the key value:

String fedId = federation.getKey().getId();

Finally, 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).

The declarative query is the query that is performed in Using Declarative Queries: Example. The stored query is the FindAllMyObjects query. Because this example does not authenticate the user, the user that makes the query is RegistryGuest. The user RegistryGuest owns only one object, itself. Therefore, the FindAllMyObjects query returns only one result, the user RegistryGuest.

ProcedureTo Run the JAXRQueryFederationExample

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

  2. Type the following command:


    asant run