Friday 19 August 2011

Set up JBPM – Oracle - Tomcat 6

1. Add transaction and Resource information after 'WatchedResource' line in TOMCAT_HOME/conf/context.xml as shown below. This step is required to create a datasource in tomcat

<WatchedResource>WEB-INF/web.xml</WatchedResource>

<Transaction factory ="bitronix.tm.BitronixUserTransactionObjectFactory" />

<Resource name="jdbc/testDS1" auth="Container" type="javax.sql.DataSource" maxActive="15" maxIdle="2" maxWait="10000" logAbandoned="true"username="username" password="password" driverClassName=" oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@yourdatabaseurl:port:db"/>


2. Create 'resource.properties' in TOMCAT_HOME/conf and add following as shown below.
resource.ds1.className=bitronix.tm.resource.jdbc.lrc.LrcXADataSource
resource.ds1.uniqueName=jdbc/testDS1
resource.ds1.minPoolSize=0
resource.ds1.maxPoolSize=5
resource.ds1.driverProperties.driverClassName=oracle.jdbc.OracleDriver

3. Copy oracle ojdbc14.jar into the ‘tomcat/lib’ and ‘jbpm-installer/runtime’ folder for oracle driver.

4. Modify hibernate.cfg.xml in TOMCAT_HOME\webapps\gwt-console-server\WEB-INF\classes\META-INF to include Oracle connection details and comment the h2 details.
Note: Its better to change into the WAR (gwt-console-server.war) itself so can be deployed on different instances.

Replace the session-factory tag from below
<session-factory>
<!-- h2 Database connection settings -->
<!--property name="connection.url">jdbc:h2:file:/NotBackedUp /data/mydb</property-->
<!--
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:tcp://localhost/~/test</ property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
-->
<!-- Oracle Database connection settings -->
<property name="connection.driver_class"& gt;oracle.jdbc.OracleDriver</property>
<property name="connection.url">
jdbc:oracle:thin:@yourdatabaseurl:port:db</property>
<property name="connection.username">username</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</ property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread& lt;/property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class"& gt; org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="AuditLog.hbm.xml"/>
</session-factory>

5. Make sure the jbpm-human-task-5.0-SNAPSHOT.jar is in TOMCAT_HOME/webapps/gwt-console-server/WEB-INF/lib (5.1 full installer zip contains this jar in the gwt-console-server web-inf lib) OR if not present then download and copy jbpm-human-task-5.0-SNAPSHOT.jar to TOMCAT_HOME/webapps/gwt-console-server/WEB-INF/lib

6. Make sure the jbpm-bam-5.0-SNAPSHOT.jar is in TOMCAT_HOME/webapps/gwt-console-server/WEB-INF/lib (5.1 full installer zip contains this jar in the gwt-console-server web-inf lib) OR if not present then download and copy copy jbpm-bam-5.0-SNAPSHOT.jar to TOMCAT_HOME/webapps/gwt-console-server/WEB-INF/lib

7. Add or Replace oracle connection details in persistence.xml of TOMCAT_HOME\webapps\gwt-console-server\WEB-INF\classes\META-INF.

<persistence-unit name="org.jbpm.persistence.jpa">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jdbc/testDS1</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<class>org.drools.persistence.session.SessionInfo</class>
<class>org.drools.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.processinstance.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>


8. Modify the jbpm-bam-5.1.0.Final.jar/hibernate.cfg.xml of to add the oracle connection properties. Replace the session-factory with the following xml.

<session-factory>
<!-- h2 Database connection settings -->
<!--property name="connection.url">jdbc:h2:file:/NotBackedUp/data/mydb</property-->
<!--
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:tcp://localhost/~/test</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
-->
<!-- Oracle Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">
jdbc:oracle:thin:@yourdatabaseurl:port:db</property>
<property name="connection.username">username</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="AuditLog.hbm.xml"/>
</session-factory>


9. Make sure all the above modified jars (jbpm-bam-5.1.0.Final.jar, jbpm-human-task-5.1.0.Final.jar) are also present/copied to the jbpm-installer/runtime folder before running ‘ant start.human.task’ from jbpm-installer. On running the task, all the tables will be created in oracle schema.

Set up the JBPM suite on tomcat 6

1. Download tomcat 6 from apache website tomcat-6.0.32.zip and unzip in a folder.
2. Change the TOMCAT_HOME, CATALINA_HOME env variable pointing to the new tomcat folder.
3. Download jbpm-5.1.0.Final-installer-full.zip from jboss site unzip into a folder.
a. Go into the lib folder, which will have 6 more files in it. 2 wars and 6 zip files.
4. copy 2 wars into the tomcat-home/webapps. Rename of war is required as per below names otherwise all the applications does not start properly.
a. Rename the designer-1.0.0.052-jboss.war to designer.war
b. Rename the guvnor-distribution-wars-5.2.0.Final-jboss-as-5.1.war to drools-guvnor.war
c. Unzip jbpm-5.1.0.Final-gwt-console.zip into the webapps. This zip contains 2 more wars.
d. Rename jbpm-gwt-console-server-5.1.0.Final.war to gwt-console-server.war
e. Rename jbpm-gwt-console-5.1.0.Final.war to jbpm-console.war
5. At this point, if tomcat is restarted, the complete suit is ready to work on. Go to tomcat manager (localhost:8080) and try launching drools-guvnor and jbpm-console. All the functionality does not work with IE so use firefox. It may ask to install google frame. Accept and continue.
6. To login into jbpm console, create few users into tomcat-users.xml as below.






Thursday 18 August 2011

Drop all tables from schema

Run below code to drop all the tables from schema.

BEGIN

FOR i IN (SELECT table_name FROM user_tables)
LOOP
EXECUTE IMMEDIATE('DROP TABLE ' || user || '.' || i.table_name || ' CASCADE CONSTRAINTS');
END LOOP;
END;