Configure jBPM with MySQL

Hello Guys, Here is my next post on jBPM, the most flexible option of jBPM is that, it can be configured with major Database vendors of market like Oracle, MS SqlServer, MySql,etc. In this post i want to explain how to download the latest jBPM and configure it with MySQL

Step 1: please download “jbpm-5.4.0.Final-installer-full.zip”
Step 2: Extract it to your preferred locations of your PC.
Step 3: Setup Mysql Database.
Step 4: With MySQL installed, log in as the root user and run the following commands

mysql> CREATE SCHEMA IF NOT EXISTS jbpm5;
mysql> CREATE USER 'jbmp5'@'localhost' IDENTIFIED BY 'jbpm5';
mysql> GRANT ALL PRIVILEGES ON jbpm5.* TO 'jbpm5'@'localhost';

mysql> CREATE SCHEMA IF NOT EXISTS task;
mysql> CREATE USER 'task'@'localhost' IDENTIFIED BY 'task';
mysql> GRANT ALL PRIVILEGES ON task.* TO 'task'@'localhost;

Set up jBPM
Step 5:

ant clean.demo

Second, you will have to change the following files:

a. build.properties
b. db/jbpm-persistence-JPA2.xml
c. db/task-persistence-JPA2.xml
d. standalone.xml
e. task-service/resources/META-INF/persistence.xml
f. lib/jbpm-gwt-console-server-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml
g. lib/jbpm-human-task-war-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml

build.properties
change:

# data base related properties
db.driver.jar=${install.home}/db/driver/${db.driver.jar.name}
db.driver.module.dir=${jboss.home}/modules/${db.driver.module.prefix}/main/
# default is H2
db.name=h2
db.driver.jar.name=${db.name}.jar
db.driver.download.url=http://repo1.maven.org/maven2/com/h2database/h2/${H2.version}/h2-${H2.version}.jar
#other options are mysql
#  db.name=mysql
#  db.driver.module.prefix=com/mysql
#  db.driver.jar.name=${db.name}-connector-java.jar
#  db.driver.download.url=https://repository.jboss.org/nexus/service/local/repositories/central/content/mysql/mysql-connector-java/5.1.18/mysql-connector-java-5.1.18.jar
#postresql
#  db.name=postresql
#  db.driver.module.prefix=org/postgresql
#  db.driver.jar.name=${db.name}-jdbc.jar
#  db.driver.download.url=https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads/postgresql/postgresql/9.1-902.jdbc4/postgresql-9.1-902.jdbc4.jar

To:

# data base related properties
db.driver.jar=${install.home}/db/driver/${db.driver.jar.name}
db.driver.module.dir=${jboss.home}/modules/${db.driver.module.prefix}/main/
#  default is H2
#  db.name=h2
#  db.driver.jar.name=${db.name}.jar
#  db.driver.download.url=http://repo1.maven.org/maven2/com/h2database/h2/${H2.version}/h2-${H2.version}.jar
#other options are mysql
  db.name=mysql
  db.driver.module.prefix=com/mysql
  db.driver.jar.name=${db.name}-connector-java.jar
  db.driver.download.url=https://repository.jboss.org/nexus/service/local/repositories/central/content/mysql/mysql-connector-java/5.1.18/mysql-connector-java-5.1.18.jar
#postresql
#  db.name=postgresql
#  db.driver.module.prefix=org/postgresql
#  db.driver.jar.name=${db.name}-jdbc.jar
#  db.driver.download.url=https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads/postgresql/postgresql/9.1-902.jdbc4/postgresql-9.1-902.jdbc4.jar

db/jbpm-persistence-JPA2.xml

change:

<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />

To:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

standalone.xml

Change:

<datasource jta="true" jndi-name="java:jboss/datasources/jbpmDS" pool-name="H2DS" enabled="true" use-java-context="true" use-ccm="true">
  <connection-url>jdbc:h2:~/jbpm</connection-url>
  <driver>h2</driver>
  <pool>
    <min-pool-size>1</min-pool-size>
    <max-pool-size>4</max-pool-size>
    <prefill>false</prefill>
    <use-strict-min>false</use-strict-min>
    <flush-strategy>FailingConnectionOnly</flush-strategy>
  </pool>
  <security>
    <user-name>sa</user-name>
  </security>
  <validation>
    <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
    <validate-on-match>false</validate-on-match>
    <background-validation>false</background-validation>
  </validation>
</datasource>
<drivers>
  <driver name="h2" module="com.h2database.h2">
    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
  </driver>
</drivers>

To:

<datasource jta="true" jndi-name="java:jboss/datasources/jbpmDS" pool-name="H2DS" enabled="true" use-java-context="true" use-ccm="true">
  <connection-url>jdbc:mysql://localhost:3306/jbpm5</connection-url>
  <driver>mysql</driver>
  <pool>
    <min-pool-size>1</min-pool-size>
    <max-pool-size>4</max-pool-size>
    <prefill>false</prefill>
    <use-strict-min>false</use-strict-min>
    <flush-strategy>FailingConnectionOnly</flush-strategy>
  </pool>
  <security>
    <user-name>jbpm5</user-name>
    <password>jbpm5</password>
  </security>
  <validation>
    <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
    <validate-on-match>false</validate-on-match>
    <background-validation>false</background-validation>
  </validation>
</datasource>
<drivers>
  <driver name="mysql" module="com.mysql">
    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
  </driver>
</drivers>

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

db/task-persistence-JPA2.xml

Change:

<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>

To:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

task-service/resources/META-INF/persistence.xml

Change:

<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.connection.url" value="jdbc:h2:tcp://localhost/runtime/task" />
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>

To:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql:://localhost:3306/task" />
<property name="hibernate.connection.username" value="task"/>
<property name="hibernate.connection.password" value="task"/>

Now its time to change the persistence.xml in lib/jbpm-gwt-console-server-5.4.0.Final-EE6.war and lib/jbpm-human-task-war-5.4.0.Final-EE6.war. to do this install 7-zip software open the war file using 7Zip and change the persistence.xml save and close it as below.

lib/jbpm-human-task-war-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml
Change:

<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />

To:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

lib/jbpm-gwt-console-server-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml
Change:

<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />

To:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

Install jBPM
Run:

ant install.demo 

To start the jBPM environment you can run:

ant start.demo.db

or

ant start.demo.db.noeclipse

after you execute all the steps above and run the application, open the database and you should find your database with the tables as shown below.
jbpm5_schema

Happy Coding, Happy jBPM 🙂

jBPM Loops Concept

Hello all, As told i will be posting jBPM tutorials from now, here is my next tutorial on jBPM loops. prior to this tutorial please download jBPM 5.x version and install the demo environment after that open the eclipse jBPM editor and code the process as shown below. just by drag and drop the BPM components.

jbpm-looping

once the process is ready please click on the empty space of the editor and edit the properties as below.

process_init_var

now click the “first log node” as shown below and open the property Palette edit the action Values as shown below.
the “kcontext” is the jBPM KnowledgeContext available inorder to access the process variables.
Edit_log1

in the process shown there are two gateways the first one is converging gateway and the second one is diverging gateway. i will post a seperate article on gateways later.click on the first gateway and assign XOR as value for the type value. now click the second log node and in the property pallete edit the properties and put the simple logic as shown below.

Edit_log2

Now click on the second gateway since it is the converging gateway, click the Condition browse button and add a condition as shown below.

ifCondition

now lets give the else logic as shown below.else

once done lets prompt the process that it is done by editing the last log node.
now its time for a test run of the process

package com.spark.jbpm.sample.loops;

import java.util.HashMap;
import java.util.Map;

import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;

/**
 * @author Sony
 *
 */
public class LoopingExample {
	
	public static final void main(String[] args) {
		try {
			// load up the knowledge base
			KnowledgeBase kbase = readKnowledgeBase();
			StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
			KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);
			// start a new process instance
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("count", 5);
			ksession.startProcess("com.sample.looping", params);
			logger.close();
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

	private static KnowledgeBase readKnowledgeBase() throws Exception {
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		kbuilder.add(ResourceFactory.newClassPathResource("looping/Looping.bpmn"), ResourceType.BPMN2);
		return kbuilder.newKnowledgeBase();
	}

}

and finally u will see the O/P of your first jBPM Process.

Happy jBPM 🙂