Adding a Database Axis

    Specify Connection Properties

    Let's add a PostgreSQL axis.

     

    jBPM3 already generates the DDL scripts for many databases. Edit hibernate.properties.postgresql.xml

    <!-- hibernate dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    
    <!-- JDBC connection properties (begin) -->
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.url">${jdbc.postgresql.url}</property>
    <property name="hibernate.connection.username">${jdbc.postgresql.username}</property>
    <property name="hibernate.connection.password">${jdbc.postgresql.password}</property>
    <!-- JDBC connection properties (end) -->
    

    Provide Data Source

    Create jbpm-postgresql-ds.xml in modules/core/src/main/resources. Use ConfigDataSources as a reference.

    <xa-datasource>
      <jndi-name>JbpmDS</jndi-name>
    
      <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
      <xa-datasource-property name="ServerName">${jdbc.postgresql.server}</xa-datasource-property>
      <xa-datasource-property name="PortNumber">${jdbc.postgresql.port}</xa-datasource-property>
      <xa-datasource-property name="DatabaseName">${jdbc.postgresql.database}</xa-datasource-property>
      <user-name>${jdbc.postgresql.username}</user-name>
      <password>${jdbc.postgresql.password}</password>
    
      <!-- disable transaction interleaving -->
      <track-connection-by-tx />
    
      <!-- corresponding type-mapping in conf/standardjbosscmp-jdbc.xml -->
      <metadata>
        <type-mapping>PostgreSQL 8.0</type-mapping>
      </metadata>
    </xa-datasource>
    

    Create Maven Profile

    In the root POM add a profile that contains the dependency on the JDBC driver

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>postgresql</groupId>
          <artifactId>postgresql</artifactId>
          <version>${postgresql.version}</version>
        </dependency>
      </dependencies>
    </dependencyManagement>
    
    <profiles>
      <profile>
        <id>postgresql</id>
        <activation>
          <property>
            <name>database</name>
            <value>postgresql</value>
          </property>
        </activation>
        <dependencies>
          <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>test</scope>
          </dependency>
        </dependencies>
      </profile>
    </profiles>
    

    Fill in Connection Parameters

    Specify the connection property values that correspond to the target environment in the following locations.

     

    EnvironmentFileLocation
    jBPM Devprofiles.xml${basedir}
    Local Dev *settings.xml${user.home}/.m2
    Local QAprofiles.xml.local.qa${basedir}/hudson
    Red Hat QAprofiles.xml.redhat.qa${basedir}/hudson

    * Useful if you have multiple jBPM branches checked out

     

    For a local PostgreSQL installation the property values would look like this:

    <properties>
      <jdbc.postgresql.server>localhost</jdbc.postgresql.server>
      <jdbc.postgresql.port>5432</jdbc.postgresql.port>
      <jdbc.postgresql.database>jbpmtest</jdbc.postgresql.database>
      <jdbc.postgresql.url>jdbc:postgresql://${jdbc.postgresql.server}:${jdbc.postgresql.port}/${jdbc.postgresql.database}</jdbc.postgresql.url>
      <jdbc.postgresql.username>jbpmtest</jdbc.postgresql.username>
      <jdbc.postgresql.password></jdbc.postgresql.password>
    </properties>
    

    Specify Connection Properties For Update

    Generating the DB schema update script requires access to an alternate database hosting the schema from a previous version. Create postgresql.properties in modules/db/src/main/resources.

    hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
    #
    # This uses the jbpm322 database schema as reference for the SchemaUpdate task
    #
    hibernate.connection.driver_class=org.postgresql.Driver
    hibernate.connection.url=jdbc:postgresql://${jdbc.postgresql.server}:${jdbc.postgresql.port}/jbpm322
    hibernate.connection.username=${jdbc.postgresql.username}
    hibernate.connection.password=${jdbc.postgresql.password}
    

    antrun-jbpmschema.xml

    <target name="update-schema" depends="setup-schema" description="Generate jBPM Database Update Scripts">
      <jbpmschema output="${scriptsdir}/jbpm.jpdl.postgresql.update322.sql" config="hibernate.cfg.postgresql.xml" properties="postgresql.properties" action="update" delimiter=";"/>
    </target>
    

    List Database as Installation Choice

    install-definition.xml

    <conditions>
      <condition type="variable" id="isPostgreSQL">
        <name>dbSelection</name>
        <value>postgresql</value>
      </condition>
    </conditions>
    
    <packs>
      <!-- 
      ********************************
      *   JBoss Integration          *
      ********************************
      -->
      <pack name="jBPM3 JBoss Integration" required="no" preselected="yes">
        <!-- Database configs to docs/examples/jbpm -->
        <fileset dir="@{deploy.artifacts.dir}/resources/jbpm-jpdl-config" targetdir="${jbossInstallPath}/docs/examples/jbpm" override="true">
          <include name="hibernate.cfg.postgresql.xml"/>
          <include name="jbpm-postgresql-ds.xml"/>
        </fileset>
        <!-- Database PostgreSQL -->
        <file src="@{deploy.artifacts.dir}/resources/jbpm-jpdl-config/jbpm-postgresql-ds.xml" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/jbpm"  condition="isPostgreSQL"/>
        <singlefile src="@{deploy.artifacts.dir}/resources/jbpm-jpdl-config/hibernate.cfg.postgresql.xml" condition="isPostgreSQL" 
          target="${jbossInstallPath}/server/${jbossTargetServer}/deploy/jbpm/jbpm-service.sar/hibernate.cfg.xml" />
        <fileset dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/jbpm/jbpm-service.sar" override="true" condition="isPostgreSQL">
          <include name="postgresql.jar" />
        </fileset>
      </pack>
    </packs>
    

    user-input-spec.xml

    <panel order="2">
      <createForPack name="jBPM3 JBoss Integration" />
      <field type="radio" variable="dbSelection">
        <spec>
          <choice txt="PostgreSQL" value="postgresql"/>
        </spec>
      </field>
    </panel>
    

    antrun-installer.xml

    <target name="configure" depends="init">
      <property name="postgresql.cfg.xml" value="${deploy.artifacts.resources}/jbpm-jpdl-config/hibernate.cfg.postgresql.xml"/>
      <macro-disable file="${postgresql.cfg.xml}" section="JDBC connection properties"/>
      <macro-disable file="${postgresql.cfg.xml}" section="Automatic schema creation"/>
      <macro-enable file="${postgresql.cfg.xml}" section="DataSource properties"/>
      <macro-enable file="${postgresql.cfg.xml}" section="JTA transaction properties"/>
    </target>
    

    Set Up DBMS

    See Install PostgreSQL on Fedora

    Run Test Suite

    Finally you should be able to run the jBPM3 tests against PostgreSQL using the -Ddatabase option

    [tdiesler@tddell core]$ mvn -Ddatabase=postgresql -Dtest=EndTasksDbTest test
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building JBoss jBPM - jPDL Core
    [INFO]    task-segment: [test]
    [INFO] ------------------------------------------------------------------------
    [INFO] [antrun:run {execution: default}]
    [INFO] Executing tasks
    
    check-database:
    
         [echo] Concat hibernate.cfg.xml using hibernate.properties.postgresql.xml
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running org.jbpm.taskmgmt.exe.EndTasksDbTest
    Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 25.799 sec
    
    Results :
    
    Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
    

    Add Database Axis To Hudson Jobs

    When the Maven build is setup to use the database for testing, you simple need to add the axis to the Hudson config.

    <axis>
      <name>database</name>
      <values>
        <string>hsqldb</string>
        <string>mysql</string>
        <string>postgresql</string>
      </values>
    </axis>
    

    This can also be done from the web interface.

     

    Good Luck