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.
- 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).
- 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.
- 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();
- 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();
- Delete a stored query.
The following code snippet
shows how to delete the stored query that you created in step 1.
process.deleteStoredQuery("CustomerOrdersStartingWithA");