cancel
Showing results for 
Search instead for 
Did you mean: 

Data from a table

anjan
Champ in-the-making
Champ in-the-making
Hi, we have integrated our application with Activiti (V 5.17) and we are using Activiti REST for all the tasks (starting the process, adding process variables…etc).

One of the process definitions that we are going to create need to fetch data from a database table.  This data will be same for all the process instances. 

One of the options I thought was adding a Java Service task in the Process Definition that will fetch the necessary data from the table and store the same in a process variable.  But I see two issues with this approach.

1. Since the data is same for all the process instances, I will be calling the database for every process instance that I create, which is not efficient.

2. The data is name/value pairs and I can store this as a Map in Process variable (from Java Service Task).  But this will be stored as a Serializable object in Activiti DB which I will not be able to easily utilize in a step in process (I want to show this data in a drop-down).

Kindly suggest a better approach.
5 REPLIES 5

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Anjan,

There are many possibilities. At least two of them:
  • Spring bean
  • JPA integration
Read activiti doc please.

Regards
Martin

jbarrez
Star Contributor
Star Contributor
1. If the data is the same for all instances, why not add your own cache for it that is used in the service task.
2. In that case, i'd store it as a json string

anjan
Champ in-the-making
Champ in-the-making
Hi Martin, I thought about JPA integration.  But my use case is just a read from the table, so I thought JPA might be an overkill.  But I will think about it.
Joram, caching is a good idea.  Are you suggesting me to add this cache on the JVM where Activiti is running (our application and Activiti are running in a separate JVM)?  If so, can you please throw some light on how to do this.

anjan
Champ in-the-making
Champ in-the-making
Joram, are you suggesting that I can keep the json string as an instance variable in my Java Service Task.  If the variable is not initialized, initialize the same, otherwise re-use it.  Is it advisable to keep instance variable in the Java Service Task.

jbarrez
Star Contributor
Star Contributor
anjan: service tasks are stateless, so you'd have to make it a bit smarter than just a static value, but it all depends on your use case of course.

My comment about json was for the 'storing as Serializable': storing as serializable is not a good idea, hence why i suggested a json representation. However, reading your post, it seems you don't need to have it as a process variable, but some smart caching logic should suffice.