Manages a single MDBX environment and an optional read-only transaction.
More...
#include <Connection.hpp>
|
| void | initialize () |
| | Initializes the environment and sets up read-only transaction.
|
| |
| void | cleanup (bool use_throw=true) |
| | Safely closes the environment and aborts transaction if needed.
|
| |
| void | db_init () |
| | Initializes MDBX environment and opens a read-only transaction.
|
| |
| void | bind_txn (MDBX_txn *txn) |
| | Registers a transaction for a specific thread.
|
| |
| void | unbind_txn () |
| | Unregisters a transaction for a specific thread.
|
| |
| MDBX_txn * | thread_txn () const |
| | Retrieves the transaction associated with the current thread.
|
| |
| virtual | ~TransactionTracker ()=default |
| |
Manages a single MDBX environment and an optional read-only transaction.
Definition at line 13 of file Connection.hpp.
◆ config_t
◆ Connection() [1/2]
| mdbxc::Connection::Connection |
( |
| ) |
|
|
default |
◆ Connection() [2/2]
| mdbxc::Connection::Connection |
( |
const Config & | config | ) |
|
|
inlineexplicit |
Constructs a connection using the given MDBX configuration.
- Parameters
-
| config | Configuration used to initialize the environment. |
Definition at line 17 of file Connection.ipp.
◆ ~Connection()
| mdbxc::Connection::~Connection |
( |
| ) |
|
|
inline |
Destructor. Closes the MDBX environment and aborts any open transactions.
Definition at line 21 of file Connection.ipp.
◆ begin()
Begins a manual transaction (must be committed or rolled back later).
- Parameters
-
| mode | The transaction mode (default: WRITABLE). |
- Exceptions
-
| MdbxException | if the transaction is already started or if beginning fails. |
| std::logic_error | |
Definition at line 73 of file Connection.ipp.
◆ cleanup()
| void mdbxc::Connection::cleanup |
( |
bool | use_throw = true | ) |
|
|
inlineprivate |
Safely closes the environment and aborts transaction if needed.
- Parameters
-
| use_throw | If true, throw on error; otherwise suppress exceptions. |
Definition at line 127 of file Connection.ipp.
◆ commit()
| void mdbxc::Connection::commit |
( |
| ) |
|
|
inline |
Commits the current manual transaction.
- Exceptions
-
Definition at line 84 of file Connection.ipp.
◆ configure()
| void mdbxc::Connection::configure |
( |
const Config & | config | ) |
|
|
inline |
Sets the MDBX configuration (must be called before connect()).
- Parameters
-
| config | New configuration to apply. |
Definition at line 32 of file Connection.ipp.
◆ connect() [1/2]
| void mdbxc::Connection::connect |
( |
| ) |
|
|
inline |
Connects to the database using the current configuration.
- Exceptions
-
Definition at line 41 of file Connection.ipp.
◆ connect() [2/2]
| void mdbxc::Connection::connect |
( |
const Config & | config | ) |
|
|
inline |
Sets configuration and connects in one step.
- Parameters
-
| config | Configuration to use. |
Definition at line 48 of file Connection.ipp.
◆ create()
| std::shared_ptr< Connection > mdbxc::Connection::create |
( |
const Config & | config | ) |
|
|
inlinestatic |
Creates and connects a new shared Connection instance.
- Parameters
-
| config | Configuration to use for initialization. |
- Returns
- Shared pointer to the created Connection.
Definition at line 26 of file Connection.ipp.
◆ current_txn()
| std::shared_ptr< Transaction > mdbxc::Connection::current_txn |
( |
| ) |
const |
|
inline |
Returns the transaction associated with the current thread.
- Returns
- Shared pointer to the active Transaction or nullptr.
Definition at line 106 of file Connection.ipp.
◆ db_init()
| void mdbxc::Connection::db_init |
( |
| ) |
|
|
inlineprivate |
Initializes MDBX environment and opens a read-only transaction.
Definition at line 137 of file Connection.ipp.
◆ disconnect()
| void mdbxc::Connection::disconnect |
( |
| ) |
|
|
inline |
Disconnects from the MDBX environment and releases resources.
- Exceptions
-
Definition at line 59 of file Connection.ipp.
◆ env_handle()
| MDBX_env * mdbxc::Connection::env_handle |
( |
| ) |
|
|
inlinenoexcept |
Returns the environment handle.
- Returns
- MDBX environment pointer.
Definition at line 112 of file Connection.ipp.
◆ initialize()
| void mdbxc::Connection::initialize |
( |
| ) |
|
|
inlineprivate |
Initializes the environment and sets up read-only transaction.
Definition at line 116 of file Connection.ipp.
◆ is_connected()
| bool mdbxc::Connection::is_connected |
( |
| ) |
const |
|
inline |
Checks whether the environment is currently open.
- Returns
- true if connected, false otherwise.
Definition at line 64 of file Connection.ipp.
◆ rollback()
| void mdbxc::Connection::rollback |
( |
| ) |
|
|
inline |
Rolls back the current manual transaction.
- Exceptions
-
| MdbxException | if no transaction is active or rollback/reset fails. |
Definition at line 95 of file Connection.ipp.
◆ transaction()
Creates a RAII transaction object.
- Parameters
-
- Exceptions
-
- Returns
- Transaction guard managing the MDBX_txn handle.
Definition at line 69 of file Connection.ipp.
◆ BaseTable
◆ Transaction
◆ m_config
◆ m_env
| MDBX_env* mdbxc::Connection::m_env = nullptr |
|
private |
Pointer to the MDBX environment handle.
Definition at line 83 of file Connection.hpp.
◆ m_mdbx_mutex
| std::mutex mdbxc::Connection::m_mdbx_mutex |
|
mutableprivate |
◆ m_transactions
| std::unordered_map<std::thread::id, std::shared_ptr<Transaction> > mdbxc::Connection::m_transactions |
|
private |
The documentation for this class was generated from the following files: