######################################################################################
This document describes the step that need to be performed to upgrade jbpm in JBossESB
######################################################################################

1. Download the target version of jbpm.

2. Copy jars from the above installation directory
Copy lib/jbpm-jpdl.jar, lib/jbpm-identity.jar, lib/jbpm-identity-config.jar to product/services/jbpm/lib/ext

 a) update org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml in jbpm-jpdl.jar:
   <subclass name="org.jbpm.context.exe.variableinstance.StringInstance"
            extends="org.jbpm.context.exe.VariableInstance"
            discriminator-value="S">
    <property name="value" type="text" column="STRINGVALUE_" length="4000"/>
   </subclass>
   Add the the length attribute as shown above.

 b) Update org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml in jbpm-jpdl.jar: 
   <subclass name="org.jbpm.context.exe.variableinstance.HibernateStringInstance"
            extends="org.jbpm.context.exe.VariableInstance"
            discriminator-value="I">
    <any name="value" id-type="string" cascade="save-update">
      <column name="STRINGIDCLASS_" />
      <column name="STRINGVALUE_" length="4000"/>
    </any>
   </subclass>
   Add the the length attribute as shown above.

 c) If the upgrade requires changes to the database scripts in src/main/resouces/jbpm-sql then make
	sure that you diff the files and apply the changes manually. 

	The following tables need to be updated:
	Table					Column
	JBPM_ACTION				EXPRESSION_			Should support varchar(4000) or equivelent to the database in question 
	JBPM_COMMENT			MESSAGE_			Should support varchar(4000) or equivelent to the database in question 
	JBPM_DELEGATION			CLASSNAME_			Should support varchar(4000) or equivelent to the database in question 
	JBPM_DELEGATION			CONFIGURATION_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_EXCEPTIONHANDLER	EXCEPTIONCLASSNAME_	Should support varchar(4000) or equivelent to the database in question 
	JBPM_JOB				EXCEPTION_			Should support varchar(4000) or equivelent to the database in question 
	JBPM_LOG				MESSAGE_			Should support varchar(4000) or equivelent to the database in question 
	JBPM_LOG				EXCEPTION__			Should support varchar(4000) or equivelent to the database in question 
	JBPM_LOG				OLDSTRINGVALUE_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_LOG				NEWSTRINGVALUE_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_MODULEDEFINITION	NAME_				Should support varchar(4000) or equivelent to the database in question 
	JBPM_NODE				DESCRIPTION_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_PROCESSDEFINITION	DESCRIPTION_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_TASK				DESCRIPTION_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_TASK_INSTANCE		DESCRIPTION_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_TRANSITION			DESCRIPTION_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_VARIABLEINSTANCE	STRINGVALUE_		Should support varchar(4000) or equivelent to the database in question 
	JBPM_VARIABLEINSTANCE	STRINGVALUE_		Should support varchar(4000) or equivelent to the database in question 


3. Copy hibernate config
Copy config/hibernate.cfg.hsqldb.xml to product/services/jbpm/src/main/resource/hibernate.cfg.xml

 a) Comment out the JDBC connection properties.

 b) Uncommnet the DataSource property and change the Datasource name to:
    <property name="hibernate.connection.datasource">java:/JbpmDS</property>

 c) Uncomment the JTA transaction properties section:
   <!-- JTA transaction properties (begin) ===
   ==== JTA transaction properties (end) -->
   <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
   <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

 d) Add the following properties:
   <property name="jta.UserTransaction">UserTransaction</property>
   <property name="hibernate.current_session_context_class">jta</property>

 e) Comment out hibernate.hbmd2ddl.auto:
   <!--
    <property name="hibernate.hbm2ddl.auto">create</property>
   --> 

4. Remove jbpm-console.war
Delete product/service/jbpm/src/main/resouces/jbpm-console.war.

5. Copy jsf-console.war
Copy lib/jsf-console.war to product/services/jbpm/src/main/resources

 a) Comment out the following from WEB-INF/web.xml:
 <!--
    <ejb-local-ref>
        <description>
            Link to the local entity bean that implements the scheduler service. Required for
            processes that contain timers.
        </description>
        <ejb-ref-name>ejb/TimerEntityBean</ejb-ref-name>
        <ejb-ref-type>Entity</ejb-ref-type>
        <local-home>org.jbpm.ejb.LocalTimerEntityHome</local-home>
        <local>org.jbpm.ejb.LocalTimerEntity</local>
        <ejb-link>TimerEntityBean</ejb-link>
    </ejb-local-ref>
  -->

 and also the following

  <!-- Job executor launcher
  <listener>
    <description>
      Starts the job executor on servlet context initialization and stops it on servlet context destruction.
    </description>
    <listener-class>org.jbpm.web.JobExecutorLauncher</listener-class>
  </listener> Job executor launcher

  <listener>
    <description>
            Closes the jBPM configuration on servlet context destruction, releasing
            application resources. This listener should appear after the job executor
            launcher to avoid reopening the configuration.
        </description>
    <listener-class>org.jbpm.web.JbpmConfigurationCloser</listener-class>
  </listener> -->

 b) Comment out the following from WEB-INF/jboss-web.xml:
 <!--
  <ejb-ref>
    <ejb-ref-name>ejb/TimerEntityBean</ejb-ref-name>
    <jndi-name>java:ejb/TimerEntityBean</jndi-name>
  </ejb-ref>
  -->

6. Update src/test/resources/hibernate.cfg.xml
Copy config/hibernate.cfg.hsqldb.xml to product/services/jbpm/src/test/resource/hibernate.cfg.xml. 


7. Run through the integration tests
From the root directory in the jbossesb project:
ant -f integration-build.xml integration


8. Going through and runing the bpm_orchestration quickstart is also recommened.
ant deploy
ant deployProcess
ant startProcess

9. Vefify that you can login to the jbpm-console
Point you browser to http://localhost:8080/jbpm-console














