Managing stored queries

Why and when to perform this task

A stored query is a query that is stored in the database and identified by a name. Although the query definitions are stored in the database, items contained in the stored query are assembled dynamically when they are queried. All stored queries are publicly accessible. You can have stored queries for business process objects, task objects, or a combination of these two object types.

Steps for this task

  1. Create a stored query.

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

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

    This query returns 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. Optional: List the available stored queries.

    For example, the following code snippet shows how to get a list of stored queries for process objects:

    String[] storedQuery = process.getStoredQueryNames();
  4. Optional: Check the query defined by a specific stored query.
    StoredQuery storedQuery = process.getStoredQuery("CustomerOrdersStartingWithA");
    String selectClause = storedQuery.getSelectClause();
    String whereClause = storedQuery.getWhereClause();
    String orderByClause = storedQuery.getOrderByClause();
    Integer threshold = storedQuery.getThreshold();
  5. Delete a stored query.

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

    process.deleteStoredQuery("CustomerOrdersStartingWithA");

Terms of use | | Broken links

Last updated: Mon Mar 27 18:04:06 2006

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