Library Version 12.1.6.2

Chapter 13. The DbTxn Handle
Prev |  | Next

## Chapter 13. The DbTxn Handle

    #include <db_cxx.h>

    class DbTxn {
    public:
        DB_TXN *DbTxn::get_DB_TXN();
        const DB_TXN *DbTxn::get_const_DB_TXN() const;
        static DbTxn *DbTxn::get_DbTxn(DB_TXN *txn);
        static const DbTxn *DbTxn::get_const_DbTxn(const DB_TXN *txn);
        ...

    };

The `DbTxn` object is the handle for a transaction. Methods of the `DbTxn` handle are used to configure, abort and commit the transaction. `DbTxn` handles are provided to Db methods in order to transactionally protect those database operations.

`DbTxn` handles are not free-threaded; transactions handles may be used by multiple threads, but only serially, that is, the application must serialize access to the `DbTxn` handle. Once the DbTxn::abort() or DbTxn::commit() methods are called, the handle may not be accessed again, regardless of the method's return. In addition, parent transactions may not issue any Berkeley DB operations while they have active child transactions (child transactions that have not yet been committed or aborted) except for DbEnv::txn_begin(), DbTxn::abort() and DbTxn::commit().

Each `DbTxn` object has an associated `DB_TXN` struct, which is used by the underlying implementation of Berkeley DB and its C++ language API. The `DbTxn::get_DB_TXN()` method returns a pointer to this struct. Given a const `DbTxn` object, `txnMget_const_DB_TXN()` returns a const pointer to the same struct.

Given a `DB_TXN` struct, the `DbTxn::get_DbTxn()` method returns the corresponding `DbTxn` object, if there is one. If the `DB_TXN` object was not associated with a `DbTxn` (that is, it was not returned from a call to `DbTxn::get_DB_TXN()`), then the result of `DbTxn::get_DbTxn` is undefined. Given a const `DB_TXN` struct, `DbTxn::get_const_DbTxn()` returns the associated const `DbTxn` object, if there is one.

These methods may be useful for Berkeley DB applications including both C and C++ language software. It should not be necessary to use these calls in a purely C++ application.

## Transaction Subsystem and Related Methods

Transaction Subsystem and Related Methods | Description
--- | ---
DbEnv::txn_recover() | Distributed transaction recovery
DbEnv::txn_checkpoint() | Checkpoint the transaction subsystem
DbEnv::txn_stat() | Return transaction subsystem statistics
DbEnv::txn_stat_print() | Print transaction subsystem statistics
DbTxn::set_timeout() | Set transaction timeout
Transaction Subsystem Configuration
DbEnv::set_timeout(), DbEnv::get_timeout() | Set/get lock and transaction timeout
Db::get_transactional() | Does the Db have transaction support
DbEnv::cdsgroup_begin() | Get a locker ID in Berkeley DB Concurrent Data Store
DbEnv::set_tx_max(), DbEnv::get_tx_max() | Set/get maximum number of transactions
DbEnv::set_tx_timestamp(), DbEnv::get_tx_timestamp() | Set/get recovery timestamp
Transaction Operations
DbEnv::txn_begin() | Begin a transaction
DbTxn::abort() | Abort a transaction
DbTxn::commit() | Commit a transaction
DbTxn::discard() | Discard a prepared but not resolved transaction handle
DbTxn::id() | Return a transaction's ID
DbTxn::prepare() | Prepare a transaction for commit
DbTxn::set_name(), DbTxn::get_name() | Associate a string with a transaction
DbTxn::set_priority(), DbTxn::get_priority() | Set/get transaction's priority

Prev |  | Next
DbSequence::stat_print() | Home | Db::get_transactional()