Managing public stored queries

Public stored queries are created by the system administrator. These queries are available to all users.

Why and when to perform this task

As the system administrator, you can create, view, and delete public stored queries. If you do not specify a user ID in the API call, it is assumed that the stored query is a public stored query.

Steps for this task

  1. Create a public stored query.

    For example, the following code snippet creates a stored query for process instances and saves it with the name CustomerOrdersStartingWithA.

    process.createStoredQuery("CustomerOrdersStartingWithA",
                 "DISTINCT PROCESS_INSTANCE.PIID, PROCESS_INSTANCE.NAME",
                 "PROCESS_INSTANCE.NAME LIKE 'A%'",
                 "PROCESS_INSTANCE.NAME",
                  (Integer)null, (TimeZone)null); 

    The result of the stored query is a sorted list of all the process-instance names that begin with the letter A and their associated process instance IDs (PIID).

  2. Run the query defined by the stored query.
    QueryResultSet result = process.query("CustomerOrdersStartingWithA", 
                   new Integer(0));
    This action returns the objects that fulfill the criteria. In this case, all of the customer orders that begin with A.
  3. List the names of the available public stored queries.

    The following code snippet shows how to limit the list of returned queries to just the public queries.

    String[] storedQuery = process.getStoredQueryNames(StoredQueryData.KIND_PUBLIC);
  4. Optional: Check the query that is defined by a specific stored query.
    A stored private query can have the same name as a stored public query. If these names are the same, the private stored query is returned. The following code snippet shows how to return only the public query with the specified name. If you want to run this query for task-based objects, specify StoredQuery as the returned object type instead of StoredQueryData.
    StoredQueryData storedQuery = process.getStoredQuery
       (StoredQueryData.KIND_PUBLIC, "CustomerOrdersStartingWithA");
    String selectClause = storedQuery.getSelectClause();
    String whereClause = storedQuery.getWhereClause();
    String orderByClause = storedQuery.getOrderByClause();
    Integer threshold = storedQuery.getThreshold();
    String owner = storedQuery.getOwner();
  5. Delete a public stored query.

    The following code snippet shows how to delete the stored query that you created in step 1.

    process.deleteStoredQuery("CustomerOrdersStartingWithA");

Copyright IBM Corporation 2005, 2006.
This information center is powered by Eclipse technology (http://www.eclipse.org)