1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/transaction/transaction_context.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/common.hpp"
12#include "duckdb/common/assert.hpp"
13#include "duckdb/common/exception.hpp"
14
15namespace duckdb {
16
17class ClientContext;
18class MetaTransaction;
19class Transaction;
20class TransactionManager;
21
22//! The transaction context keeps track of all the information relating to the
23//! current transaction
24class TransactionContext {
25public:
26 TransactionContext(ClientContext &context);
27 ~TransactionContext();
28
29 MetaTransaction &ActiveTransaction() {
30 if (!current_transaction) {
31 throw InternalException("TransactionContext::ActiveTransaction called without active transaction");
32 }
33 return *current_transaction;
34 }
35
36 bool HasActiveTransaction() {
37 return !!current_transaction;
38 }
39
40 void BeginTransaction();
41 void Commit();
42 void Rollback();
43 void ClearTransaction();
44
45 void SetAutoCommit(bool value);
46 bool IsAutoCommit() {
47 return auto_commit;
48 }
49
50 idx_t GetActiveQuery();
51 void ResetActiveQuery();
52 void SetActiveQuery(transaction_t query_number);
53
54private:
55 ClientContext &context;
56 bool auto_commit;
57
58 unique_ptr<MetaTransaction> current_transaction;
59
60 TransactionContext(const TransactionContext &) = delete;
61};
62
63} // namespace duckdb
64