| 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 | |
| 15 | namespace duckdb { |
| 16 | |
| 17 | class ClientContext; |
| 18 | class MetaTransaction; |
| 19 | class Transaction; |
| 20 | class TransactionManager; |
| 21 | |
| 22 | //! The transaction context keeps track of all the information relating to the |
| 23 | //! current transaction |
| 24 | class TransactionContext { |
| 25 | public: |
| 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 | |
| 54 | private: |
| 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 |