|
fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
|
Represents a transaction in one or more Firebird databases. More...
#include <Transaction.h>
Public Member Functions | |
| Transaction (Attachment &attachment, const TransactionOptions &options={}) | |
| Constructs a Transaction object that starts a transaction in the specified Attachment using the specified options. | |
| Transaction (Attachment &attachment, std::string_view setTransactionCmd) | |
Constructs a Transaction object that starts a transaction specified by a SET TRANSACTION command. | |
| Transaction (std::span< std::reference_wrapper< Attachment > > attachments, const TransactionOptions &options={}) | |
| Constructs a Transaction object that starts a multi-database transaction across the specified Attachments using the specified options. | |
| Transaction (Transaction &&o) noexcept | |
| Move constructor. | |
| Transaction & | operator= (Transaction &&)=delete |
| Transaction (const Transaction &)=delete | |
| Transaction & | operator= (const Transaction &)=delete |
| ~Transaction () noexcept | |
| Rolls back the transaction if it is still active. | |
| bool | isValid () noexcept |
| Returns whether the Transaction object is valid. | |
| FbRef< fb::ITransaction > | getHandle () noexcept |
| Returns the internal Firebird ITransaction handle. | |
| TransactionState | getState () const noexcept |
| Returns the current transaction state. | |
| void | prepare () |
| Prepares the transaction for two-phase commit (2PC phase 1). | |
| void | prepare (std::string_view message) |
| Prepares the transaction for two-phase commit with a text message identifier. | |
| void | prepare (std::span< const std::uint8_t > message) |
| Prepares the transaction for two-phase commit with a binary message identifier. | |
| void | commit () |
| Commits the transaction. | |
| void | commitRetaining () |
| Commits the transaction while maintains it active. | |
| void | rollback () |
| Rolls back the transaction. | |
| void | rollbackRetaining () |
| Rolls back the transaction while maintains it active. | |
Represents a transaction in one or more Firebird databases.
Single-database transactions are created using the Attachment constructor. Multi-database transactions are created using the vector of Attachments constructor and support two-phase commit (2PC) protocol via the prepare() method.
For 2PC:
Important: Prepared transactions MUST be explicitly committed or rolled back. The destructor will NOT automatically rollback prepared transactions.
The Transaction must exist and remain valid while there are other objects using it, such as Statement. If a Transaction object is destroyed before being committed or rolled back (and not prepared), it will be automatically rolled back.
Definition at line 350 of file Transaction.h.
|
explicit |
Constructs a Transaction object that starts a transaction in the specified Attachment using the specified options.
Definition at line 135 of file Transaction.cpp.
|
explicit |
Constructs a Transaction object that starts a transaction specified by a SET TRANSACTION command.
Definition at line 152 of file Transaction.cpp.
|
explicit |
Constructs a Transaction object that starts a multi-database transaction across the specified Attachments using the specified options.
All attachments must use the same Client. The same TransactionOptions (TPB) will be applied to all databases.
This constructor enables two-phase commit (2PC) support via the prepare() method.
Definition at line 165 of file Transaction.cpp.
|
inlinenoexcept |
Move constructor.
A moved Transaction object becomes invalid.
Definition at line 381 of file Transaction.h.
|
inlinenoexcept |
Rolls back the transaction if it is still active.
Prepared transactions are NOT automatically rolled back and must be explicitly committed or rolled back before destruction.
Definition at line 401 of file Transaction.h.
| void Transaction::commit | ( | ) |
Commits the transaction.
Can be called from ACTIVE or PREPARED state.
Definition at line 214 of file Transaction.cpp.
| void Transaction::commitRetaining | ( | ) |
Commits the transaction while maintains it active.
Cannot be called on a prepared transaction.
Definition at line 227 of file Transaction.cpp.
|
inlinenoexcept |
Returns the internal Firebird ITransaction handle.
Definition at line 432 of file Transaction.h.
|
inlinenoexcept |
Returns the current transaction state.
Definition at line 440 of file Transaction.h.
|
inlinenoexcept |
Returns whether the Transaction object is valid.
Definition at line 424 of file Transaction.h.
| void Transaction::prepare | ( | ) |
Prepares the transaction for two-phase commit (2PC phase 1).
After prepare() is called, the transaction must be explicitly committed or rolled back. The destructor will NOT automatically rollback prepared transactions.
Definition at line 249 of file Transaction.cpp.
| void Transaction::prepare | ( | std::span< const std::uint8_t > | message | ) |
Prepares the transaction for two-phase commit with a binary message identifier.
The message can be used to identify the transaction during recovery operations.
Definition at line 254 of file Transaction.cpp.
| void Transaction::prepare | ( | std::string_view | message | ) |
Prepares the transaction for two-phase commit with a text message identifier.
The message can be used to identify the transaction during recovery operations.
Definition at line 266 of file Transaction.cpp.
| void Transaction::rollback | ( | ) |
Rolls back the transaction.
Can be called from ACTIVE or PREPARED state.
Definition at line 201 of file Transaction.cpp.
| void Transaction::rollbackRetaining | ( | ) |
Rolls back the transaction while maintains it active.
Cannot be called on a prepared transaction.
Definition at line 238 of file Transaction.cpp.