Use the Explicit Transaction Mechanism in BimRv

Alexey Korolev

July 02, 2020

To modify objects, BimRv now uses an explicit transaction mechanism which allows developers to achieve a persistent database state at any moment and also implement rollback mechanisms. The new mechanism also reduces debugging complexity and eliminates issues for open mode switches.

Using explicit transactions requires a data modification call to be invoked after starting a transaction, otherwise an exception is thrown.

The simplest way to open a transaction is to use a transaction block. Here is a typical sample:

ODBM_TRANSACTION_BEGIN(transaction_name, pointer_to_database)  transaction_name.start();  /* modification calls */  
const bool some_condition = /* whatever condition is required */;  
if (some_condition) {
    transaction_name.commit();
  } else {
    transaction_name.rollback();
  } 
ODBM_TRANSACTION_END()

These are the main points of the code:

  • transaction_name.start(); — Starts a transaction named ‘transaction_name’.
  • transaction_name.commit(); — Commits modifications made during a transaction.
  • transaction_name.rollback(); — Reverses modifications made during a transaction.

Either ‘start’ or ‘rollback’ closes the transaction, and no more modifications can be made. The new explicit transaction mechanism replaces the implicit transaction mechanism that was used in ODA BimRv versions before 20.6.