This example shows the persistence feature of JBPM5 using Hello Proces example (http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in).
JBPM5 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 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.
How to install and run this example?
Start with the setup as shown in http://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in.
This example needs two jar files, one for database (e.g, h2.jar for H2, oracle-11.1.0.6.jar for Oracel etc) and another one Bitronix transaction manager (btm-1.3.3.jar). Add theste two jar files into Eclipse's project classpath.
This examples has a bpmn file (HelloProcess.bpmn), a process test program that starts the process(ProcessTest.java), a standalone task server (TaskServer.java), two persistence configuration files (orm.xml and persistence.xml ) and a Bitronix JNDI file ( jndi.properties) .
The persistence configuration files need to be included in META-INF folder as shown below. Please refer to JPA/Hibernate documents to know more about persistence configuration details.
After running the example successfully, tables for process, human task etc are created as shown below.
The task can be approved using the Eclipse plugin. Select the plugin using Windows->ShowView->DRools Task->Human Task View.
The logging for Hibernate persistence is set to true to display the generated SQL queries as shown below.
Process logs from ProcessTest.java
Taskserver logs from TaskServer.java
Here are some important points to note:
Process persistence: It uses JPA/Hibernate as default to persist the runtime state. Create the knowledge session as shown below .
/*
* Create EntityManagerFactory and register it in the environment
* Create the knowledge session that uses JPA to persists runtime state
*/
private static StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );
env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);
}
Persistence configuration file (persistence.xml) includes the classes that are required for process persistence.
Human task persistence has another independent persistencecomponent which is responsible for persisting task related activities (e.g.,task assignments, comments, content, notification etc)
The human task management component is an independent service which has communication with the process engine. This is started using 'TaskServer.java' class.
EntityManagerFactory emfTask = Persistence.createEntityManagerFactory( "org.jbpm.task" );
TaskService taskService = new TaskService(emfTask, SystemEventListenerFactory.getSystemEventListener());
/* Start Mina server for HT*/
MinaTaskServer server = new MinaTaskServer(taskService);
Thread thread = new Thread(server);
thread.start();
It is also required to have the corresponding human task classes in the Hibernate persistence configuration file (persistence.xml) as shown below.
History or Auditlog persistence: The persistence configuration file should also include the classes that correspond to audit logs.