Start a transaction, execute Goal and terminate the
transaction. Only if Goal succeeds, the transaction is
commited. If Goal fails or raises an exception, the
transaction is aborted and
bdb_transaction/1 either
fails or rethrows the exception. Of special interest is the exception
error(package(db, deadlock), _)
This exception indicates a deadlock was raised by one of the DB
predicates. Deadlocks may arise if multiple processes or threads access
the same keys in a different order. The DB infra-structure causes one of
the processes involved in the deadlock to abort its transaction. This
process may choose to restart the transaction.
For example, a DB application may define {Goal}
to
realise transactions and restart these automatically is a deadlock is
raised:
{Goal} :-
catch(bdb_transaction(Goal), E, true),
( var(E)
-> true
; E = error(package(db, deadlock), _)
-> {Goal}
; throw(E)
).
Environment | defines the environment to which
the transaction applies. If omitted, the default environment is used.
See bdb_init/1 and bdb_init/2. |