How to perform a Database commit from MF

3
In our app we use a scheduled event to import complex XML messages. All messages that are delivered to the system within a timeframe of 5 minutes are imported in one batch. In some cases this concerns more then 50 messages. Processing one messages takes approximately 10 to 30 seconds and every message is committed (without events) from within the MF. The problem is that users get to see the imported messages when the schedules events processed the last message in the batch. In some cases user have to wait more then 30 minutes before messages become visible to them. It looks like the Microflow commit only posts data to the database and the actual database commit is executed when the (master) microflow has finished. Is there a way to perform a "database commit" from Microflow?
asked
3 answers
4

This is because the entire microflow is performed within one transaction.

If you want to prematurely commit it to the database, you should call

 endTransaction();

on the current Context. This can be done from a Java Action. After that you need to start another transaction.

Please note though, that this is dangerous stuff you're playing with and that we cannot guarantee that it'll work.

answered
3

You need java actions to achieve this behavior. In Java you can start seperate transactions and commit them right away:

for(IMendixObject obj : allyourobjects) {
  IContext newContext = this.getContext().getSession().getContext(); //eventually: .getSudoContext(); 
  newContext.startTransaction();    
  //do some stuff with newContext, you can even invoke a microflow here
  newContext.endTransaction(); 
}
answered
1

Is it an idea for a future release of the Mendix modeler to create 2 new MF actiontypes "startTransaction" and "endTransaction" to give the programmer/modeler more control over the transactionscope?

answered