forked from chankinyuk/5300-Dolphin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_tables.h
150 lines (123 loc) · 4.19 KB
/
schema_tables.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* @file schema_tables.h - schema table classes:
* Columns
* Tables
* @author Kevin Lundeen
* @see "Seattle University, CPSC5300, Summer 2018"
*/
#pragma once
#include "heap_storage.h"
/**
* Initialize access to the schema tables.
* Must be called before anything else is done with any of the schema
* data structures.
*/
void initialize_schema_tables();
class Columns; // forward declare
/**
* @class Tables - The singleton table that stores the metadata for all other tables.
* For now, we are not indexing anything, so a query requires sequential scan
* of the table.
*/
class Tables : public HeapTable {
public:
/**
* Name of the tables table ("_tables")
*/
static const Identifier TABLE_NAME;
// ctor/dtor
Tables();
virtual ~Tables() {}
// HeapTable overrides
virtual void create();
virtual Handle insert(const ValueDict* row);
virtual void del(Handle handle);
/**
* Get the columns and their attributes for a given table.
* @param table_name table to get column info for
* @param column_names returned by reference: list of column names
* for table_name
* @param column_attributes returned by reference: list of corresponding
* attributes for column_names
*/
static void get_columns(Identifier table_name, ColumnNames &column_names, ColumnAttributes &column_attributes);
/**
* Get the correctly instantiated DbRelation for a given table.
* @param table_name table to get
* @returns instantiated DbRelation of the correct type
*/
static DbRelation& get_table(Identifier table_name);
protected:
// hard-coded columns for _tables table
static ColumnNames& COLUMN_NAMES();
static ColumnAttributes& COLUMN_ATTRIBUTES();
// keep a reference to the columns table (for get_columns method)
static Columns* columns_table;
private:
// keep a cache of all the tables we've instantiated so far
static std::map<Identifier,DbRelation*> table_cache;
};
/**
* @class Columns - The singleton table that stores the column metadata for all tables.
*/
class Columns : public HeapTable {
public:
/**
* Name of the columns table ("_columns")
*/
static const Identifier TABLE_NAME;
// ctor/dtor
Columns();
virtual ~Columns() {}
// HeapTable overrides
virtual void create();
virtual Handle insert(const ValueDict* row);
protected:
// hard-coded columns for the _columns table
static ColumnNames& COLUMN_NAMES();
static ColumnAttributes& COLUMN_ATTRIBUTES();
};
typedef ColumnNames IndexNames;
class Indices : public HeapTable {
public:
/**
* Name of the indices table ("_indices")
*/
static const Identifier TABLE_NAME;
// ctor/dtor
Indices();
virtual ~Indices() {}
/**
* Get the search key for the given index.
* @param table_name what table the requested index is on
* @param index_name name of index (unique by table)
* @param column_names returned by reference: list of column names
* in search key in order
* @param is_hash returned by reference: set to False if the
* requested index is a btree index
* @param is_unique search key for this index is a key for the relation
*/
virtual void get_columns(Identifier table_name, Identifier index_name,
ColumnNames &column_names, bool &is_hash, bool &is_unique);
/**
* Get the instantiated DbIndex for the given index.
* @param table_name what table the requested index is on
* @param index_name name of index (unique by table)
* @returns DbIndex for requested index
*/
virtual DbIndex& get_index(Identifier table_name, Identifier index_name);
/**
* Get the list of indices on a given table.
* @param table_name which table to lookup the indices on
* @returns list of index names for table_name
*/
virtual IndexNames get_index_names(Identifier table_name);
// overrides
virtual Handle insert(const ValueDict* row);
virtual void del(Handle handle);
protected:
static ColumnNames& COLUMN_NAMES();
static ColumnAttributes& COLUMN_ATTRIBUTES();
private:
static std::map<std::pair<Identifier,Identifier>,DbIndex*> index_cache;
};