1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/transaction/transaction.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp"
12#include "duckdb/common/types/data_chunk.hpp"
13#include "duckdb/transaction/undo_buffer.hpp"
14#include "duckdb/common/atomic.hpp"
15#include "duckdb/transaction/transaction_data.hpp"
16
17namespace duckdb {
18class SequenceCatalogEntry;
19class SchemaCatalogEntry;
20
21class AttachedDatabase;
22class ColumnData;
23class ClientContext;
24class CatalogEntry;
25class DataTable;
26class DatabaseInstance;
27class LocalStorage;
28class MetaTransaction;
29class TransactionManager;
30class WriteAheadLog;
31
32class ChunkVectorInfo;
33
34struct DeleteInfo;
35struct UpdateInfo;
36
37//! The transaction object holds information about a currently running or past
38//! transaction
39class Transaction {
40public:
41 DUCKDB_API Transaction(TransactionManager &manager, ClientContext &context);
42 DUCKDB_API virtual ~Transaction();
43
44 TransactionManager &manager;
45 weak_ptr<ClientContext> context;
46 //! The current active query for the transaction. Set to MAXIMUM_QUERY_ID if
47 //! no query is active.
48 atomic<transaction_t> active_query;
49
50public:
51 DUCKDB_API static Transaction &Get(ClientContext &context, AttachedDatabase &db);
52 DUCKDB_API static Transaction &Get(ClientContext &context, Catalog &catalog);
53
54 //! Whether or not the transaction has made any modifications to the database so far
55 DUCKDB_API bool IsReadOnly();
56
57 virtual bool IsDuckTransaction() const {
58 return false;
59 }
60
61public:
62 template <class TARGET>
63 TARGET &Cast() {
64 D_ASSERT(dynamic_cast<TARGET *>(this));
65 return reinterpret_cast<TARGET &>(*this);
66 }
67 template <class TARGET>
68 const TARGET &Cast() const {
69 D_ASSERT(dynamic_cast<const TARGET *>(this));
70 return reinterpret_cast<const TARGET &>(*this);
71 }
72};
73
74} // namespace duckdb
75