25#ifndef FBCPP_TRANSACTION_H
26#define FBCPP_TRANSACTION_H
28#include "fb-cpp-export.h"
127 const std::vector<std::uint8_t>&
getTpb()
const
148 tpb = std::move(value);
157 return isolationLevel;
165 isolationLevel = value;
174 return readCommittedMode;
182 readCommittedMode = value;
261 return restartRequests;
269 restartRequests = value;
291 std::vector<std::uint8_t> tpb;
292 std::optional<TransactionIsolationLevel> isolationLevel;
293 std::optional<TransactionReadCommittedMode> readCommittedMode;
294 std::optional<TransactionAccessMode> accessMode;
295 std::optional<TransactionWaitMode> waitMode;
296 bool noAutoUndo =
false;
297 bool ignoreLimbo =
false;
298 bool restartRequests =
false;
299 bool autoCommit =
false;
376 std::span<std::reference_wrapper<Attachment>> attachments,
const TransactionOptions& options = {});
384 handle{std::move(o.handle)},
386 isMultiDatabase{o.isMultiDatabase}
388 o.state = TransactionState::ROLLED_BACK;
391 Transaction& operator=(Transaction&&) =
delete;
393 Transaction(
const Transaction&) =
delete;
394 Transaction& operator=(
const Transaction&) =
delete;
406 assert(state != TransactionState::PREPARED &&
407 "Prepared transaction must be explicitly committed or rolled back");
411 if (state == TransactionState::ACTIVE)
427 return handle !=
nullptr;
459 void prepare(std::string_view message);
466 void prepare(std::span<const std::uint8_t> message);
480 void commitRetaining();
494 void rollbackRetaining();
500 const bool isMultiDatabase =
false;
Represents a connection to a Firebird database.
Represents a Firebird client library instance.
Reference-counted smart pointer for Firebird objects using addRef/release semantics.
Represents options used when creating a Transaction object.
bool getAutoCommit() const
Returns whether the transaction will be automatically committed.
const std::vector< std::uint8_t > & getTpb() const
Returns the TPB (Transaction Parameter Block) which will be used to start the transaction.
TransactionOptions & setWaitMode(TransactionWaitMode value)
Sets the transaction wait mode.
TransactionOptions & setTpb(std::vector< std::uint8_t > &&value)
Sets the TPB (Transaction Parameter Block) which will be used to start the transaction.
bool getRestartRequests() const
Returns whether the transaction will restart requests.
const std::optional< TransactionAccessMode > getAccessMode() const
Returns the transaction access mode.
bool getNoAutoUndo() const
Returns whether the transaction will not automatically undo changes in case of a deadlock or update c...
bool getIgnoreLimbo() const
Returns whether the transaction will ignore limbo transactions.
const std::optional< TransactionIsolationLevel > getIsolationLevel() const
Returns the transaction isolation level.
const std::optional< TransactionReadCommittedMode > getReadCommittedMode() const
Returns the read committed mode.
TransactionOptions & setAccessMode(TransactionAccessMode value)
Sets the transaction access mode.
TransactionOptions & setTpb(const std::vector< std::uint8_t > &value)
Sets the TPB (Transaction Parameter Block) which will be used to start the transaction.
TransactionOptions & setReadCommittedMode(TransactionReadCommittedMode value)
Sets the read committed mode.
TransactionOptions & setNoAutoUndo(bool value)
Sets whether the transaction will not automatically undo changes in case of a deadlock or update conf...
TransactionOptions & setIsolationLevel(TransactionIsolationLevel value)
Sets the transaction isolation level.
TransactionOptions & setAutoCommit(bool value)
Sets whether the transaction will be automatically committed.
const std::optional< TransactionWaitMode > getWaitMode() const
Returns the transaction wait mode.
TransactionOptions & setIgnoreLimbo(bool value)
Sets whether the transaction will ignore limbo transactions.
TransactionOptions & setRestartRequests(bool value)
Sets whether the transaction will restart requests.
Represents a transaction in one or more Firebird databases.
Transaction(Transaction &&o) noexcept
Move constructor.
~Transaction() noexcept
Rolls back the transaction if it is still active.
TransactionState getState() const noexcept
Returns the current transaction state.
bool isValid() noexcept
Returns whether the Transaction object is valid.
FbRef< fb::ITransaction > getHandle() noexcept
Returns the internal Firebird ITransaction handle.
TransactionState
Transaction state for tracking two-phase commit lifecycle.
@ ACTIVE
Transaction is active and can execute statements.
@ COMMITTED
Transaction has been committed.
@ PREPARED
Transaction has been prepared (2PC phase 1).
@ ROLLED_BACK
Transaction has been rolled back.
TransactionAccessMode
Transaction access mode.
TransactionReadCommittedMode
Transaction read committed mode.
@ NO_RECORD_VERSION
Does not allow reading of record versions; waits for or errors on uncommitted changes.
@ RECORD_VERSION
Allows reading of the latest committed version of a record.
@ READ_ONLY
Read-only replica.
@ READ_WRITE
Read-write replica.
TransactionIsolationLevel
Transaction isolation level.
@ READ_COMMITTED
Allows reading of committed changes from other transactions.
@ SNAPSHOT
Provides a stable snapshot of the database at transaction start time.
@ CONSISTENCY
Ensures full transaction consistency at the expense of concurrency.
TransactionWaitMode
Transaction wait mode.
@ WAIT
Transaction waits until a conflicting lock is released.
@ NO_WAIT
Transaction returns an error immediately if a lock conflict occurs.