DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
TableManager.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 
21 using Deveel.Data.Index;
22 using Deveel.Data.Sql.Objects;
24 using Deveel.Data.Types;
25 
26 namespace Deveel.Data.Sql.Tables {
27  public sealed class TableManager : IObjectManager {
28  private readonly List<ITableSource> visibleTables;
29  private List<IMutableTable> accessedTables;
30  private List<ITableSource> selectedTables;
31  private readonly List<IIndexSet> tableIndices;
32  private List<ITableContainer> internalTables;
33 
34  private readonly Dictionary<ObjectName, IMutableTable> tableCache;
35 
36  private List<object> cleanupQueue;
37 
38  public TableManager(ITransaction transaction, ITableSourceComposite composite) {
39  if (transaction == null)
40  throw new ArgumentNullException("transaction");
41 
42  Transaction = transaction;
43 
44  Composite = composite;
45 
46  visibleTables = new List<ITableSource>();
47  tableIndices = new List<IIndexSet>();
48  accessedTables = new List<IMutableTable>();
49  tableCache = new Dictionary<ObjectName, IMutableTable>();
50  selectedTables = new List<ITableSource>();
51  }
52 
54  Dispose(true);
55  }
56 
57  public ITransaction Transaction { get; private set; }
58 
59  private ITableSourceComposite Composite { get; set; }
60 
61  internal IEnumerable<IMutableTable> AccessedTables {
62  get { return accessedTables; }
63  }
64 
65  internal IEnumerable<ITableSource> SelectedTables {
66  get {
67  lock (selectedTables) {
68  return selectedTables.ToArray();
69  }
70  }
71  }
72 
73  private bool IgnoreIdentifiersCase {
74  get { return Transaction.IgnoreIdentifiersCase(); }
75  }
76 
77  public void Dispose() {
78  Dispose(true);
79  GC.SuppressFinalize(this);
80  }
81 
82  private void DisposeAllIndices() {
83  // Dispose all the IIndexSet for each table
84  try {
85  foreach (var tableIndex in tableIndices) {
86  tableIndex.Dispose();
87  }
88  } catch (Exception) {
89  // TODO: Report the error ...
90  }
91 
92  // Dispose all tables we dropped (they will be in the cleanup_queue.
93  try {
94  if (cleanupQueue != null) {
95  for (int i = 0; i < cleanupQueue.Count; i += 2) {
96  var tableSource = (TableSource) cleanupQueue[i];
97  IIndexSet indexSet = (IIndexSet) cleanupQueue[i + 1];
98  indexSet.Dispose();
99  }
100  }
101  } catch (Exception) {
102  // TODO: Report the error
103  } finally {
104  cleanupQueue = null;
105  }
106  }
107 
108  private void DisposeTouchedTables() {
109  try {
110  foreach (var table in accessedTables) {
111  table.Dispose();
112  }
113 
114  accessedTables.Clear();
115  } catch (Exception) {
116  // TODO: Report the error
117  } finally {
118  accessedTables = null;
119  }
120  }
121 
122  private void Dispose(bool disposing) {
123  if (disposing) {
124  DisposeAllIndices();
125  DisposeTouchedTables();
126  }
127 
128  Transaction = null;
129  }
130 
132  get { return DbObjectType.Table; }
133  }
134 
135  public void Create() {
136  // SYSTEM.PKEY_INFO
137  var tableInfo = new TableInfo(SystemSchema.PrimaryKeyInfoTableName);
138  tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
139  tableInfo.AddColumn("name", PrimitiveTypes.String());
140  tableInfo.AddColumn("schema", PrimitiveTypes.String());
141  tableInfo.AddColumn("table", PrimitiveTypes.String());
142  tableInfo.AddColumn("deferred", PrimitiveTypes.Numeric());
143  tableInfo = tableInfo.AsReadOnly();
144  Transaction.CreateTable(tableInfo);
145 
146  // SYSTEM.PKEY_COLS
148  tableInfo.AddColumn("pk_id", PrimitiveTypes.Numeric());
149  tableInfo.AddColumn("column", PrimitiveTypes.String());
150  tableInfo.AddColumn("seq_no", PrimitiveTypes.Numeric());
151  tableInfo = tableInfo.AsReadOnly();
152  Transaction.CreateTable(tableInfo);
153 
154  // SYSTEM.FKEY_INFO
156  tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
157  tableInfo.AddColumn("name", PrimitiveTypes.String());
158  tableInfo.AddColumn("schema", PrimitiveTypes.String());
159  tableInfo.AddColumn("table", PrimitiveTypes.String());
160  tableInfo.AddColumn("ref_schema", PrimitiveTypes.String());
161  tableInfo.AddColumn("ref_table", PrimitiveTypes.String());
162  tableInfo.AddColumn("update_rule", PrimitiveTypes.Numeric());
163  tableInfo.AddColumn("delete_rule", PrimitiveTypes.Numeric());
164  tableInfo.AddColumn("deferred", PrimitiveTypes.Numeric());
165  tableInfo = tableInfo.AsReadOnly();
166  Transaction.CreateTable(tableInfo);
167 
168  // SYSTEM.FKEY_COLS
170  tableInfo.AddColumn("fk_id", PrimitiveTypes.Numeric());
171  tableInfo.AddColumn("fcolumn", PrimitiveTypes.String());
172  tableInfo.AddColumn("pcolumn", PrimitiveTypes.String());
173  tableInfo.AddColumn("seq_no", PrimitiveTypes.Numeric());
174  tableInfo = tableInfo.AsReadOnly();
175  Transaction.CreateTable(tableInfo);
176 
177  // SYSTEM.UNIQUE_INFO
179  tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
180  tableInfo.AddColumn("name", PrimitiveTypes.String());
181  tableInfo.AddColumn("schema", PrimitiveTypes.String());
182  tableInfo.AddColumn("table", PrimitiveTypes.String());
183  tableInfo.AddColumn("deferred", PrimitiveTypes.Numeric());
184  tableInfo = tableInfo.AsReadOnly();
185  Transaction.CreateTable(tableInfo);
186 
187  // SYSTEM.UNIQUE_COLS
189  tableInfo.AddColumn("un_id", PrimitiveTypes.Numeric());
190  tableInfo.AddColumn("column", PrimitiveTypes.String());
191  tableInfo.AddColumn("seq_no", PrimitiveTypes.Numeric());
192  tableInfo = tableInfo.AsReadOnly();
193  Transaction.CreateTable(tableInfo);
194 
195  // SYSTEM.CHECK_INFO
196  tableInfo = new TableInfo(SystemSchema.CheckInfoTableName);
197  tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
198  tableInfo.AddColumn("name", PrimitiveTypes.String());
199  tableInfo.AddColumn("schema", PrimitiveTypes.String());
200  tableInfo.AddColumn("table", PrimitiveTypes.String());
201  tableInfo.AddColumn("expression", PrimitiveTypes.String());
202  tableInfo.AddColumn("deferred", PrimitiveTypes.Numeric());
203  tableInfo.AddColumn("serialized_expression", PrimitiveTypes.Binary());
204  tableInfo = tableInfo.AsReadOnly();
205  Transaction.CreateTable(tableInfo);
206  }
207 
209  var tableInfo = objInfo as TableInfo;
210  if (tableInfo == null)
211  throw new ArgumentException();
212 
213  CreateTable(tableInfo);
214  }
215 
216  public void CreateTable(TableInfo tableInfo) {
217  CreateTable(tableInfo, false);
218  }
219 
220  public void CreateTable(TableInfo tableInfo, bool temporary) {
221  var tableName = tableInfo.TableName;
222  var source = FindVisibleTable(tableName, false);
223  if (source != null)
224  throw new InvalidOperationException(String.Format("Table '{0}' already exists.", tableName));
225 
226  tableInfo = tableInfo.AsReadOnly();
227 
228  source = Composite.CreateTableSource(tableInfo, temporary);
229 
230  // Add this table (and an index set) for this table.
231  AddVisibleTable(source, source.CreateIndexSet());
232 
233  int tableId = source.TableId;
234  Transaction.Registry.RegisterEvent(new TableCreatedEvent(tableId, tableName));
235 
236  Transaction.CreateNativeSequence(tableName);
237  }
238 
239  public void CreateTemporaryTable(TableInfo tableInfo) {
240  CreateTable(tableInfo, true);
241  }
242 
243  public void SelectTable(ObjectName tableName) {
244  // Special handling of internal tables,
245  if (IsDynamicTable(tableName))
246  return;
247 
248  var source = FindVisibleTable(tableName, false);
249  if (source == null)
250  throw new ObjectNotFoundException(tableName);
251 
252  lock (selectedTables) {
253  if (!selectedTables.Contains(source))
254  selectedTables.Add(source);
255  }
256  }
257 
258  public void CompactTable(ObjectName tableName) {
259  // Find the master table.
260  var currentTable = FindVisibleTable(tableName, false);
261  if (currentTable == null)
262  throw new ObjectNotFoundException(tableName);
263 
264  // If the table is worth compacting
265  if (currentTable.CanCompact) {
266  // The view of this table within this transaction.
267  var indexSet = GetIndexSetForTable(currentTable);
268 
269  // Drop the current table
270  DropTable(tableName);
271 
272  // And copy to the new table
273  CopyTable(currentTable, indexSet);
274  }
275  }
276 
277  private void CopyTable(ITableSource tableSource, IIndexSet indexSet) {
278  var tableInfo = tableSource.TableInfo;
279  var tableName = tableInfo.TableName;
280  var source = FindVisibleTable(tableName, false);
281  if (source != null)
282  throw new ObjectNotFoundException(tableName);
283 
284  // Copy the table and add to the list of visible tables.
285  source = Composite.CopySourceTable(tableSource, indexSet);
286 
287  AddVisibleTable(source, source.CreateIndexSet());
288 
289  // Log in the journal that this transaction touched the table_id.
290  int tableId = source.TableId;
291  Transaction.Registry.RegisterEvent(new TableCreatedEvent(tableId, tableName));
292 
293  Transaction.CreateNativeSequence(tableName);
294  }
295 
297  int sz = tableIndices.Count;
298  for (int i = 0; i < sz; ++i) {
299  if (visibleTables[i].TableId == tableSource.TableId) {
300  return tableIndices[i];
301  }
302  }
303 
304  throw new Exception("Table source not found in this transaction.");
305  }
306 
307  private void AddVisibleTable(ITableSource table, IIndexSet indexSet) {
308  if (Transaction.ReadOnly())
309  throw new Exception("Transaction is Read-only.");
310 
311  visibleTables.Add(table);
312  tableIndices.Add(indexSet);
313  }
314 
315  private static int IndexOfTable(IList<ITableSource> sources, int tableId) {
316  for (int i = 0; i < sources.Count; i++) {
317  var source = sources[i];
318  if (source.TableId == tableId)
319  return i;
320  }
321 
322  return -1;
323  }
324 
325  internal void RemoveVisibleTable(ITableSource table) {
326  if (Transaction.ReadOnly())
327  throw new Exception("Transaction is Read-only.");
328 
329  var i = IndexOfTable(visibleTables, table.TableId);
330  if (i != -1) {
331  visibleTables.RemoveAt(i);
332  IIndexSet indexSet = tableIndices[i];
333  tableIndices.RemoveAt(i);
334  if (cleanupQueue == null)
335  cleanupQueue = new List<object>();
336 
337  cleanupQueue.Add(table);
338  cleanupQueue.Add(indexSet);
339 
340  // Remove from the table cache
341  var tableName = table.TableInfo.TableName;
342  tableCache.Remove(tableName);
343  }
344  }
345 
346  internal void UpdateVisibleTable(TableSource table, IIndexSet indexSet) {
347  if (Transaction.ReadOnly())
348  throw new Exception("Transaction is Read-only.");
349 
350  RemoveVisibleTable(table);
351  AddVisibleTable(table, indexSet);
352  }
353 
354  private ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase) {
355  return visibleTables
356  .FirstOrDefault(source => source != null &&
357  source.TableInfo.TableName.Equals(tableName, ignoreCase));
358  }
359 
360  public SqlNumber SetUniqueId(ObjectName tableName, SqlNumber value) {
361  var tableSource = FindVisibleTable(tableName, false);
362  if (tableSource == null)
363  throw new ObjectNotFoundException(tableName,
364  String.Format("Table with name '{0}' could not be found to set the unique id.", tableName));
365 
366  tableSource.SetUniqueId(value.ToInt64());
367  return value;
368  }
369 
370  public SqlNumber NextUniqueId(ObjectName tableName) {
371  var tableSource = FindVisibleTable(tableName, false);
372  if (tableSource == null)
373  throw new ObjectNotFoundException(tableName,
374  String.Format("Table with name '{0}' could not be found to retrieve unique id.", tableName));
375 
376  var value = tableSource.GetNextUniqueId();
377  return new SqlNumber(value);
378  }
379 
380  private bool IsDynamicTable(ObjectName tableName) {
381  if (internalTables == null)
382  return false;
383 
384  return internalTables.Any(info => info != null && info.ContainsTable(tableName));
385  }
386 
387  private ITable GetDynamicTable(ObjectName tableName) {
388  foreach (var info in internalTables) {
389  if (info != null) {
390  int index = info.FindByName(tableName);
391  if (index != -1)
392  return info.GetTable(index);
393  }
394  }
395 
396  throw new ArgumentException(String.Format("Table '{0}' is not a dynamic table.", tableName));
397  }
398 
399  private string GetDynamicTableType(ObjectName tableName) {
400  // Otherwise we need to look up the table in the internal table list,
401  foreach (var info in internalTables) {
402  if (info != null) {
403  int index = info.FindByName(tableName);
404  if (index != -1)
405  return info.GetTableType(index);
406  }
407  }
408 
409  throw new ArgumentException(String.Format("Table '{0}' is not a dynamic table.", tableName));
410  }
411 
413  return RealTableExists(objName);
414  }
415 
416  public bool RealTableExists(ObjectName tableName) {
417  return FindVisibleTable(tableName, false) != null;
418  }
419 
421  return TableExists(objName);
422  }
423 
424  public bool TableExists(ObjectName tableName) {
425  return IsDynamicTable(tableName) ||
426  RealTableExists(tableName);
427  }
428 
430  return GetTable(objName);
431  }
432 
433  public ITable GetTable(ObjectName tableName) {
434  // If table is in the cache, return it
435  IMutableTable table;
436  if (tableCache.TryGetValue(tableName, out table))
437  return table;
438 
439  var source = FindVisibleTable(tableName, false);
440 
441  if (source == null) {
442  if (IsDynamicTable(tableName))
443  return GetDynamicTable(tableName);
444  } else {
445  // Otherwise make a view of tha master table data source and write it in
446  // the cache.
447  table = CreateTableAtCommit(source);
448 
449  // Put table name in the cache
450  tableCache[tableName] = table;
451  }
452 
453  return table;
454  }
455 
456  public String GetTableType(ObjectName tableName) {
457  if (tableName == null)
458  throw new ArgumentNullException("tableName");
459 
460  if (IsDynamicTable(tableName))
461  return GetDynamicTableType(tableName);
462  if (FindVisibleTable(tableName, false) != null)
463  return TableTypes.Table;
464 
465  // No table found so report the error.
466  throw new ObjectNotFoundException(tableName);
467  }
468 
470  int sz = internalTables.Where(container => container != null).Sum(container => container.TableCount);
471 
472  var list = new ObjectName[sz];
473  int index = -1;
474 
475  foreach (var container in internalTables) {
476  if (container != null) {
477  int tableCount = container.TableCount;
478  for (int i = 0; i < tableCount; ++i) {
479  list[++index] = container.GetTableName(i);
480  }
481  }
482  }
483 
484  return list;
485  }
486 
488  // Is it a visable table (match case insensitive)
489  var table = FindVisibleTable(tableName, true);
490  if (table != null)
491  return table.TableInfo.TableName;
492 
493  var comparison = IgnoreIdentifiersCase
494  ? StringComparison.OrdinalIgnoreCase
495  : StringComparison.Ordinal;
496 
497  // Is it an internal table?
498  string tschema = tableName.ParentName;
499  string tname = tableName.Name;
500  var list = GetDynamicTables();
501  foreach (var ctable in list) {
502  if (String.Equals(ctable.ParentName, tschema, comparison) &&
503  String.Equals(ctable.Name, tname, comparison)) {
504  return ctable;
505  }
506  }
507 
508  // No matches so return the original object.
509  return tableName;
510  }
511 
513  var table = GetTable(tableName);
514  if (table == null)
515  return null;
516 
517  if (!(table is IMutableTable))
518  throw new InvalidOperationException();
519 
520  return (IMutableTable) table;
521  }
522 
524  foreach (var info in internalTables) {
525  if (info != null) {
526  int index = info.FindByName(tableName);
527  if (index != -1)
528  return info.GetTableInfo(index);
529  }
530  }
531 
532  throw new Exception("Not an internal table: " + tableName);
533  }
534 
535  public TableInfo GetTableInfo(ObjectName tableName) {
536  // If this is a dynamic table then handle specially
537  if (IsDynamicTable(tableName))
538  return GetDynamicTableInfo(tableName);
539 
540  // Otherwise return from the pool of visible tables
541  return visibleTables
542  .Select(table => table.TableInfo)
543  .FirstOrDefault(tableInfo => tableInfo.TableName.Equals(tableName));
544  }
545 
547  // Create the table for this transaction.
548  var table = source.CreateTableAtCommit(Transaction);
549 
550  accessedTables.Add(table);
551 
553 
554  return table;
555  }
556 
558  var tableInfo = objInfo as TableInfo;
559  if (tableInfo == null)
560  throw new ArgumentException();
561 
562  return AlterTable(tableInfo);
563  }
564 
565  public bool AlterTable(TableInfo tableInfo) {
566  tableInfo = tableInfo.AsReadOnly();
567 
568  var tableName = tableInfo.TableName;
569 
570  // The current schema context is the schema of the table name
571  string currentSchema = tableName.Parent.Name;
572  using (var session = new SystemSession(Transaction, currentSchema)) {
573  using (var context = session.CreateQuery()) {
574 
575  // Get the next unique id of the unaltered table.
576  var nextId = NextUniqueId(tableName);
577 
578  // Drop the current table
579  var cTable = GetTable(tableName);
580  var droppedTableId = cTable.TableInfo.Id;
581 
582  DropTable(tableName);
583 
584  // And create the table table
585  CreateTable(tableInfo);
586 
587  var alteredTable = GetMutableTable(tableName);
588  var source = FindVisibleTable(tableName, false);
589  int alteredTableId = source.TableId;
590 
591  // Set the sequence id of the table
592  source.SetUniqueId(nextId.ToInt64());
593 
594  // Work out which columns we have to copy to where
595  int[] colMap = new int[tableInfo.ColumnCount];
596  var origTd = cTable.TableInfo;
597  for (int i = 0; i < colMap.Length; ++i) {
598  string colName = tableInfo[i].ColumnName;
599  colMap[i] = origTd.IndexOfColumn(colName);
600  }
601 
602  // First move all the rows from the old table to the new table,
603  // This does NOT update the indexes.
604  var e = cTable.GetEnumerator();
605  while (e.MoveNext()) {
606  int rowIndex = e.Current.RowId.RowNumber;
607  var dataRow = alteredTable.NewRow();
608  for (int i = 0; i < colMap.Length; ++i) {
609  int col = colMap[i];
610  if (col != -1) {
611  dataRow.SetValue(i, cTable.GetValue(rowIndex, col));
612  }
613  }
614 
615  dataRow.SetDefault(context);
616 
617  // Note we use a low level 'AddRow' method on the master table
618  // here. This does not touch the table indexes. The indexes are
619  // built later.
620  int newRowNumber = source.AddRow(dataRow);
621 
622  // Set the record as committed added
623  source.WriteRecordState(newRowNumber, RecordState.CommittedAdded);
624  }
625 
626  // TODO: We need to copy any existing index definitions that might
627  // have been set on the table being altered.
628 
629  // Rebuild the indexes in the new master table,
630  source.BuildIndexes();
631 
632  // Get the snapshot index set on the new table and set it here
633  SetIndexSetForTable(source, source.CreateIndexSet());
634 
635  // Flush this out of the table cache
636  FlushTableCache(tableName);
637 
638  // Ensure the native sequence generator exists...
639  Transaction.RemoveNativeSequence(tableName);
640  Transaction.CreateNativeSequence(tableName);
641 
642  // Notify that this database object has been successfully dropped and
643  // created.
644  Transaction.Registry.RegisterEvent(new TableDroppedEvent(droppedTableId, tableName));
645  Transaction.Registry.RegisterEvent(new TableCreatedEvent(alteredTableId, tableName));
646 
647  return true;
648  }
649  }
650  }
651 
652  private
653  void FlushTableCache(ObjectName tableName) {
654  tableCache.Remove(tableName);
655  }
656 
657  private void SetIndexSetForTable(ITableSource source, IIndexSet indexSet) {
658  int sz = tableIndices.Count;
659  for (int i = 0; i < sz; ++i) {
660  if (visibleTables[i].TableId == source.TableId) {
661  tableIndices[i] = indexSet;
662  return;
663  }
664  }
665 
666  throw new Exception("Table source not found in this transaction.");
667  }
668 
670  return DropTable(objName);
671  }
672 
673  public ObjectName ResolveName(ObjectName objName, bool ignoreCase) {
674  // Is it a visible table (match case insensitive)
675  var table = FindVisibleTable(objName, ignoreCase);
676  if (table != null)
677  return table.TableInfo.TableName;
678 
679  // Is it an internal table?
680  string tschema = objName.ParentName;
681  string tname = objName.Name;
682  var list = GetDynamicTables();
683 
684  var comparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
685  foreach (var ctable in list) {
686  if (String.Equals(ctable.ParentName, tschema, comparison) &&
687  String.Equals(ctable.Name, tname, comparison)) {
688  return ctable;
689  }
690  }
691 
692  // No matches so return the original object.
693  return objName;
694  }
695 
696  public bool DropTable(ObjectName tableName) {
697  var source = FindVisibleTable(tableName, false);
698  if (source == null)
699  return false;
700 
701  // Removes this table from the visible table list of this transaction
702  RemoveVisibleTable(source);
703 
704  // Log in the journal that this transaction touched the table_id.
705  int tableId = source.TableId;
706  Transaction.Registry.RegisterEvent(new TableDroppedEvent(tableId, tableName));
707 
708  Transaction.RemoveNativeSequence(tableName);
709 
710  return true;
711  }
712 
713  public void AssertConstraints(ObjectName tableName) {
714  throw new NotImplementedException();
715  }
716 
717  public void AddInternalTables(ITableContainer container) {
718  if (internalTables == null)
719  internalTables = new List<ITableContainer>();
720 
721  internalTables.Add(container);
722  }
723 
724  internal IEnumerable<ITableSource> GetVisibleTables() {
725  return visibleTables.ToArray();
726  }
727 
728  internal void AddVisibleTables(IEnumerable<TableSource> tableSources, IEnumerable<IIndexSet> indexSets) {
729  var tableList = tableSources.ToList();
730  var indexSetList = indexSets.ToList();
731  for (int i = 0; i < tableList.Count; i++) {
732  AddVisibleTable(tableList[i], indexSetList[i]);
733  }
734  }
735 
736  public IEnumerable<ObjectName> GetTableNames() {
737  var result = (visibleTables
738  .Where(tableSource => tableSource != null)
739  .Select(tableSource => tableSource.TableInfo.TableName)).ToList();
740 
741  var dynamicTables = GetDynamicTables();
742  if (dynamicTables != null)
743  result.AddRange(dynamicTables);
744 
745  return result.ToArray();
746  }
747  }
748 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
String GetTableType(ObjectName tableName)
void AssertConstraints(ObjectName tableName)
bool AlterObject(IObjectInfo objInfo)
Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specif...
bool TableExists(ObjectName tableName)
bool DropObject(ObjectName objName)
Deletes a database object handled by this manager from the system.
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
ITable GetTable(ObjectName tableName)
SqlNumber SetUniqueId(ObjectName tableName, SqlNumber value)
A long string in the system.
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
void FlushTableCache(ObjectName tableName)
void SetIndexSetForTable(ITableSource source, IIndexSet indexSet)
bool RealObjectExists(ObjectName objName)
Checks if an object really exists in the system.
string GetDynamicTableType(ObjectName tableName)
void UpdateVisibleTable(TableSource table, IIndexSet indexSet)
Represents a database object, such as a table, a trigger, a type or a column.
Definition: IDbObject.cs:24
void CreateTemporaryTable(TableInfo tableInfo)
IMutableTable CreateTableAtCommit(ITransaction transaction)
static BinaryType Binary(int maxSize)
static readonly ObjectName CheckInfoTableName
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static readonly ObjectName PrimaryKeyInfoTableName
void CreateTable(TableInfo tableInfo)
static readonly ObjectName UniqueKeyInfoTableName
ITable GetDynamicTable(ObjectName tableName)
void AddVisibleTables(IEnumerable< TableSource > tableSources, IEnumerable< IIndexSet > indexSets)
bool AlterTable(TableInfo tableInfo)
static readonly ObjectName UniqueKeyColumnsTableName
RecordState
An enumeration that represents the various states of a record.
Definition: RecordState.cs:23
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
A new table was created during a transaction.
static readonly ObjectName ForeignKeyInfoTableName
bool RealTableExists(ObjectName tableName)
bool DropTable(ObjectName tableName)
static readonly ObjectName ForeignKeyColumnsTableName
void RemoveVisibleTable(ITableSource table)
static NumericType Numeric()
void CreateObject(IObjectInfo objInfo)
Create a new object of the ObjectType given the specifications given.
List< ITableSource > selectedTables
Definition: TableManager.cs:30
Provides the constant names of the types of tables in a database system.
Definition: TableTypes.cs:24
TableInfo AsReadOnly()
Creates a new instance of TableInfo as an immutable copy of this table metadata.
Definition: TableInfo.cs:342
ObjectName ResolveName(ObjectName objName, bool ignoreCase)
Normalizes the input object name using the case sensitivity specified.
void AddInternalTables(ITableContainer container)
A table was accessed during the transaction.
TableInfo GetDynamicTableInfo(ObjectName tableName)
void Create()
Initializes the manager into the underlying system.
ObjectName TryResolveCase(ObjectName tableName)
A container for any system tables that are generated from information inside the database engine...
TableInfo GetTableInfo(ObjectName tableName)
Provides utilities and properties for handling the SYSTEN schema of a database.
Definition: SystemSchema.cs:37
IIndexSet GetIndexSetForTable(ITableSource tableSource)
SqlNumber NextUniqueId(ObjectName tableName)
DbObjectType ObjectType
Gets the type of objects managed by this instance.
An object that access to a set of indexes.
Definition: IIndexSet.cs:27
int IndexOfColumn(string columnName)
Gets the offset of the column with the given name.
Definition: TableInfo.cs:310
IEnumerable< ITableSource > GetVisibleTables()
long IConvertible. ToInt64(IFormatProvider provider)
Definition: SqlNumber.cs:305
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
IEnumerable< ObjectName > GetTableNames()
const string Table
Definition: TableTypes.cs:25
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
static readonly ObjectName PrimaryKeyColumnsTableName
int ColumnCount
Gets a count of the columns defined by this object.
Definition: TableInfo.cs:159
IDbObject GetObject(ObjectName objName)
Gets a database object managed by this manager.
bool ObjectExists(ObjectName objName)
Checks if an object identified by the given name is managed by this instance.
readonly Dictionary< ObjectName, IMutableTable > tableCache
Definition: TableManager.cs:34
IMutableTable CreateTableAtCommit(ITableSource source)
List< ITableContainer > internalTables
Definition: TableManager.cs:32
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
readonly List< IIndexSet > tableIndices
Definition: TableManager.cs:31
void AddVisibleTable(ITableSource table, IIndexSet indexSet)
bool IsDynamicTable(ObjectName tableName)
Defines the contract for the business managers of database objects of a given type.
The simplest implementation of a transaction.
Definition: ITransaction.cs:30
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
static int IndexOfTable(IList< ITableSource > sources, int tableId)
void SelectTable(ObjectName tableName)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
void CreateTable(TableInfo tableInfo, bool temporary)
TableManager(ITransaction transaction, ITableSourceComposite composite)
Definition: TableManager.cs:38
void CompactTable(ObjectName tableName)
void CopyTable(ITableSource tableSource, IIndexSet indexSet)
List< IMutableTable > accessedTables
Definition: TableManager.cs:29
An interface that defines contracts to alter the contents of a table.
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
IMutableTable GetMutableTable(ObjectName tableName)