1
votes

I'm currently working with some business process creation using BPMN with Activiti. For one step in that business process I need to query a database and use that result in subsequent steps. So I'm looking for possible workarounds to integrate SQL operation capabilities to Activiti. So can anyone please suggest me whether is there any way to embed sql query capabilities for the activiti? Any suggestion for external database interaction for BPMN process using Activiti Engine is highly appreciated.

If such solution does not exists, any help on how to implement such feature for activiti also helpful

2
Can you provide more details about your use case? You need to fetch some data from some external database and include it in your workflow (for example show some info so that a manager can make a decision) ?Younes Regaieg
Yes. Ex: Say I'm managing book purchase workflow scenario. I need to query mySQL database to check the availability of the requested book in the stocks. As in that example , actually I need to find a generic way to interact with external databases within BPMN processes. So any suggestion on how to extend the activiti engine for that capabilities will also helpfulAnupama Pathirage
I found following example which matches with my case. link But it is with alfresco activiti commercial version. Is there any way to add that to apache version.Anupama Pathirage

2 Answers

2
votes

You can Setup a Java Service Task as instructed here and implement your custom logic that may or may not include interraction with an external DataBase. Just remember to save the output of your service task to your process variables (execution) in case you need it for further processing (review for example, ...)

Here is a sample BPMN Service task:

   <serviceTask id="javaService"
         name="My Java Service Task"
         activiti:class="org.activiti.MyJavaDelegate" />

And here is a sample implementation for it :

public class ToUppercase implements JavaDelegate {
  public void execute(DelegateExecution execution) throws Exception {
    String var = (String) execution.getVariable("input");
    var = var.toUpperCase();
    execution.setVariable("input", var);
  }
}

Do not forget to manage your DB connection pools, ... etc so that you do not any unnecessary problems in production

EDIT :
I couldn't detect any thing from that blog post your referenced in your comment that may not function correctly in activiti community edition, just remember to make all your custom classes and dependencies available on your classpath.

Note : The post from the blog post is talking about the embedded activiti engine in alfresco (in that case it was Enterprise Edition), but yet again, it should work fine even with the community edition of activiti!

2
votes

Accessing data from an external database is a very common use case for a Service Task. I see others have pointed you in that direction which is pefectly reasonable.

But, there is another option which uses the same database layer that Activiti itself uses. This layer is iBatis and is used for all entity storage within the Database engine.

The user guide does describe how to use iBatis here: http://www.activiti.org/userguide/#advanced.custom.sql.queries

We have used this with great effect at a number of customers.

If however this doesnt satisfy your requirements, then there is always the option of using a custom Java Service class (look at Springs JDBCTemplate - it is very easy to use).

Hope this helps.