View on GitHub
ejpp
Embedded JSON Database engine for C++11/14
Public Member Functions | List of all members
ejdb::unique_transaction Struct Reference

Defines an exception-safe wrapper around collection::transaction_t with unique ownership. More...

#include <ejdb.hpp>

+ Inheritance diagram for ejdb::unique_transaction:

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_transactionoperator= (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_trelease () noexcept
 Releases ownership of current collection::transaction_t, if any, without terminating its transaction.
 
void start ()
 Starts a transaction. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

ejdb::unique_transaction::unique_transaction ( collection::transaction_t trans)
explicit

Constructs from a collection::transaction_t and starts transaction.

Exceptions
std::system_errorwith an ejdb::errc when the transaction could not be started.
ejdb::unique_transaction::unique_transaction ( unique_transaction &&  other)
noexcept

Move constructor.

Parameters
otherunique_transaction to construct from.

Ensures other neither owns nor is associated with a collection::transaction_t, avoiding erroneous transaction termination.

Member Function Documentation

void ejdb::unique_transaction::abort ( )

Aborts all changes since starting a transaction.

Exceptions
std::system_errorwith std::errc::operation_not_permitted when referenced collection::transaction_t is null.
std::system_errorwith errc::illegal_transaction_state when the transaction has already been terminated.
std::system_errorwith an ejdb::errc when the transaction could not be aborted.
void ejdb::unique_transaction::commit ( )

Commits all changes since starting a transaction.

Exceptions
std::system_errorwith std::errc::operation_not_permitted when referenced collection::transaction_t is null.
std::system_errorwith errc::illegal_transaction_state when the transaction has already been terminated.
std::system_errorwith an ejdb::errc when the transaction could not be committed.
unique_transaction & ejdb::unique_transaction::operator= ( unique_transaction &&  other)

Move assignment.

Parameters
otherunique_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.

Exceptions
whateverabort() may throw.
void ejdb::unique_transaction::start ( )

Starts a transaction.

Exceptions
std::system_errorwith std::errc::operation_not_permitted when referenced collection::transaction_t is null.
std::system_errorwith errc::illegal_transaction_state when the transaction has already been started.
std::system_errorwith an ejdb::errc when the transaction could not be started.

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