9#include <access/xact.h>
14using command_id = ::CommandId;
24 ffi_guard{acquire ? ::GetCurrentTransactionId : ::GetCurrentTransactionIdIfAny}());
27 bool is_valid()
const {
return TransactionIdIsValid(id_); }
29 bool operator==(
const transaction_id &other)
const {
return TransactionIdEquals(id_, other.id_); }
30 bool operator>(
const transaction_id &other)
const {
return TransactionIdFollows(id_, other.id_); }
32 return TransactionIdFollowsOrEquals(id_, other.id_);
35 return TransactionIdPrecedes(id_, other.id_);
38 return TransactionIdPrecedesOrEquals(id_, other.id_);
41 bool did_abort()
const {
return is_valid() && TransactionIdDidAbort(id_); }
42 bool did_commit()
const {
return is_valid() && TransactionIdDidCommit(id_); }
52 : owner(::CurrentResourceOwner), commit(commit),
name(
"") {
54 ffi_guard{::BeginInternalSubTransaction}(
nullptr);
57 throw std::runtime_error(
"internal subtransaction already started");
62 : owner(::CurrentResourceOwner), commit(commit),
name(
name) {
64 ffi_guard{::BeginInternalSubTransaction}(this->name.c_str());
67 throw std::runtime_error(
"internal subtransaction already started");
74 ffi_guard{::ReleaseCurrentSubTransaction}();
76 ffi_guard{::RollbackAndReleaseCurrentSubTransaction}();
78 ::CurrentResourceOwner = owner;
82 ::ResourceOwner owner;
85 static inline std::stack<internal_subtransaction *> txns;
89 transaction(
bool commit =
true) : should_commit(commit), released(
false) {
91 if (!::IsTransactionState()) {
92 ::SetCurrentStatementStartTimestamp();
93 ::StartTransactionCommand();
94 ::PushActiveSnapshot(::GetTransactionSnapshot());
102 ::PopActiveSnapshot();
104 ::CommitTransactionCommand();
106 ::AbortCurrentTransaction();
114 ::PopActiveSnapshot();
115 ::CommitTransactionCommand();
122 ::PopActiveSnapshot();
123 ::AbortCurrentTransaction();