1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/catalog/catalog_entry.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/common.hpp"
12#include "duckdb/common/enums/catalog_type.hpp"
13#include "duckdb/common/exception.hpp"
14#include "duckdb/common/atomic.hpp"
15#include "duckdb/common/optional_ptr.hpp"
16#include <memory>
17
18namespace duckdb {
19struct AlterInfo;
20class Catalog;
21class CatalogSet;
22class ClientContext;
23class SchemaCatalogEntry;
24
25//! Abstract base class of an entry in the catalog
26class CatalogEntry {
27public:
28 CatalogEntry(CatalogType type, Catalog &catalog, string name);
29 CatalogEntry(CatalogType type, string name, idx_t oid);
30 virtual ~CatalogEntry();
31
32 //! The oid of the entry
33 idx_t oid;
34 //! The type of this catalog entry
35 CatalogType type;
36 //! Reference to the catalog set this entry is stored in
37 optional_ptr<CatalogSet> set;
38 //! The name of the entry
39 string name;
40 //! Whether or not the object is deleted
41 bool deleted;
42 //! Whether or not the object is temporary and should not be added to the WAL
43 bool temporary;
44 //! Whether or not the entry is an internal entry (cannot be deleted, not dumped, etc)
45 bool internal;
46 //! Timestamp at which the catalog entry was created
47 atomic<transaction_t> timestamp;
48 //! Child entry
49 unique_ptr<CatalogEntry> child;
50 //! Parent entry (the node that dependents_map this node)
51 optional_ptr<CatalogEntry> parent;
52
53public:
54 virtual unique_ptr<CatalogEntry> AlterEntry(ClientContext &context, AlterInfo &info);
55 virtual void UndoAlter(ClientContext &context, AlterInfo &info);
56
57 virtual unique_ptr<CatalogEntry> Copy(ClientContext &context) const;
58
59 //! Sets the CatalogEntry as the new root entry (i.e. the newest entry)
60 // this is called on a rollback to an AlterEntry
61 virtual void SetAsRoot();
62
63 //! Convert the catalog entry to a SQL string that can be used to re-construct the catalog entry
64 virtual string ToSQL() const;
65
66 virtual Catalog &ParentCatalog();
67 virtual SchemaCatalogEntry &ParentSchema();
68
69 virtual void Verify(Catalog &catalog);
70
71public:
72 template <class TARGET>
73 TARGET &Cast() {
74 D_ASSERT(dynamic_cast<TARGET *>(this));
75 return reinterpret_cast<TARGET &>(*this);
76 }
77 template <class TARGET>
78 const TARGET &Cast() const {
79 D_ASSERT(dynamic_cast<const TARGET *>(this));
80 return reinterpret_cast<const TARGET &>(*this);
81 }
82};
83
84class InCatalogEntry : public CatalogEntry {
85public:
86 InCatalogEntry(CatalogType type, Catalog &catalog, string name);
87 ~InCatalogEntry() override;
88
89 //! The catalog the entry belongs to
90 Catalog &catalog;
91
92public:
93 Catalog &ParentCatalog() override {
94 return catalog;
95 }
96
97 void Verify(Catalog &catalog) override;
98};
99
100} // namespace duckdb
101