9
9
)
10
10
11
11
const (
12
- tableFieldCatalog = "fldcat"
13
- tableTableCatalog = "tblcat"
12
+ defaultTableFieldCatalog = "fldcat"
13
+ defaultTableTableCatalog = "tblcat"
14
14
15
15
fieldTableName = "tblname"
16
16
fieldSlotSize = "slotsize"
@@ -21,17 +21,39 @@ const (
21
21
)
22
22
23
23
type TableMgrImpl struct {
24
+ tableCatalog string
25
+ fieldCatalog string
24
26
tblCatLayout record.Layout
25
27
fldCatLayout record.Layout
26
28
mu sync.Mutex
27
29
}
28
30
31
+ type TableMgrOption func (* TableMgrImpl )
32
+
33
+ func WithTableTableCatalog (name string ) TableMgrOption {
34
+ return func (tm * TableMgrImpl ) {
35
+ tm .tableCatalog = name
36
+ }
37
+ }
38
+
39
+ func WithTableFieldCatalog (name string ) TableMgrOption {
40
+ return func (tm * TableMgrImpl ) {
41
+ tm .fieldCatalog = name
42
+ }
43
+ }
44
+
29
45
// MaxName is the maximum character length a tablename or fieldname can have.
30
46
const MAX_NAME_LENGTH = 16
31
47
32
48
// NewTableMgr creates a new catalog manager for the database system.
33
- func NewTableMgr (tx tx.Transaction ) (* TableMgrImpl , error ) {
34
- tm := & TableMgrImpl {}
49
+ func NewTableMgr (tx tx.Transaction , opts ... TableMgrOption ) (* TableMgrImpl , error ) {
50
+ tm := & TableMgrImpl {
51
+ tableCatalog : defaultTableTableCatalog ,
52
+ fieldCatalog : defaultTableFieldCatalog ,
53
+ }
54
+ for _ , opt := range opts {
55
+ opt (tm )
56
+ }
35
57
36
58
var err error
37
59
@@ -47,10 +69,10 @@ func NewTableMgr(tx tx.Transaction) (*TableMgrImpl, error) {
47
69
return nil , fmt .Errorf ("metadata: failed to create field catalog layout from schema: %w" , err )
48
70
}
49
71
50
- if err := tm .CreateTable (tableTableCatalog , tblCatSchema , tx ); err != nil {
72
+ if err := tm .CreateTable (tm . tableCatalog , tblCatSchema , tx ); err != nil {
51
73
return nil , err
52
74
}
53
- if err := tm .CreateTable (tableFieldCatalog , fldCatSchema , tx ); err != nil {
75
+ if err := tm .CreateTable (defaultTableFieldCatalog , fldCatSchema , tx ); err != nil {
54
76
return nil , err
55
77
}
56
78
return tm , nil
@@ -100,7 +122,7 @@ func (tm *TableMgrImpl) CreateTable(tblname string, sch record.Schema, tx tx.Tra
100
122
}
101
123
102
124
func (tm * TableMgrImpl ) HasTable (tblname string , tx tx.Transaction ) (bool , error ) {
103
- tcat , err := record .NewTableScan (tx , tableTableCatalog , tm .tblCatLayout )
125
+ tcat , err := record .NewTableScan (tx , tm . tableCatalog , tm .tblCatLayout )
104
126
if err != nil {
105
127
return false , fmt .Errorf ("metadata: failed to create table scan: %w" , err )
106
128
}
@@ -118,7 +140,7 @@ func (tm *TableMgrImpl) HasTable(tblname string, tx tx.Transaction) (bool, error
118
140
}
119
141
120
142
func (tm * TableMgrImpl ) addToTableCatalog (tblname string , slotSize int , tx tx.Transaction ) error {
121
- tcat , err := record .NewTableScan (tx , tableTableCatalog , tm .tblCatLayout )
143
+ tcat , err := record .NewTableScan (tx , tm . tableCatalog , tm .tblCatLayout )
122
144
if err != nil {
123
145
return fmt .Errorf ("metadata: failed to create table scan: %w" , err )
124
146
}
@@ -140,7 +162,7 @@ func (tm *TableMgrImpl) addToFieldCatalog(tblname string, schema record.Schema,
140
162
if err != nil {
141
163
return fmt .Errorf ("metadata: failed to create layout from schema: %w" , err )
142
164
}
143
- fcat , err := record .NewTableScan (tx , tableFieldCatalog , tm .fldCatLayout )
165
+ fcat , err := record .NewTableScan (tx , tm . fieldCatalog , tm .fldCatLayout )
144
166
if err != nil {
145
167
return fmt .Errorf ("metadata: failed to create table scan: %w" , err )
146
168
}
@@ -179,7 +201,7 @@ func (tm *TableMgrImpl) addToFieldCatalog(tblname string, schema record.Schema,
179
201
func (tm * TableMgrImpl ) DropTable (tblname string , tx tx.Transaction ) error {
180
202
tm .mu .Lock ()
181
203
defer tm .mu .Unlock ()
182
- tcat , err := record .NewTableScan (tx , tableTableCatalog , tm .tblCatLayout )
204
+ tcat , err := record .NewTableScan (tx , tm . tableCatalog , tm .tblCatLayout )
183
205
if err != nil {
184
206
return fmt .Errorf ("metadata: failed to create table scan: %w" , err )
185
207
}
@@ -198,7 +220,7 @@ func (tm *TableMgrImpl) DropTable(tblname string, tx tx.Transaction) error {
198
220
}
199
221
tcat .Close ()
200
222
201
- fcat , err := record .NewTableScan (tx , tableFieldCatalog , tm .fldCatLayout )
223
+ fcat , err := record .NewTableScan (tx , tm . fieldCatalog , tm .fldCatLayout )
202
224
if err != nil {
203
225
return fmt .Errorf ("metadata: failed to create table scan: %w" , err )
204
226
}
@@ -233,7 +255,7 @@ func (tm *TableMgrImpl) GetLayout(tblname string, tx tx.Transaction) (record.Lay
233
255
}
234
256
235
257
func (tm * TableMgrImpl ) getTableSlotSize (tblname string , tx tx.Transaction ) (int , error ) {
236
- tcat , err := record .NewTableScan (tx , tableTableCatalog , tm .tblCatLayout )
258
+ tcat , err := record .NewTableScan (tx , tm . tableCatalog , tm .tblCatLayout )
237
259
if err != nil {
238
260
return 0 , fmt .Errorf ("metadata: failed to create table scan: %w" , err )
239
261
}
@@ -254,7 +276,7 @@ func (tm *TableMgrImpl) getTableSlotSize(tblname string, tx tx.Transaction) (int
254
276
func (tm * TableMgrImpl ) getTableSchemaOffset (tblName string , tx tx.Transaction ) (record.Schema , map [string ]int , error ) {
255
277
sch := record .NewSchema ()
256
278
offsets := make (map [string ]int )
257
- fcat , err := record .NewTableScan (tx , tableFieldCatalog , tm .fldCatLayout )
279
+ fcat , err := record .NewTableScan (tx , defaultTableFieldCatalog , tm .fldCatLayout )
258
280
if err != nil {
259
281
return nil , nil , fmt .Errorf ("metadata: failed to create table scan: %w" , err )
260
282
}
@@ -288,3 +310,11 @@ func (tm *TableMgrImpl) getTableSchemaOffset(tblName string, tx tx.Transaction)
288
310
}
289
311
return sch , offsets , nil
290
312
}
313
+
314
+ func (tm * TableMgrImpl ) TableCatalog () string {
315
+ return tm .tableCatalog
316
+ }
317
+
318
+ func (tm * TableMgrImpl ) FieldCatalog () string {
319
+ return tm .fieldCatalog
320
+ }
0 commit comments