1#include "duckdb/catalog/catalog_transaction.hpp"
2#include "duckdb/catalog/catalog.hpp"
3#include "duckdb/transaction/duck_transaction.hpp"
4#include "duckdb/main/database.hpp"
5
6namespace duckdb {
7
8CatalogTransaction::CatalogTransaction(Catalog &catalog, ClientContext &context) {
9 auto &transaction = Transaction::Get(context, catalog);
10 this->db = &DatabaseInstance::GetDatabase(context);
11 if (!transaction.IsDuckTransaction()) {
12 this->transaction_id = transaction_t(-1);
13 this->start_time = transaction_t(-1);
14 } else {
15 auto &dtransaction = transaction.Cast<DuckTransaction>();
16 this->transaction_id = dtransaction.transaction_id;
17 this->start_time = dtransaction.start_time;
18 }
19 this->transaction = &transaction;
20 this->context = &context;
21}
22
23CatalogTransaction::CatalogTransaction(DatabaseInstance &db, transaction_t transaction_id_p, transaction_t start_time_p)
24 : db(&db), context(nullptr), transaction(nullptr), transaction_id(transaction_id_p), start_time(start_time_p) {
25}
26
27ClientContext &CatalogTransaction::GetContext() {
28 if (!context) {
29 throw InternalException("Attempting to get a context in a CatalogTransaction without a context");
30 }
31 return *context;
32}
33
34CatalogTransaction CatalogTransaction::GetSystemTransaction(DatabaseInstance &db) {
35 return CatalogTransaction(db, 1, 1);
36}
37
38} // namespace duckdb
39