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:
FindAllMyObjects is equivalent to the QueryManager.getRegistryObjects() method, which is described in Finding Objects You Published.
GetCallersUser is equivalent to the question “Who am I?” This query returns the User object that is associated with the client that executed the query. If the caller is not logged in to the Registry, this query returns the user that is named “Registry Guest”.
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(); ...
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.