9#include <access/xact.h>
16 : owner(::CurrentResourceOwner), commit(commit),
name(
"") {
18 ffi_guard{::BeginInternalSubTransaction}(
nullptr);
21 throw std::runtime_error(
"internal subtransaction already started");
26 : owner(::CurrentResourceOwner), commit(commit),
name(
name) {
28 ffi_guard{::BeginInternalSubTransaction}(this->name.c_str());
31 throw std::runtime_error(
"internal subtransaction already started");
38 ffi_guard{::ReleaseCurrentSubTransaction}();
40 ffi_guard{::RollbackAndReleaseCurrentSubTransaction}();
42 ::CurrentResourceOwner = owner;
46 ::ResourceOwner owner;
49 static inline std::stack<internal_subtransaction *> txns;
53 transaction(
bool commit =
true) : should_commit(commit), released(
false) {
55 if (!::IsTransactionState()) {
56 ::SetCurrentStatementStartTimestamp();
57 ::StartTransactionCommand();
58 ::PushActiveSnapshot(::GetTransactionSnapshot());
66 ::PopActiveSnapshot();
68 ::CommitTransactionCommand();
70 ::AbortCurrentTransaction();
78 ::PopActiveSnapshot();
79 ::CommitTransactionCommand();
86 ::PopActiveSnapshot();
87 ::AbortCurrentTransaction();