Here is an example that shows task persistence using H2 database. A simple process that has a couple of human tasks as shown below is considered for this example.

 

processbpmn2.png

 

This example uses the jBPM plugin for Eclipse (jBPM6 - Eclipse BPMN Modeler Installation).

 

 

This examples has a bpmn file (SampleHumanTasks.bpmn), a process test program that starts the process(TaskPersistnecTest.java or TaskPersistenceExample.java), a persistence configuration files (persistence.xml ) and a Bitronix JNDI file ( jndi.properties) .

The persistence configuration file needs to be included in META-INF folder as shown below. Please refer to JPA/Hibernate documents to know more about persistence configuration details.

 

projectexplorer.png

 

This example uses H2 database to show the persistence of process state into various tables.

startH2.png

JBPM6 database persistence involves following categories:

 

1.) Process persistence: This involves persisting runtime state that represents current execution state in a specific context. The runtime state contains the minimal runtime state that is required to continue execution at a later time. This allows restoring the state of execution of all the running processes (e.g., ProcessInstanceInfo)  in the event of a failure.

 

2.) Human task persistence: Task management component, which is treated as a separate component, can persist all the task information (e.g, user, assignment etc) into database.

 

3.) History or Auditlog persistence: All the audit log information(e.g., ProcessInstanceLog, NodeInstanceLog etc)can stored in database for reporting purposes.

 

The database tables can be viewed in Eclipse using one of database plugins such as SQLExplorer, QuantumDB etc.

tables.png

The database mapping of various tables can be seen in the JPA persistence xml file included in META-INF.

persistence1.png

 

 

persistence2.png

 

jBPM6 introduces a new module called RuntimeManager which simplies the access to KnowledgeSession (KieSession) and taskservice etc.

There are various pre-defined startegies for creating RuntimeManager, such as singleton (one session for all the requests), session per request (a new session for each request) and session per process instance (each process has its own context and all the commands get executed in that context).

 

This example uses singleton strategy.

runtimemanager.png

Here is a code snippet that shows how to use the taskservice to start and complete a task.

tasksummarycomplete.png

 

After running the example successfully following results can be seen,

results.png

A SQL client can be used to examine the contents of various process, task and audit tables.

teaskquery.png

 

processinstancelog.png