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 > Examples of the query and queryAll methods
Example: Querying tasks in the ready state
This example shows how to use the query method to retrieve tasks that the logged-on user can work with.
John Smith wants to get a list of the tasks that have been assigned to him. For a user to be able to work on a task, the task must be in the ready state. The logged-on user must also have a potential owner work item for the task. The following code snippet shows the query method call for this query:
query( "DISTINCT TASK.TKIID", "TASK.KIND IN ( TASK.KIND.KIND_HUMAN, TASK.KIND.KIND_PARTICIPATING ) AND " + "TASK.STATE = TASK.STATE.STATE_READY AND " + "WORK_ITEM.REASON = WORK_ITEM.REASON.REASON_POTENTIAL_OWNER", (String)null, (String)null, (Integer)null, (TimeZone)null )The following actions are taken when the SQL SELECT statement is generated:
- A condition for access control is added to the where clause. This example assumes that group work items are not enabled.
- Constants, such as TASK.STATE.STATE_READY, are replaced by their numeric values.
- A FROM clause and join conditions are added.
The following code snippet shows the SQL statement that is generated from the API query:
SELECT DISTINCT TASK.TKIID FROM TASK TA, WORK_ITEM WI, WHERE WI.OBJECT_ID = TA.TKIID AND TA.KIND IN ( 101, 105 ) AND TA.STATE = 2 AND WI.REASON = 1 AND ( WI.OWNER_ID = 'JohnSmith' OR WI.OWNER_ID = null AND WI.EVERYBODY = true )To restrict the API query to tasks for a specific process, for example, sampleProcess, the query looks as follows:
query( "DISTINCT TASK.TKIID", "PROCESS_TEMPLATE.NAME = 'sampleProcess' AND "+ "TASK.KIND IN ( TASK.KIND.KIND_HUMAN, TASK.KIND.KIND_PARTICIPATING ) AND " + "TASK.STATE = TASK.STATE.STATE_READY AND " + "WORK_ITEM.REASON = WORK_ITEM.REASON.REASON_POTENTIAL_OWNER", (String)null, (String)null, (Integer)null, (TimeZone)null )