jBPM and Spring

Data Access Object (DAO) Pattern

The Spring jBPM Module makes it fairly easy to interact with the key process entities. Spring support classes make this almost identical to dealing with Hibernate using Hibernate DAOs.

Consider the following example. First, we create a class that includes a JbpmConfiguration in the same way a HibernateDAO would include a SessionFactory.

public class ProcessDAOImpl implements ProcessDAO {

  private JbpmConfiguration configuration;

  public JbpmConfiguration getConfiguration() {
    return this.configuration;
  }

  public void setConfiguration(JbpmConfiguration configuration) {
    this.configuration = configuration;
  }

  ...
}

Next, we create a JbpmTemplate, comparable to the HibernateTemplate class from Spring’s Hibernate DAO support.

private JbpmTemplate getJbpmTemplate() {
  return new JbpmTemplate(this.configuration);
}

Lastly, when we want to access jBPM’s entities, we use a callback pattern, again comparable to Spring’s Hibernate DAO pattern:

public ProcessInstance getProcessInstance(final long processInstanceId) {
  return (ProcessInstance) getJbpmTemplate().execute(new JbpmCallback() {
    public Object doInJbpm(JbpmContext context) throws JbpmException {
      return context.getProcessInstance(processInstanceId);
    }
  });
}

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply