DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Package Functions | Properties | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Deveel.Data.Sql.Tables.TableManager Class Reference
Inheritance diagram for Deveel.Data.Sql.Tables.TableManager:
Deveel.Data.Sql.IObjectManager

Public Member Functions

 TableManager (ITransaction transaction, ITableSourceComposite composite)
 
void Dispose ()
 
void Create ()
 Initializes the manager into the underlying system. More...
 
void CreateTable (TableInfo tableInfo)
 
void CreateTable (TableInfo tableInfo, bool temporary)
 
void CreateTemporaryTable (TableInfo tableInfo)
 
void SelectTable (ObjectName tableName)
 
void CompactTable (ObjectName tableName)
 
SqlNumber SetUniqueId (ObjectName tableName, SqlNumber value)
 
SqlNumber NextUniqueId (ObjectName tableName)
 
bool RealTableExists (ObjectName tableName)
 
bool TableExists (ObjectName tableName)
 
ITable GetTable (ObjectName tableName)
 
String GetTableType (ObjectName tableName)
 
ObjectName TryResolveCase (ObjectName tableName)
 
IMutableTable GetMutableTable (ObjectName tableName)
 
TableInfo GetTableInfo (ObjectName tableName)
 
bool AlterTable (TableInfo tableInfo)
 
ObjectName ResolveName (ObjectName objName, bool ignoreCase)
 Normalizes the input object name using the case sensitivity specified. More...
 
bool DropTable (ObjectName tableName)
 
void AssertConstraints (ObjectName tableName)
 
void AddInternalTables (ITableContainer container)
 
IEnumerable< ObjectNameGetTableNames ()
 

Package Functions

IIndexSet GetIndexSetForTable (ITableSource tableSource)
 
void RemoveVisibleTable (ITableSource table)
 
void UpdateVisibleTable (TableSource table, IIndexSet indexSet)
 
IEnumerable< ITableSourceGetVisibleTables ()
 
void AddVisibleTables (IEnumerable< TableSource > tableSources, IEnumerable< IIndexSet > indexSets)
 

Properties

ITransaction Transaction [get, private set]
 
ITableSourceComposite Composite [get, set]
 
IEnumerable< IMutableTableAccessedTables [get]
 
IEnumerable< ITableSourceSelectedTables [get]
 
bool IgnoreIdentifiersCase [get]
 
DbObjectType IObjectManager. ObjectType [get]
 
- Properties inherited from Deveel.Data.Sql.IObjectManager
DbObjectType ObjectType [get]
 Gets the type of objects managed by this instance. More...
 

Private Member Functions

 ~TableManager ()
 
void DisposeAllIndices ()
 
void DisposeTouchedTables ()
 
void Dispose (bool disposing)
 
void IObjectManager. CreateObject (IObjectInfo objInfo)
 Create a new object of the ObjectType given the specifications given. More...
 
void CopyTable (ITableSource tableSource, IIndexSet indexSet)
 
void AddVisibleTable (ITableSource table, IIndexSet indexSet)
 
ITableSource FindVisibleTable (ObjectName tableName, bool ignoreCase)
 
bool IsDynamicTable (ObjectName tableName)
 
ITable GetDynamicTable (ObjectName tableName)
 
string GetDynamicTableType (ObjectName tableName)
 
bool IObjectManager. RealObjectExists (ObjectName objName)
 Checks if an object really exists in the system. More...
 
bool IObjectManager. ObjectExists (ObjectName objName)
 Checks if an object identified by the given name is managed by this instance. More...
 
IDbObject IObjectManager. GetObject (ObjectName objName)
 Gets a database object managed by this manager. More...
 
ObjectName[] GetDynamicTables ()
 
TableInfo GetDynamicTableInfo (ObjectName tableName)
 
IMutableTable CreateTableAtCommit (ITableSource source)
 
bool IObjectManager. AlterObject (IObjectInfo objInfo)
 Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specification, with the format given. More...
 
void FlushTableCache (ObjectName tableName)
 
void SetIndexSetForTable (ITableSource source, IIndexSet indexSet)
 
bool IObjectManager. DropObject (ObjectName objName)
 Deletes a database object handled by this manager from the system. More...
 

Static Private Member Functions

static int IndexOfTable (IList< ITableSource > sources, int tableId)
 

Private Attributes

readonly List< ITableSourcevisibleTables
 
List< IMutableTableaccessedTables
 
List< ITableSourceselectedTables
 
readonly List< IIndexSettableIndices
 
List< ITableContainerinternalTables
 
readonly Dictionary< ObjectName, IMutableTabletableCache
 
List< object > cleanupQueue
 

Detailed Description

Definition at line 27 of file TableManager.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Tables.TableManager.TableManager ( ITransaction  transaction,
ITableSourceComposite  composite 
)
inline

Definition at line 38 of file TableManager.cs.

38  {
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  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
ITableSourceComposite Composite
Definition: TableManager.cs:59
List< ITableSource > selectedTables
Definition: TableManager.cs:30
readonly Dictionary< ObjectName, IMutableTable > tableCache
Definition: TableManager.cs:34
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
readonly List< IIndexSet > tableIndices
Definition: TableManager.cs:31
List< IMutableTable > accessedTables
Definition: TableManager.cs:29
Deveel.Data.Sql.Tables.TableManager.~TableManager ( )
inlineprivate

Definition at line 53 of file TableManager.cs.

53  {
54  Dispose(true);
55  }

Member Function Documentation

void Deveel.Data.Sql.Tables.TableManager.AddInternalTables ( ITableContainer  container)
inline

Definition at line 717 of file TableManager.cs.

717  {
718  if (internalTables == null)
719  internalTables = new List<ITableContainer>();
720 
721  internalTables.Add(container);
722  }
List< ITableContainer > internalTables
Definition: TableManager.cs:32
void Deveel.Data.Sql.Tables.TableManager.AddVisibleTable ( ITableSource  table,
IIndexSet  indexSet 
)
inlineprivate

Definition at line 307 of file TableManager.cs.

307  {
308  if (Transaction.ReadOnly())
309  throw new Exception("Transaction is Read-only.");
310 
311  visibleTables.Add(table);
312  tableIndices.Add(indexSet);
313  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
readonly List< IIndexSet > tableIndices
Definition: TableManager.cs:31
void Deveel.Data.Sql.Tables.TableManager.AddVisibleTables ( IEnumerable< TableSource tableSources,
IEnumerable< IIndexSet indexSets 
)
inlinepackage

Definition at line 728 of file TableManager.cs.

728  {
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  }
void AddVisibleTable(ITableSource table, IIndexSet indexSet)
bool IObjectManager. Deveel.Data.Sql.Tables.TableManager.AlterObject ( IObjectInfo  objInfo)
inlineprivate

Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specification, with the format given.

Parameters
objInfoThe object specification used to alter an existing object.
Returns
Returns true an object was identified and successfully altered, or false if none database object was found for the unique name given.
Exceptions
ArgumentNullExceptionIf the given objInfo object is null.
ArgumentExceptionIf the type of the object specified (IObjectInfo.ObjectType) is different than the type of objects handled by this manager.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 557 of file TableManager.cs.

557  {
558  var tableInfo = objInfo as TableInfo;
559  if (tableInfo == null)
560  throw new ArgumentException();
561 
562  return AlterTable(tableInfo);
563  }
bool AlterTable(TableInfo tableInfo)
bool Deveel.Data.Sql.Tables.TableManager.AlterTable ( TableInfo  tableInfo)
inline

Definition at line 565 of file TableManager.cs.

565  {
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  }
ITable GetTable(ObjectName tableName)
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)
void CreateTable(TableInfo tableInfo)
RecordState
An enumeration that represents the various states of a record.
Definition: RecordState.cs:23
A new table was created during a transaction.
bool DropTable(ObjectName tableName)
SqlNumber NextUniqueId(ObjectName tableName)
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
IMutableTable GetMutableTable(ObjectName tableName)
void Deveel.Data.Sql.Tables.TableManager.AssertConstraints ( ObjectName  tableName)
inline

Definition at line 713 of file TableManager.cs.

713  {
714  throw new NotImplementedException();
715  }
void Deveel.Data.Sql.Tables.TableManager.CompactTable ( ObjectName  tableName)
inline

Definition at line 258 of file TableManager.cs.

258  {
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  }
bool DropTable(ObjectName tableName)
IIndexSet GetIndexSetForTable(ITableSource tableSource)
void CopyTable(ITableSource tableSource, IIndexSet indexSet)
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
void Deveel.Data.Sql.Tables.TableManager.CopyTable ( ITableSource  tableSource,
IIndexSet  indexSet 
)
inlineprivate

Definition at line 277 of file TableManager.cs.

277  {
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  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
ITableSourceComposite Composite
Definition: TableManager.cs:59
A new table was created during a transaction.
ITableSource CopySourceTable(ITableSource tableSource, IIndexSet indexSet)
void AddVisibleTable(ITableSource table, IIndexSet indexSet)
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
void Deveel.Data.Sql.Tables.TableManager.Create ( )
inline

Initializes the manager into the underlying system.

Typically this method generates the tables required to manage the features relative to the objects.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 135 of file TableManager.cs.

135  {
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
147  tableInfo = new TableInfo(SystemSchema.PrimaryKeyColumnsTableName);
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
155  tableInfo = new TableInfo(SystemSchema.ForeignKeyInfoTableName);
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
169  tableInfo = new TableInfo(SystemSchema.ForeignKeyColumnsTableName);
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
178  tableInfo = new TableInfo(SystemSchema.UniqueKeyInfoTableName);
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
188  tableInfo = new TableInfo(SystemSchema.UniqueKeyColumnsTableName);
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  }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
static BinaryType Binary(int maxSize)
static NumericType Numeric()
void IObjectManager. Deveel.Data.Sql.Tables.TableManager.CreateObject ( IObjectInfo  objInfo)
inlineprivate

Create a new object of the ObjectType given the specifications given.

Parameters
objInfoThe object specifications used to create a new object.
Exceptions
ArgumentNullExceptionIf the given objInfo is null.
ArgumentExceptionIf the object type of the specification (IObjectInfo.ObjectType) is different than the ObjectType of this manager.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 208 of file TableManager.cs.

208  {
209  var tableInfo = objInfo as TableInfo;
210  if (tableInfo == null)
211  throw new ArgumentException();
212 
213  CreateTable(tableInfo);
214  }
void CreateTable(TableInfo tableInfo)
void Deveel.Data.Sql.Tables.TableManager.CreateTable ( TableInfo  tableInfo)
inline

Definition at line 216 of file TableManager.cs.

216  {
217  CreateTable(tableInfo, false);
218  }
void CreateTable(TableInfo tableInfo)
void Deveel.Data.Sql.Tables.TableManager.CreateTable ( TableInfo  tableInfo,
bool  temporary 
)
inline

Definition at line 220 of file TableManager.cs.

220  {
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  }
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
ITableSourceComposite Composite
Definition: TableManager.cs:59
ITableSource CreateTableSource(TableInfo tableInfo, bool temporary)
A new table was created during a transaction.
void AddVisibleTable(ITableSource table, IIndexSet indexSet)
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
IMutableTable Deveel.Data.Sql.Tables.TableManager.CreateTableAtCommit ( ITableSource  source)
inlineprivate

Definition at line 546 of file TableManager.cs.

546  {
547  // Create the table for this transaction.
548  var table = source.CreateTableAtCommit(Transaction);
549 
550  accessedTables.Add(table);
551 
552  Transaction.Registry.RegisterEvent(new TableAccessEvent(source.TableId, source.TableInfo.TableName));
553 
554  return table;
555  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
A table was accessed during the transaction.
List< IMutableTable > accessedTables
Definition: TableManager.cs:29
void Deveel.Data.Sql.Tables.TableManager.CreateTemporaryTable ( TableInfo  tableInfo)
inline

Definition at line 239 of file TableManager.cs.

239  {
240  CreateTable(tableInfo, true);
241  }
void CreateTable(TableInfo tableInfo)
void Deveel.Data.Sql.Tables.TableManager.Dispose ( )
inline

Definition at line 77 of file TableManager.cs.

77  {
78  Dispose(true);
79  GC.SuppressFinalize(this);
80  }
void Deveel.Data.Sql.Tables.TableManager.Dispose ( bool  disposing)
inlineprivate

Definition at line 122 of file TableManager.cs.

122  {
123  if (disposing) {
126  }
127 
128  Transaction = null;
129  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
void Deveel.Data.Sql.Tables.TableManager.DisposeAllIndices ( )
inlineprivate

Definition at line 82 of file TableManager.cs.

82  {
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  }
An object that access to a set of indexes.
Definition: IIndexSet.cs:27
readonly List< IIndexSet > tableIndices
Definition: TableManager.cs:31
void Deveel.Data.Sql.Tables.TableManager.DisposeTouchedTables ( )
inlineprivate

Definition at line 108 of file TableManager.cs.

108  {
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  }
List< IMutableTable > accessedTables
Definition: TableManager.cs:29
bool IObjectManager. Deveel.Data.Sql.Tables.TableManager.DropObject ( ObjectName  objName)
inlineprivate

Deletes a database object handled by this manager from the system.

Parameters
objNameThe unique name of the object to be deleted.
Returns
Returns true if a database object was found with the given unique name and successfully deleted from the system, or false if none object was found.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 669 of file TableManager.cs.

669  {
670  return DropTable(objName);
671  }
bool DropTable(ObjectName tableName)
bool Deveel.Data.Sql.Tables.TableManager.DropTable ( ObjectName  tableName)
inline

Definition at line 696 of file TableManager.cs.

696  {
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  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
void RemoveVisibleTable(ITableSource table)
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
ITableSource Deveel.Data.Sql.Tables.TableManager.FindVisibleTable ( ObjectName  tableName,
bool  ignoreCase 
)
inlineprivate

Definition at line 354 of file TableManager.cs.

354  {
355  return visibleTables
356  .FirstOrDefault(source => source != null &&
357  source.TableInfo.TableName.Equals(tableName, ignoreCase));
358  }
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
void Deveel.Data.Sql.Tables.TableManager.FlushTableCache ( ObjectName  tableName)
inlineprivate

Definition at line 653 of file TableManager.cs.

653  {
654  tableCache.Remove(tableName);
655  }
readonly Dictionary< ObjectName, IMutableTable > tableCache
Definition: TableManager.cs:34
ITable Deveel.Data.Sql.Tables.TableManager.GetDynamicTable ( ObjectName  tableName)
inlineprivate

Definition at line 387 of file TableManager.cs.

387  {
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  }
A long string in the system.
List< ITableContainer > internalTables
Definition: TableManager.cs:32
TableInfo Deveel.Data.Sql.Tables.TableManager.GetDynamicTableInfo ( ObjectName  tableName)
inlineprivate

Definition at line 523 of file TableManager.cs.

523  {
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  }
List< ITableContainer > internalTables
Definition: TableManager.cs:32
ObjectName [] Deveel.Data.Sql.Tables.TableManager.GetDynamicTables ( )
inlineprivate

Definition at line 469 of file TableManager.cs.

469  {
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  }
List< ITableContainer > internalTables
Definition: TableManager.cs:32
string Deveel.Data.Sql.Tables.TableManager.GetDynamicTableType ( ObjectName  tableName)
inlineprivate

Definition at line 399 of file TableManager.cs.

399  {
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  }
A long string in the system.
List< ITableContainer > internalTables
Definition: TableManager.cs:32
IIndexSet Deveel.Data.Sql.Tables.TableManager.GetIndexSetForTable ( ITableSource  tableSource)
inlinepackage

Definition at line 296 of file TableManager.cs.

296  {
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  }
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
readonly List< IIndexSet > tableIndices
Definition: TableManager.cs:31
IMutableTable Deveel.Data.Sql.Tables.TableManager.GetMutableTable ( ObjectName  tableName)
inline

Definition at line 512 of file TableManager.cs.

512  {
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  }
ITable GetTable(ObjectName tableName)
IDbObject IObjectManager. Deveel.Data.Sql.Tables.TableManager.GetObject ( ObjectName  objName)
inlineprivate

Gets a database object managed by this manager.

Parameters
objNameThe name that uniquely identifies the object to get.
Returns
Returns a IDbObject instance that is identified by the given unique name, or null if this manager was not able to map any object to the name specified.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 429 of file TableManager.cs.

429  {
430  return GetTable(objName);
431  }
ITable GetTable(ObjectName tableName)
ITable Deveel.Data.Sql.Tables.TableManager.GetTable ( ObjectName  tableName)
inline

Definition at line 433 of file TableManager.cs.

433  {
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  }
ITable GetDynamicTable(ObjectName tableName)
readonly Dictionary< ObjectName, IMutableTable > tableCache
Definition: TableManager.cs:34
IMutableTable CreateTableAtCommit(ITableSource source)
bool IsDynamicTable(ObjectName tableName)
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
TableInfo Deveel.Data.Sql.Tables.TableManager.GetTableInfo ( ObjectName  tableName)
inline

Definition at line 535 of file TableManager.cs.

535  {
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  }
TableInfo GetDynamicTableInfo(ObjectName tableName)
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
bool IsDynamicTable(ObjectName tableName)
IEnumerable<ObjectName> Deveel.Data.Sql.Tables.TableManager.GetTableNames ( )
inline

Definition at line 736 of file TableManager.cs.

736  {
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  }
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
String Deveel.Data.Sql.Tables.TableManager.GetTableType ( ObjectName  tableName)
inline

Definition at line 456 of file TableManager.cs.

456  {
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  }
string GetDynamicTableType(ObjectName tableName)
bool IsDynamicTable(ObjectName tableName)
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
IEnumerable<ITableSource> Deveel.Data.Sql.Tables.TableManager.GetVisibleTables ( )
inlinepackage

Definition at line 724 of file TableManager.cs.

724  {
725  return visibleTables.ToArray();
726  }
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
static int Deveel.Data.Sql.Tables.TableManager.IndexOfTable ( IList< ITableSource sources,
int  tableId 
)
inlinestaticprivate

Definition at line 315 of file TableManager.cs.

315  {
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  }
bool Deveel.Data.Sql.Tables.TableManager.IsDynamicTable ( ObjectName  tableName)
inlineprivate

Definition at line 380 of file TableManager.cs.

380  {
381  if (internalTables == null)
382  return false;
383 
384  return internalTables.Any(info => info != null && info.ContainsTable(tableName));
385  }
List< ITableContainer > internalTables
Definition: TableManager.cs:32
SqlNumber Deveel.Data.Sql.Tables.TableManager.NextUniqueId ( ObjectName  tableName)
inline

Definition at line 370 of file TableManager.cs.

370  {
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  }
A long string in the system.
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
bool IObjectManager. Deveel.Data.Sql.Tables.TableManager.ObjectExists ( ObjectName  objName)
inlineprivate

Checks if an object identified by the given name is managed by this instance.

Parameters
objNameThe name that uniquely identifies the object.
Returns

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 420 of file TableManager.cs.

420  {
421  return TableExists(objName);
422  }
bool TableExists(ObjectName tableName)
bool IObjectManager. Deveel.Data.Sql.Tables.TableManager.RealObjectExists ( ObjectName  objName)
inlineprivate

Checks if an object really exists in the system.

Parameters
objNameThe unique name of the object to check.
Returns
Returns true if an object with the given name concretely exists in the system, or false otherwise.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 412 of file TableManager.cs.

412  {
413  return RealTableExists(objName);
414  }
bool RealTableExists(ObjectName tableName)
bool Deveel.Data.Sql.Tables.TableManager.RealTableExists ( ObjectName  tableName)
inline

Definition at line 416 of file TableManager.cs.

416  {
417  return FindVisibleTable(tableName, false) != null;
418  }
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
void Deveel.Data.Sql.Tables.TableManager.RemoveVisibleTable ( ITableSource  table)
inlinepackage

Definition at line 325 of file TableManager.cs.

325  {
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  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
An object that access to a set of indexes.
Definition: IIndexSet.cs:27
readonly Dictionary< ObjectName, IMutableTable > tableCache
Definition: TableManager.cs:34
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
readonly List< IIndexSet > tableIndices
Definition: TableManager.cs:31
static int IndexOfTable(IList< ITableSource > sources, int tableId)
ObjectName Deveel.Data.Sql.Tables.TableManager.ResolveName ( ObjectName  objName,
bool  ignoreCase 
)
inline

Normalizes the input object name using the case sensitivity specified.

Parameters
objNameThe input object name, that can be partial or complete, to be normalized to the real name of an object.
ignoreCaseThe case sensitivity specification used to compare the input name with the names of the existing objects handled by this manager.
Returns
Returns the fully normalized ObjectName that is the real name of an object matching the input name, or null if the input name was not possible to be resolved.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 673 of file TableManager.cs.

673  {
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  }
A long string in the system.
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
void Deveel.Data.Sql.Tables.TableManager.SelectTable ( ObjectName  tableName)
inline

Definition at line 243 of file TableManager.cs.

243  {
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  }
List< ITableSource > selectedTables
Definition: TableManager.cs:30
bool IsDynamicTable(ObjectName tableName)
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
void Deveel.Data.Sql.Tables.TableManager.SetIndexSetForTable ( ITableSource  source,
IIndexSet  indexSet 
)
inlineprivate

Definition at line 657 of file TableManager.cs.

657  {
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  }
readonly List< ITableSource > visibleTables
Definition: TableManager.cs:28
readonly List< IIndexSet > tableIndices
Definition: TableManager.cs:31
SqlNumber Deveel.Data.Sql.Tables.TableManager.SetUniqueId ( ObjectName  tableName,
SqlNumber  value 
)
inline

Definition at line 360 of file TableManager.cs.

360  {
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  }
A long string in the system.
long IConvertible. ToInt64(IFormatProvider provider)
Definition: SqlNumber.cs:305
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
bool Deveel.Data.Sql.Tables.TableManager.TableExists ( ObjectName  tableName)
inline

Definition at line 424 of file TableManager.cs.

424  {
425  return IsDynamicTable(tableName) ||
426  RealTableExists(tableName);
427  }
bool RealTableExists(ObjectName tableName)
bool IsDynamicTable(ObjectName tableName)
ObjectName Deveel.Data.Sql.Tables.TableManager.TryResolveCase ( ObjectName  tableName)
inline

Definition at line 487 of file TableManager.cs.

487  {
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  }
A long string in the system.
ITableSource FindVisibleTable(ObjectName tableName, bool ignoreCase)
void Deveel.Data.Sql.Tables.TableManager.UpdateVisibleTable ( TableSource  table,
IIndexSet  indexSet 
)
inlinepackage

Definition at line 346 of file TableManager.cs.

346  {
347  if (Transaction.ReadOnly())
348  throw new Exception("Transaction is Read-only.");
349 
350  RemoveVisibleTable(table);
351  AddVisibleTable(table, indexSet);
352  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
void RemoveVisibleTable(ITableSource table)
void AddVisibleTable(ITableSource table, IIndexSet indexSet)

Member Data Documentation

List<IMutableTable> Deveel.Data.Sql.Tables.TableManager.accessedTables
private

Definition at line 29 of file TableManager.cs.

List<object> Deveel.Data.Sql.Tables.TableManager.cleanupQueue
private

Definition at line 36 of file TableManager.cs.

List<ITableContainer> Deveel.Data.Sql.Tables.TableManager.internalTables
private

Definition at line 32 of file TableManager.cs.

List<ITableSource> Deveel.Data.Sql.Tables.TableManager.selectedTables
private

Definition at line 30 of file TableManager.cs.

readonly Dictionary<ObjectName, IMutableTable> Deveel.Data.Sql.Tables.TableManager.tableCache
private

Definition at line 34 of file TableManager.cs.

readonly List<IIndexSet> Deveel.Data.Sql.Tables.TableManager.tableIndices
private

Definition at line 31 of file TableManager.cs.

readonly List<ITableSource> Deveel.Data.Sql.Tables.TableManager.visibleTables
private

Definition at line 28 of file TableManager.cs.

Property Documentation

IEnumerable<IMutableTable> Deveel.Data.Sql.Tables.TableManager.AccessedTables
getpackage

Definition at line 61 of file TableManager.cs.

ITableSourceComposite Deveel.Data.Sql.Tables.TableManager.Composite
getsetprivate

Definition at line 59 of file TableManager.cs.

bool Deveel.Data.Sql.Tables.TableManager.IgnoreIdentifiersCase
getprivate

Definition at line 73 of file TableManager.cs.

DbObjectType IObjectManager. Deveel.Data.Sql.Tables.TableManager.ObjectType
getprivate

Definition at line 131 of file TableManager.cs.

IEnumerable<ITableSource> Deveel.Data.Sql.Tables.TableManager.SelectedTables
getpackage

Definition at line 65 of file TableManager.cs.

ITransaction Deveel.Data.Sql.Tables.TableManager.Transaction
getprivate set

Definition at line 57 of file TableManager.cs.


The documentation for this class was generated from the following file: