MDBX Containers
Loading...
Searching...
No Matches
mdbxc::Transaction Class Reference

Manages MDBX transactions with automatic cleanup and error handling. More...

#include <Transaction.hpp>

Public Member Functions

virtual ~Transaction ()
 Destructor that safely closes or resets the transaction.
 
void begin ()
 Starts the transaction.
 
void commit ()
 Commits the transaction.
 
void rollback ()
 Rolls back the transaction.
 
MDBX_txn * handle () const noexcept
 Returns the internal MDBX transaction handle.
 
 Transaction (TransactionTracker *registry, MDBX_env *env, TransactionMode mode)
 Constructs a new transaction object.
 
 Transaction (Transaction &&) noexcept=default
 
Transactionoperator= (Transaction &&) noexcept=default
 

Private Member Functions

 Transaction (const Transaction &)=delete
 
Transactionoperator= (const Transaction &)=delete
 

Private Attributes

TransactionTrackerm_registry = nullptr
 
MDBX_env * m_env = nullptr
 Pointer to the MDBX environment handle.
 
MDBX_txn * m_txn = nullptr
 MDBX transaction handle.
 
TransactionMode m_mode
 Current transaction mode.
 
bool m_started = false
 

Friends

class Connection
 

Detailed Description

Manages MDBX transactions with automatic cleanup and error handling.

Supports both read-only and writable modes. Provides methods for beginning, committing, and rolling back transactions, with integration of MDBX-specific behavior.

Definition at line 25 of file Transaction.hpp.

Constructor & Destructor Documentation

◆ ~Transaction()

mdbxc::Transaction::~Transaction ( )
inlinevirtual

Destructor that safely closes or resets the transaction.

If the transaction is still active, read-only transactions are reset (reusable), and writable transactions are aborted.

Definition at line 8 of file Transaction.ipp.

◆ Transaction() [1/3]

mdbxc::Transaction::Transaction ( TransactionTracker * registry,
MDBX_env * env,
TransactionMode mode )
inline

Constructs a new transaction object.

Parameters
registryTransaction tracker used to associate the transaction with the current thread.
envPointer to the MDBX environment handle.
modeAccess mode of the transaction.

Definition at line 3 of file Transaction.ipp.

◆ Transaction() [2/3]

mdbxc::Transaction::Transaction ( Transaction && )
defaultnoexcept

◆ Transaction() [3/3]

mdbxc::Transaction::Transaction ( const Transaction & )
privatedelete

Member Function Documentation

◆ begin()

void mdbxc::Transaction::begin ( )
inline

Starts the transaction.

For read-only transactions, uses a shared reusable handle and attempts renewal. For writable transactions, begins a new transaction using the MDBX environment.

Exceptions
MdbxExceptionif the transaction is already started or if beginning fails.

Definition at line 15 of file Transaction.ipp.

◆ commit()

void mdbxc::Transaction::commit ( )
inline

Commits the transaction.

For read-only transactions, resets the handle for reuse. For writable transactions, commits the changes and closes the handle.

Exceptions
MdbxExceptionif no transaction is active or commit/reset fails.

Definition at line 27 of file Transaction.ipp.

◆ handle()

MDBX_txn * mdbxc::Transaction::handle ( ) const
inlinenoexcept

Returns the internal MDBX transaction handle.

Returns
Raw pointer to MDBX_txn, or nullptr if not active.

Definition at line 77 of file Transaction.ipp.

◆ operator=() [1/2]

Transaction & mdbxc::Transaction::operator= ( const Transaction & )
privatedelete

◆ operator=() [2/2]

Transaction & mdbxc::Transaction::operator= ( Transaction && )
defaultnoexcept

◆ rollback()

void mdbxc::Transaction::rollback ( )
inline

Rolls back the transaction.

For read-only transactions, resets the handle. For writable transactions, aborts the transaction.

Exceptions
MdbxExceptionif no transaction is active or rollback/reset fails.

Definition at line 52 of file Transaction.ipp.

Friends And Related Symbol Documentation

◆ Connection

friend class Connection
friend

Definition at line 26 of file Transaction.hpp.

Member Data Documentation

◆ m_env

MDBX_env* mdbxc::Transaction::m_env = nullptr
private

Pointer to the MDBX environment handle.

Definition at line 81 of file Transaction.hpp.

◆ m_mode

TransactionMode mdbxc::Transaction::m_mode
private

Current transaction mode.

Definition at line 83 of file Transaction.hpp.

◆ m_registry

TransactionTracker* mdbxc::Transaction::m_registry = nullptr
private

Definition at line 80 of file Transaction.hpp.

◆ m_started

bool mdbxc::Transaction::m_started = false
private

Definition at line 84 of file Transaction.hpp.

◆ m_txn

MDBX_txn* mdbxc::Transaction::m_txn = nullptr
private

MDBX transaction handle.

Definition at line 82 of file Transaction.hpp.


The documentation for this class was generated from the following files: