Strolch Transactions play a central role in a Strolch agent. A transaction is opened for a realm, and grants access to the model of the agent. Transactions are implemented as a Java try-with-resources by implementing the AutoCloseable interface. This makes it trivial to understand the scope of a transaction.

Transactions handle the following:

When a transaction is opened, it is by default read-only, i.e. does not perform any commands when it is closed. Should the TX perform commands, then it is important to call tx.commitOnClose(), but only at the end of the work, so that exception handling can properly work if something goes wrong.

StrolchTransaction offers a myriad of methods:

Transactions are opened by accessing the realm, but there are convenience methods depending on the use-case:

Important is to always open the transaction as a try-with-resource block and to define if the TX should commit, or not:

try (StrolchTransaction tx = openTx(...)) {

  // do work

  // either or:
  tx.doNothingOnClose(); // can also be omitted, as default
  tx.commitOnClose();
}