IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Developing client applications for BPEL processes and tasks > Queries on BPEL process and task data > Business Process Choreographer EJB query API > Manage stored queries

Manage public stored queries

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

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.


Procedure

  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), null);
    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 use the Human Task Manager API to retrieve information about a stored query, use StoredQuery for the returned object 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 created in step 1.

    process.deleteStoredQuery("CustomerOrdersStartingWithA");

Manage stored queries