Provides RAII wrapper for an active database transaction on the current thread (do not use across threads). A Transaction object is considered a "top level transaction" if it is the first one on the call stack in the thread. If the thread already has an ongoing Transaction, additional Transaction instances are considered "inner transactions". More...
#include <objectbox.hpp>
Public Member Functions | |
Transaction (Store &store, TxMode mode) | |
Transaction (const Transaction &)=delete | |
Delete because the default copy constructor can break things (i.e. a Transaction can not be copied). More... | |
Transaction (Transaction &&source) noexcept | |
Move constructor, used by Store::tx() More... | |
Transaction & | operator= (Transaction source) |
Copy-and-swap style. More... | |
virtual | ~Transaction () |
Never throws. More... | |
bool | isActive () |
A Transaction is active if it was not ended via success(), close() or moving. More... | |
OBX_txn * | cPtr () const |
The transaction pointer of the ObjectBox C API. More... | |
void | success () |
"Finishes" this write transaction successfully; performs a commit if this is the top level transaction and all inner transactions (if any) were also successful. This object will also be "closed". More... | |
obx_err | closeNoThrow () |
Explicit close to free up resources (non-throwing version). It's OK to call this method multiple times; additional calls will have no effect. More... | |
void | close () |
Explicit close to free up resources; unlike closeNoThrow() (which is also called by the destructor), this version throw in the unlikely case of failing. It's OK to call this method multiple times; additional calls will have no effect. More... | |
uint64_t | getDataSizeCommitted () const |
The data size of the committed state (not updated for this transaction). More... | |
int64_t | getDataSizeChange () const |
Cumulative change (delta) of data size by this pending transaction (uncommitted). More... | |
Provides RAII wrapper for an active database transaction on the current thread (do not use across threads). A Transaction object is considered a "top level transaction" if it is the first one on the call stack in the thread. If the thread already has an ongoing Transaction, additional Transaction instances are considered "inner transactions".
The top level transaction defines the actual transaction scope on the DB level. Internally, the top level Transaction object manages (creates and destroys) a Transaction object. Inner transactions use the Transaction object of the top level Transaction.
For write transactions, the top level call to success() actually commits the underlying Transaction. If inner transactions are spawned, all of them must call success() in order for the top level transaction to be successful and actually commit.
|
delete |
Delete because the default copy constructor can break things (i.e. a Transaction can not be copied).
|
inlinenoexcept |
Move constructor, used by Store::tx()
|
inlinevirtual |
Never throws.
void obx::Transaction::close | ( | ) |
Explicit close to free up resources; unlike closeNoThrow() (which is also called by the destructor), this version throw in the unlikely case of failing. It's OK to call this method multiple times; additional calls will have no effect.
obx_err obx::Transaction::closeNoThrow | ( | ) |
Explicit close to free up resources (non-throwing version). It's OK to call this method multiple times; additional calls will have no effect.
OBX_txn* obx::Transaction::cPtr | ( | ) | const |
The transaction pointer of the ObjectBox C API.
if | this Transaction was already closed or moved |
int64_t obx::Transaction::getDataSizeChange | ( | ) | const |
Cumulative change (delta) of data size by this pending transaction (uncommitted).
uint64_t obx::Transaction::getDataSizeCommitted | ( | ) | const |
The data size of the committed state (not updated for this transaction).
|
inline |
A Transaction is active if it was not ended via success(), close() or moving.
Transaction& obx::Transaction::operator= | ( | Transaction | source | ) |
Copy-and-swap style.
void obx::Transaction::success | ( | ) |