Context transactions and save points

3
Can someone explain to me in detail what the behavior of a savepoint is? The API docs state that when calling startTransaction(), a savepoint will be added when a transaction has already been started. When calling endTransaction(), a savepoint will be removed from the queue if the transaction is nested. What does this mean exactly? What can a savepoint do for me? What does a rollback do with respect to savepoints? ...
asked
1 answers
6

A (database) transaction rollback always rollback to the latest added save point. Let's say you do the following:

  • create a object x (database insert)
  • adds a savepoint
  • create a object y (another database insert)
  • rollback (can be caused by unhandled error or called manually)

Then only the create of y (the corresponding database insert) will be rolled back. Without a save point everything will be rolled back to the start in this case.

Personally I never use save points, but I use (totally) seperate transactions instead for heavy batch processing. Say you want to execute a big microflow for each of a set of 500-objects. Default behaviour is that when processing object 499 fails, everything will be rolled back (because there are no save points added). By adding and removing save points you are nesting transactions and you can manage to where there will be roll-backed (this is also possible within your microflow editor by setting error handling).

Nesting with save points means that everything is still one database transaction on top level. And that means that for long during microflows you are creating (unnecessary) database locks and load on your database server and DBMS.

Because of that I mostly use totally separate transactions for each object. That can be done within a Java action by this.createContext(). On the newly created context object you can use startTransaction() and pass that IContext object to your processing microflow or code.

answered