For one of the projects I'm working on, I need the rollbackTransaction function available on the context object, available here: rollbackTransaction function .
What I expect the function to do:
Code used for java actions: startTransaction, endTransaction and rollbackTransaction
/** the startTransaction java action implementation */ this.getContext().startTransaction(); /** the endTransactionjava action implementation */ this.getContext().endTransaction(); /** the rollbackTransActionjava action implementation */ this.getContext().rollbackTransAction();
This does not seem to work as expected, whether this is because of understand the function wrong or the implementation not working i’m not sure.
I have created a sample project with the above java actions and a test microflow which is called after clicking the navigation button assigned to it.
Sample project download: https://we.tl/t-IGnDhd7hi0
Thanks in Advance,
Vince van Noort
The rollback works as designed because a rollback is only reverting database commits and is not touching the in-memory attribute-value of NewTestObect. My tests result in these conclusions:
The Rollback is rolling back all database-actions since the last start transaction. Look at the objects ending up in the database, they all have Name ‘test_name’. So: ok.
Removing the Rollback-action, restarting the app, makes the objects in the database get the name ‘test_name_CHANGED’. So far so good.
The only thing that this rollback-action does not do, is reverting the in-memory attribute-value of NewTestObect, That still is ‘test_name_CHANGED’ . That is the source of your confusion.
If you use mendix own rollback action it works. In addition to Tim's answer, mendix rollback function works for objects not yet committed.
If you want to revert a committed object, you could probably use the rollback java action, followed by a database retrieve.
Thank you Tim van Steenbergen and Ramón Frigge for answering my questions so quickly.
The intention is indeed to rollback every action taken since the last endTransaction, and according to Tim’s research, it does this on the database side of things, which is good, because that was what i was looking for. To further explain why i would prefer not to use the rollback function is because i would like a much larger set of objects, not all of the same type to be rollbacked at the same time, without keeping a list of these objects and looping over them.
Next question based on answers:
However, i would also like to revert all in-memory changes made to the objects, any of you aware whether this is possible? (is it possible to set/renew the context, to a new context?).