ejpp
Embedded JSON Database engine for C++11/14
|
View on GitHub
Defines an exception-safe wrapper around collection::transaction_t with unique ownership. More...
#include <ejdb.hpp>
Public Member Functions | |
unique_transaction () noexcept=default | |
Default constructor. Does not own a collection::transaction_t. | |
unique_transaction (collection::transaction_t &trans) | |
Constructs from a collection::transaction_t and starts transaction. More... | |
unique_transaction (collection::transaction_t &trans, adopt_transaction_t) noexcept | |
Constructs from a collection::transaction_t and adopts its status. | |
unique_transaction (collection::transaction_t &trans, try_transaction_t) noexcept | |
Constructs from a collection::transaction_t and attempts to start transaction. | |
unique_transaction (unique_transaction &&) noexcept | |
Move constructor. More... | |
void | abort () |
Aborts all changes since starting a transaction. More... | |
void | commit () |
Commits all changes since starting a transaction. More... | |
operator bool () const noexcept | |
Returns whether or not a collection::transaction_t is currently owned and has a transaction in progress. | |
unique_transaction & | operator= (unique_transaction &&) |
Move assignment. More... | |
bool | owns_transaction () const noexcept |
Returns whether or not a collection::transaction_t is currently owned and has a transaction in progress. | |
collection::transaction_t * | release () noexcept |
Releases ownership of current collection::transaction_t, if any, without terminating its transaction. | |
void | start () |
Starts a transaction. More... | |
Defines an exception-safe wrapper around collection::transaction_t with unique ownership.
Uses RAII to allow safe usage of a collection::transaction_t in the presence of exceptions. When a collection::transaction_t is owned, the destructor aborts transaction when an exception is thrown, otherwise commits.
The parent db object is guaranteed to remain alive throughout the lifetime of a unique_transaction.
The parent collection object must stay alive at least as long as a unique_transaction when it owns or contains a collection::transaction_t.
|
explicit |
Constructs from a collection::transaction_t and starts transaction.
std::system_error | with an ejdb::errc when the transaction could not be started. |
|
noexcept |
Move constructor.
other | unique_transaction to construct from. |
Ensures other
neither owns nor is associated with a collection::transaction_t, avoiding erroneous transaction termination.
void ejdb::unique_transaction::abort | ( | ) |
Aborts all changes since starting a transaction.
std::system_error | with std::errc::operation_not_permitted when referenced collection::transaction_t is null. |
std::system_error | with errc::illegal_transaction_state when the transaction has already been terminated. |
std::system_error | with an ejdb::errc when the transaction could not be aborted. |
void ejdb::unique_transaction::commit | ( | ) |
Commits all changes since starting a transaction.
std::system_error | with std::errc::operation_not_permitted when referenced collection::transaction_t is null. |
std::system_error | with errc::illegal_transaction_state when the transaction has already been terminated. |
std::system_error | with an ejdb::errc when the transaction could not be committed. |
unique_transaction & ejdb::unique_transaction::operator= | ( | unique_transaction && | other | ) |
Move assignment.
other | unique_transaction to assign from. |
Aborts current transaction if one is owned.
Ensures other
neither owns nor is associated with a collection::transaction_t, avoiding erroneous transaction termination.
whatever | abort() may throw. |
void ejdb::unique_transaction::start | ( | ) |
Starts a transaction.
std::system_error | with std::errc::operation_not_permitted when referenced collection::transaction_t is null. |
std::system_error | with errc::illegal_transaction_state when the transaction has already been started. |
std::system_error | with an ejdb::errc when the transaction could not be started. |