| 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 | |
| 17 | namespace duckdb { |
| 18 | class SequenceCatalogEntry; |
| 19 | class SchemaCatalogEntry; |
| 20 | |
| 21 | class AttachedDatabase; |
| 22 | class ColumnData; |
| 23 | class ClientContext; |
| 24 | class CatalogEntry; |
| 25 | class DataTable; |
| 26 | class DatabaseInstance; |
| 27 | class LocalStorage; |
| 28 | class MetaTransaction; |
| 29 | class TransactionManager; |
| 30 | class WriteAheadLog; |
| 31 | |
| 32 | class ChunkVectorInfo; |
| 33 | |
| 34 | struct DeleteInfo; |
| 35 | struct UpdateInfo; |
| 36 | |
| 37 | //! The transaction object holds information about a currently running or past |
| 38 | //! transaction |
| 39 | class Transaction { |
| 40 | public: |
| 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 | |
| 50 | public: |
| 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 | |
| 61 | public: |
| 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 |