cancel
Showing results for 
Search instead for 
Did you mean: 

Migrating example source code from the Manning book

jemmerling
Champ in-the-making
Champ in-the-making
If anyone is interested, I migrated the source code examples from the Manning book to the latest version of Activiti (5.17.0).

First thing to be aware of is the installation process described in the book has been phased out, see http://bpmn20inaction.blogspot.nl/2013/02/activiti-in-action-updates-part-1.html.

This is for the bpmn-examples project only (for now).

Then some modification to the POM. Activiti and Spring must both be upgraded:

      <activiti-version>5.17.0</activiti-version>
      <spring-version>4.0.6.RELEASE</spring-version>

Also this <pluginManagement/> tag must be added. I don't know enough about Maven to know why:
  <build>
     <pluginManagement>
    <plugins>

I commented out everything other than the class declaration for the ProcessInitiator example for Chapter 9, as the Spring Annotations have been discontinued and this example would seem to longer serve any useful purpose.

In the LDAP example (Chapter 10) there were some API changes. GroupManager becomes GroupEntityManager.

   @Override
   public List<Group> findGroupByQueryCriteria(GroupQueryImpl query, Page page)/* {
      // TODO Auto-generated method stub
      return super.findGroupByQueryCriteria(query, page);
   }

   @Override
  public List<Group> findGroupByQueryCriteria(Object query, Page page)*/ {

This method went away (not that it was exactly doing anything to begin with:

   /*@Override

  public GroupEntity findGroupById(String groupId) {
      throw new ActivitiException("LDAP group manager doesn't support finding a group by id");
  }*/

To populate the Activiti schema in H2 I used the DbSchemaCreate program. I suppose the old ANT script took care of this.

The default URL for separately installed H2 is
jdbc:h2:~/test
. The book example expects
jdbc:h2:tcp://localhost/~/activiti
. I suppose the ANT script took care of that. So there is an activiti.cfg.xml in which you can change the URL but that is for Spring to use, and the BookOrderTest class doesn't seem to use Spring for this. Instead, the URL is hardcoded (I found where but don't remember now). So the get the test to use the correct URL I added a line to change the URL after the fact:

      ProcessEngineConfiguration config = ProcessEngineConfiguration
            .createStandaloneProcessEngineConfiguration();
      config.setJdbcUrl("jdbc:h2:~/test");
      ProcessEngine processEngine = /*ProcessEngineConfiguration
         .createStandaloneProcessEngineConfiguration()*/
      config
          .buildProcessEngine();

After that I was able to get the BookOrderTest to work.

If anybody wants me to upload my modified workspace (actually just the bpmn-examples project) I would be happy to oblige. All advice is welcome.

Thanks to Tijs and Joram for the help they gave me!

–John Emmerling

4 REPLIES 4

jemmerling
Champ in-the-making
Champ in-the-making
Some updates having to do with database access. First I must confess I don't understand everything that is going on.

So the Activiti Explorer has a db.properties containing the following:

jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000.

This implies an in-memory database. For the examples in the book to work i.e. the Book Order example in Chapter 1, it seems it should be using the stand-alone H2 instance as called for in the book.

Another thing I noticed is that in my home directory there was a couple of H2 database files including one named activiti.h2.db. I'm not certain how that got created (would an in-memory instance do that?). Also, when the Explorer launches it tries to create a new Activiti schema which makes sense for an in-memory database.

What I changed was to get everything to use the following URL: jdbc:h2:~/activiti this includes the Explorer and the Manning book example code. I was finally able to get the example to work! I can now see the new task in the Explorer. It did seem rather slow showing up, though.

However under the circumstances I am not convinced that if I were to bounce Tomcat there would not be a problem because some of my experimentation indicated it was failing startup due to trying to create a new schema instance where one already exists. Which makes sense for an in-memory H2 instance but not for a stand-alone instance, however the example in the book seems to require a stand-alone instance.

Just wondering if anybody has further insight?

jbarrez
Star Contributor
Star Contributor
The book assumes an H2 database exposed to TCP I would assume.
This is an in memory database, but persistent in a file, so it would survive a reboot.

jemmerling
Champ in-the-making
Champ in-the-making
1.) Can an in-memory H2 instance be accessed from a different JVM e.g. the Explorer data being accessed by the JUnit tests in the Manning book sample code? As that is needed for the examples to work.
2.) If the data is persisted between sessions then won't there still be a problem when Tomcat is bounced because the Explorer will try to recreate the schema from scratch?

Thanks!

–John Emmerling

jbarrez
Star Contributor
Star Contributor
1. Yes, if you set up the H2 db with the TCP interface

2. No, there is a check in Activiti that checks if the schema is correct. Unless you mean something else with 'bounced'?