DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Transactions.TransactionTable Class Reference
Inheritance diagram for Deveel.Data.Transactions.TransactionTable:
Deveel.Data.Sql.Tables.IMutableTable Deveel.Data.Transactions.ILockable Deveel.Data.Sql.Tables.ITable Deveel.Data.Sql.IDbObject

Classes

class  RowEnumerator
 

Public Member Functions

 TransactionTable (ITransaction transaction, TableSource tableSource, TableEventRegistry eventRegistry)
 
DataObject GetValue (long rowNumber, int columnOffset)
 Gets a single cell within the table that is located at the given column offset and row. More...
 
ColumnIndex GetIndex (int columnOffset)
 Gets an index for given column that can be used to select values from this table. More...
 
IEnumerator< RowGetEnumerator ()
 
void Dispose ()
 
RowId AddRow (Row row)
 Persists a new row to the table. More...
 
void UpdateRow (Row row)
 Updates the values of a row into the table. More...
 
bool RemoveRow (RowId rowId)
 Deletes row identified by the given coordinates from the table. More...
 
void FlushIndexes ()
 Flushes all changes made on this table to the backing index scheme. More...
 
void AssertConstraints ()
 Performs all constraint integrity checks and actions to any modifications based on any changes that happened to the table since that last call to this method. More...
 
void AddLock ()
 
void RemoveLock ()
 

Properties

int ColumnCount [get]
 
IContext Context [get, private set]
 
TableInfo TableInfo [get]
 
int RowCount [get]
 
IIndex RowIndex [get]
 
ITransaction Transaction [get, private set]
 
TableSource TableSource [get, private set]
 
TableEventRegistry EventRegistry [get, private set]
 
int TableId [get]
 
ObjectName FullName [get]
 
DbObjectType ObjectType [get]
 
object ILockable. RefId [get]
 
- Properties inherited from Deveel.Data.Sql.Tables.IMutableTable
TableEventRegistry EventRegistry [get]
 
- Properties inherited from Deveel.Data.Sql.Tables.ITable
IContext Context [get]
 
TableInfo TableInfo [get]
 Gets the metadata information of the table, used to resolve the column sources. More...
 
int RowCount [get]
 Gets the total number of rows in the table. More...
 
- Properties inherited from Deveel.Data.Sql.IDbObject
ObjectName FullName [get]
 Gets the fully qualified name of the object used to resolve it uniquely within the database. More...
 
DbObjectType ObjectType [get]
 Gets the type of database object that the implementation is for More...
 
- Properties inherited from Deveel.Data.Transactions.ILockable
object RefId [get]
 

Private Member Functions

 ~TransactionTable ()
 
void AssertNotDisposed ()
 
void EnsureRowIndexListCurrent ()
 
void EnsureColumnIndexCurrent (int column)
 
IEnumerator IEnumerable. GetEnumerator ()
 
void Dispose (bool disposing)
 
void ExecuteUpdateReferentialAction (ConstraintInfo constraint, DataObject[] originalKey, DataObject[] newKey, IQuery context)
 
void ExecuteDeleteReferentialAction (ConstraintInfo constraint, DataObject[] originalKey, IQuery context)
 
void ILockable. Released (Lock @lock)
 
void ILockable. Acquired (Lock @lock)
 

Private Attributes

int rowListRebuild
 
IIndex rowIndex
 
int[] indexRebuilds
 
IIndexSet indexSet
 
ColumnIndex[] columnIndexes
 
int lastEntryRICheck
 
bool disposed
 

Detailed Description

Definition at line 28 of file TransactionTable.cs.

Constructor & Destructor Documentation

Deveel.Data.Transactions.TransactionTable.TransactionTable ( ITransaction  transaction,
TableSource  tableSource,
TableEventRegistry  eventRegistry 
)
inline

Definition at line 40 of file TransactionTable.cs.

40  {
41  Transaction = transaction;
42  TableSource = tableSource;
43  EventRegistry = eventRegistry;
44  Context = tableSource.DatabaseContext;
45  indexSet = transaction.GetTableManager().GetIndexSetForTable(tableSource);
46  rowListRebuild = 0;
47 
48  var colCount = ColumnCount;
49  indexRebuilds = new int[colCount];
50  columnIndexes = new ColumnIndex[colCount];
51  lastEntryRICheck = eventRegistry.EventCount;
52  }
Deveel.Data.Transactions.TransactionTable.~TransactionTable ( )
inlineprivate

Definition at line 54 of file TransactionTable.cs.

54  {
55  Dispose(false);
56  }

Member Function Documentation

void ILockable. Deveel.Data.Transactions.TransactionTable.Acquired ( Lock lock)
inlineprivate

Implements Deveel.Data.Transactions.ILockable.

Definition at line 660 of file TransactionTable.cs.

660  {
661  // TODO: increment a count ref to prevent disposal?
662  }
void Deveel.Data.Transactions.TransactionTable.AddLock ( )
inline
RowId Deveel.Data.Transactions.TransactionTable.AddRow ( Row  row)
inline

Persists a new row to the table.

The row to be added must belong to the table context, otherwise an exception will be thrown.

Parameters
rowThe row to be persisted.
Returns
Returns a RowId that is the pointer to the row established in the table.
Exceptions
ArgumentExceptionIf the gven row does not belong to the table context.
ArgumentNullExceptionIf the given row is null.

Implements Deveel.Data.Sql.Tables.IMutableTable.

Definition at line 243 of file TransactionTable.cs.

243  {
245 
246  if (Transaction.ReadOnly())
247  throw new Exception("Transaction is Read only.");
248 
250  throw new InvalidOperationException("Can not add row - table is read-only.");
251 
252  int rowNum;
253  try {
254  rowNum = TableSource.AddRow(row);
255  } catch (Exception ex) {
256  throw new InvalidOperationException(
257  String.Format("Unknown error when adding a row to the table '{0}'.", TableInfo.TableName), ex);
258  }
259 
260  row.SetRowNumber(rowNum);
261 
262  // Note this doesn't need to be synchronized because we are exclusive on
263  // this table.
264 
265  EventRegistry.Register(new TableRowEvent(TableId, rowNum, TableRowEventType.Add));
266 
267  return new RowId(TableId, rowNum);
268  }
A long string in the system.
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
Defines the value of a ROWID object, that is a unique reference within a database system to a single ...
Definition: RowId.cs:24
void SetRowNumber(int rowNumber)
Sets the number component of the ID of this column.
Definition: Row.cs:484
void Register(ITableEvent tableEvent)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
TableRowEventType
The kind of events that can happen on a table row during the life-time of a transaction.
void Deveel.Data.Transactions.TransactionTable.AssertConstraints ( )
inline

Performs all constraint integrity checks and actions to any modifications based on any changes that happened to the table since that last call to this method.

It is important that is called after any call to AddRow, RemoveRow or UpdateRow.

Any constraints that are marked as ConstraintDeferrability.InitiallyImmediate are checked when this is called, otherwise the constraint is checked at commit time.

Any referential actions are performed when this method is called. If a referential action causes a modification to another table, this method is recursively called on the table modified.

If a referential integrity constraint is violated and a referential action is unable to maintain the integrity of the database, any changes made to the table are reverted.

Implements Deveel.Data.Sql.Tables.IMutableTable.

Definition at line 414 of file TransactionTable.cs.

414  {
416 
417  try {
418  // Early exit condition
420  return;
421 
422  // This table name
423  var tableInfo = TableInfo;
424  var tName = tableInfo.TableName;
425 
426  using (var session = new SystemSession(Transaction, tName.ParentName)) {
427  using (var context = session.CreateQuery()) {
428 
429  // Are there any added, deleted or updated entries in the journal since
430  // we last checked?
431  List<int> rowsUpdated = new List<int>();
432  List<int> rowsDeleted = new List<int>();
433  List<int> rowsAdded = new List<int>();
434 
435  var events = EventRegistry.Skip(lastEntryRICheck);
436  foreach (var tableEvent in events.OfType<TableRowEvent>()) {
437  var rowNum = tableEvent.RowNumber;
438  if (tableEvent.EventType == TableRowEventType.Remove ||
439  tableEvent.EventType == TableRowEventType.UpdateRemove) {
440  rowsDeleted.Add(rowNum);
441 
442  var index = rowsAdded.IndexOf(rowNum);
443  if (index != -1)
444  rowsAdded.RemoveAt(index);
445  } else if (tableEvent.EventType == TableRowEventType.Add ||
446  tableEvent.EventType == TableRowEventType.UpdateAdd) {
447  rowsAdded.Add(rowNum);
448  }
449 
450  if (tableEvent.EventType == TableRowEventType.UpdateAdd ||
451  tableEvent.EventType == TableRowEventType.UpdateRemove)
452  rowsUpdated.Add(rowNum);
453  }
454 
455  // Were there any updates or deletes?
456  if (rowsDeleted.Count > 0) {
457  // Get all references on this table
458  var foreignConstraints = Transaction.QueryTableImportedForeignKeys(tName);
459 
460  // For each foreign constraint
461  foreach (var constraint in foreignConstraints) {
462  // For each deleted/updated record in the table,
463  foreach (var rowNum in rowsDeleted) {
464  // What was the key before it was updated/deleted
465  var cols = tableInfo.IndexOfColumns(constraint.ForeignColumnNames).ToArray();
466 
467  var originalKey = new DataObject[cols.Length];
468  int nullCount = 0;
469  for (int p = 0; p < cols.Length; ++p) {
470  originalKey[p] = GetValue(rowNum, cols[p]);
471  if (originalKey[p].IsNull) {
472  ++nullCount;
473  }
474  }
475 
476  // Check the original key isn't null
477  if (nullCount != cols.Length) {
478  // Is is an update?
479  int updateIndex = rowsUpdated.IndexOf(rowNum);
480  if (updateIndex != -1) {
481  // Yes, this is an update
482  int rowIndexAdd = rowsUpdated[updateIndex + 1];
483 
484  // It must be an update, so first see if the change caused any
485  // of the keys to change.
486  bool keyChanged = false;
487  var keyUpdatedTo = new DataObject[cols.Length];
488  for (int p = 0; p < cols.Length; ++p) {
489  keyUpdatedTo[p] = GetValue(rowIndexAdd, cols[p]);
490  if (originalKey[p].CompareTo(keyUpdatedTo[p]) != 0) {
491  keyChanged = true;
492  }
493  }
494  if (keyChanged) {
495  // Allow the delete, and execute the action,
496  // What did the key update to?
497  ExecuteUpdateReferentialAction(constraint, originalKey, keyUpdatedTo, context);
498  }
499 
500  // If the key didn't change, we don't need to do anything.
501  } else {
502  // No, so it must be a delete,
503  // This will look at the referencee table and if it contains
504  // the key, work out what to do with it.
505  ExecuteDeleteReferentialAction(constraint, originalKey, context);
506  }
507 
508  } // If the key isn't null
509 
510  } // for each deleted rows
511 
512  } // for each foreign key reference to this table
513 
514  }
515 
516  // Were there any rows added (that weren't deleted)?
517  if (rowsAdded.Count > 0) {
518  int[] rowIndices = rowsAdded.ToArray();
519 
520  // Check for any field constraint violations in the added rows
521  Transaction.CheckFieldConstraintViolations(this, rowIndices);
522 
523  // Check this table, adding the given row_index, immediate
524  Transaction.CheckAddConstraintViolations(this, rowIndices, ConstraintDeferrability.InitiallyImmediate);
525  }
526  }
527  }
528  } catch (ConstraintViolationException) {
529  // If a constraint violation, roll back the changes since the last
530  // check.
531  int rollbackPoint = EventRegistry.EventCount - lastEntryRICheck;
532  if (rowListRebuild <= rollbackPoint) {
533  EventRegistry.Rollback(rollbackPoint);
534  } else {
535  // TODO: emit a warning
536  }
537 
538  throw;
539  } finally {
540  // Make sure we update the 'last_entry_ri_check' variable
542  }
543  }
A database exception that represents a constraint violation.
ConstraintDeferrability
The type of deferrance of a constraint.
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
void ExecuteUpdateReferentialAction(ConstraintInfo constraint, DataObject[] originalKey, DataObject[] newKey, IQuery context)
void ExecuteDeleteReferentialAction(ConstraintInfo constraint, DataObject[] originalKey, IQuery context)
DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
TableRowEventType
The kind of events that can happen on a table row during the life-time of a transaction.
void Deveel.Data.Transactions.TransactionTable.AssertNotDisposed ( )
inlineprivate

Definition at line 84 of file TransactionTable.cs.

84  {
85  if (disposed)
86  throw new ObjectDisposedException("Table", "The table was disposed.");
87  }
void Deveel.Data.Transactions.TransactionTable.Dispose ( bool  disposing)
inlineprivate

Definition at line 214 of file TransactionTable.cs.

214  {
215  if (!disposed) {
216  if (disposing) {
217  // Dispose and invalidate the indexes
218  // This is really a safety measure to ensure the index can't be
219  // used outside the scope of the lifetime of this object.
220  if (columnIndexes != null) {
221  foreach (var columnIndex in columnIndexes) {
222  if (columnIndex != null)
223  columnIndex.Dispose();
224  }
225  }
226  }
227 
228  columnIndexes = null;
229  rowIndex = null;
230  EventRegistry = null;
231  indexRebuilds = null;
232  indexSet = null;
233  Transaction = null;
234  disposed = true;
235  }
236  }
void Deveel.Data.Transactions.TransactionTable.Dispose ( )
inline

Definition at line 238 of file TransactionTable.cs.

238  {
239  Dispose(true);
240  GC.SuppressFinalize(this);
241  }
void Deveel.Data.Transactions.TransactionTable.EnsureColumnIndexCurrent ( int  column)
inlineprivate

Definition at line 120 of file TransactionTable.cs.

120  {
121  var index = columnIndexes[column];
122 
123  // NOTE: We should be assured that no Write operations can occur over
124  // this section of code because writes are exclusive operations
125  // within a transaction.
126  // Are there journal entries pending on this scheme since?
127  int rebuildIndex = indexRebuilds[column];
128  int journalCount = EventRegistry.EventCount;
129  while (rebuildIndex < journalCount) {
130  var tableEvent = EventRegistry.GetEvent(rebuildIndex);
131  if (tableEvent is TableRowEvent) {
132  var rowEvent = (TableRowEvent) tableEvent;
133  if (rowEvent.EventType == TableRowEventType.Add ||
134  rowEvent.EventType == TableRowEventType.UpdateAdd) {
135  index.Insert(rowEvent.RowNumber);
136  } else if (rowEvent.EventType == TableRowEventType.Remove ||
137  rowEvent.EventType == TableRowEventType.UpdateRemove) {
138  index.Remove(rowEvent.RowNumber);
139  } else {
140  throw new InvalidOperationException(String.Format("Table row event type {0} is invalid.", rowEvent.EventType));
141  }
142  }
143 
144  ++rebuildIndex;
145  }
146 
147  indexRebuilds[column] = rebuildIndex;
148  }
A long string in the system.
ITableEvent GetEvent(int index)
TableRowEventType
The kind of events that can happen on a table row during the life-time of a transaction.
void Deveel.Data.Transactions.TransactionTable.EnsureRowIndexListCurrent ( )
inlineprivate

Definition at line 89 of file TransactionTable.cs.

89  {
90  int rebuildIndex = rowListRebuild;
91  int journalCount = EventRegistry.EventCount;
92  while (rebuildIndex < journalCount) {
93  var command = EventRegistry.GetEvent(rebuildIndex);
94  if (command is TableRowEvent) {
95  var rowEvent = (TableRowEvent) command;
96  var index = rowEvent.RowNumber;
97 
98  if (rowEvent.EventType == TableRowEventType.Add ||
99  rowEvent.EventType == TableRowEventType.UpdateAdd) {
100  // Add to 'row_list'.
101  if (!RowIndex.UniqueInsertSort(index))
102  throw new InvalidOperationException(String.Format("Row index already used in this table ({0})", index));
103  } else if (rowEvent.EventType == TableRowEventType.Remove ||
104  rowEvent.EventType == TableRowEventType.UpdateRemove) {
105  // Remove from 'row_list'
106  if (!RowIndex.RemoveSort(index))
107  throw new InvalidOperationException("Row index removed that wasn't in this table!");
108  } else {
109  throw new InvalidOperationException(String.Format("Table row event type {0} is invalid.", rowEvent.EventType));
110  }
111  }
112 
113  ++rebuildIndex;
114  }
115 
116  // It's now current (row_list_rebuild == journal_count);
117  rowListRebuild = rebuildIndex;
118  }
A long string in the system.
ITableEvent GetEvent(int index)
TableRowEventType
The kind of events that can happen on a table row during the life-time of a transaction.
void Deveel.Data.Transactions.TransactionTable.ExecuteDeleteReferentialAction ( ConstraintInfo  constraint,
DataObject[]  originalKey,
IQuery  context 
)
inlineprivate

Definition at line 546 of file TransactionTable.cs.

546  {
547  var deleteRule = constraint.OnDelete;
548  if (deleteRule == ForeignKeyAction.NoAction &&
549  constraint.Deferred != ConstraintDeferrability.InitiallyImmediate) {
550  // Constraint check is deferred
551  return;
552  }
553 
554  // So either delete rule is not NO ACTION, or if it is we are initially
555  // immediate.
556  var keyTable = Transaction.GetMutableTable(constraint.TableName);
557  var tableInfo = keyTable.TableInfo;
558  var keyCols = tableInfo.IndexOfColumns(constraint.ColumnNames).ToArray();
559  var keyEntries = keyTable.FindKeys(keyCols, originalKey).ToList();
560 
561  // Are there keys effected?
562  if (keyEntries.Count > 0) {
563  if (deleteRule == ForeignKeyAction.NoAction) {
564  // Throw an exception;
567  constraint.Deferred.AsDebugString() +
568  " foreign key constraint violation on delete (" +
569  constraint.ConstraintName + ") Columns = " +
570  constraint.TableName + "( " +
571  String.Join(", ", constraint.ColumnNames) +
572  " ) -> " + constraint.ForeignTable.FullName + "( " +
573  String.Join(", ", constraint.ForeignColumnNames) +
574  " )");
575  }
576 
577  // Perform a referential action on each updated key
578  foreach (int rowNum in keyEntries) {
579  var dataRow = new Row(keyTable, new RowId(tableInfo.Id, rowNum));
580  dataRow.SetFromTable();
581 
582  if (deleteRule == ForeignKeyAction.Cascade) {
583  // Cascade the removal of the referenced rows
584  keyTable.RemoveRow(dataRow.RowId);
585  } else if (deleteRule == ForeignKeyAction.SetNull) {
586  for (int n = 0; n < keyCols.Length; ++n) {
587  dataRow.SetNull(keyCols[n]);
588  }
589  keyTable.UpdateRow(dataRow);
590  } else if (deleteRule == ForeignKeyAction.SetDefault) {
591  for (int n = 0; n < keyCols.Length; ++n) {
592  dataRow.SetDefault(keyCols[n], context);
593  }
594  keyTable.UpdateRow(dataRow);
595  } else {
596  throw new Exception("Do not understand referential action: " + deleteRule);
597  }
598  }
599 
600  // Check referential integrity of modified table,
601  keyTable.AssertConstraints();
602  }
603 
604  }
Enumerates a known set of codes in a SQL Model
A database exception that represents a constraint violation.
A long string in the system.
ConstraintDeferrability Deferred
ConstraintDeferrability
The type of deferrance of a constraint.
A single row in a table of a database.
Definition: Row.cs:44
ForeignKeyAction
Enumerates the foreign key referential trigger actions.
const int ForeignKeyViolation
A Foreign Key constraint violation error code.
string FullName
Gets the full reference name formatted.
Definition: ObjectName.cs:114
Defines the value of a ROWID object, that is a unique reference within a database system to a single ...
Definition: RowId.cs:24
void Deveel.Data.Transactions.TransactionTable.ExecuteUpdateReferentialAction ( ConstraintInfo  constraint,
DataObject[]  originalKey,
DataObject[]  newKey,
IQuery  context 
)
inlineprivate

Definition at line 351 of file TransactionTable.cs.

352  {
353  var updateRule = constraint.OnUpdate;
354  if (updateRule == ForeignKeyAction.NoAction &&
355  constraint.Deferred != ConstraintDeferrability.InitiallyImmediate) {
356  // Constraint check is deferred
357  return;
358  }
359 
360  // So either update rule is not NO ACTION, or if it is we are initially
361  // immediate.
362  var keyTable = Transaction.GetMutableTable(constraint.TableName);
363  var tableInfo = keyTable.TableInfo;
364  var keyCols = tableInfo.IndexOfColumns(constraint.ColumnNames).ToArray();
365  var keyEntries = keyTable.FindKeys(keyCols, originalKey);
366 
367  // Are there keys effected?
368  if (keyEntries.Any()) {
369  if (updateRule == ForeignKeyAction.NoAction)
370 
371  // Throw an exception;
374  constraint.Deferred.AsDebugString() +
375  " foreign key constraint violation on update (" +
376  constraint.ConstraintName + ") Columns = " +
377  constraint.TableName + "( " +
378  String.Join(", ", constraint.ColumnNames) +
379  " ) -> " + constraint.ForeignTable.FullName + "( " +
380  String.Join(", ", constraint.ForeignColumnNames) +
381  " )");
382 
383  // Perform a referential action on each updated key
384  foreach (int rowNum in keyEntries) {
385  var dataRow = new Row(keyTable, new RowId(keyTable.TableInfo.Id, rowNum));
386  dataRow.SetFromTable();
387 
388  if (updateRule == ForeignKeyAction.Cascade) {
389  // Update the keys
390  for (int n = 0; n < keyCols.Length; ++n) {
391  dataRow.SetValue(keyCols[n], newKey[n]);
392  }
393  keyTable.UpdateRow(dataRow);
394  } else if (updateRule == ForeignKeyAction.SetNull) {
395  for (int n = 0; n < keyCols.Length; ++n) {
396  dataRow.SetNull(keyCols[n]);
397  }
398  keyTable.UpdateRow(dataRow);
399  } else if (updateRule == ForeignKeyAction.SetDefault) {
400  for (int n = 0; n < keyCols.Length; ++n) {
401  dataRow.SetDefault(keyCols[n], context);
402  }
403  keyTable.UpdateRow(dataRow);
404  } else {
405  throw new Exception("Do not understand referential action: " + updateRule);
406  }
407  }
408 
409  // Check referential integrity of modified table,
410  keyTable.AssertConstraints();
411  }
412  }
Enumerates a known set of codes in a SQL Model
A database exception that represents a constraint violation.
A long string in the system.
ConstraintDeferrability Deferred
ConstraintDeferrability
The type of deferrance of a constraint.
A single row in a table of a database.
Definition: Row.cs:44
ForeignKeyAction
Enumerates the foreign key referential trigger actions.
const int ForeignKeyViolation
A Foreign Key constraint violation error code.
string FullName
Gets the full reference name formatted.
Definition: ObjectName.cs:114
Defines the value of a ROWID object, that is a unique reference within a database system to a single ...
Definition: RowId.cs:24
void Deveel.Data.Transactions.TransactionTable.FlushIndexes ( )
inline

Flushes all changes made on this table to the backing index scheme.

This is used during the commit phase of this objects lifetime. The transaction control mechanism has found that there are no clashes and now we need to commit the current table view to the conglomerate. Because this object may not update index information immediately, we call this to flush all the changes to the table to the backing index set.

When this method returns, the backing index-set of this view will be completely up to date.

Implements Deveel.Data.Sql.Tables.IMutableTable.

Definition at line 340 of file TransactionTable.cs.

340  {
342 
344 
345  // This will flush all of the column indexes
346  for (int i = 0; i < columnIndexes.Length; ++i) {
347  GetIndex(i);
348  }
349  }
ColumnIndex GetIndex(int columnOffset)
Gets an index for given column that can be used to select values from this table. ...
IEnumerator<Row> Deveel.Data.Transactions.TransactionTable.GetEnumerator ( )
inline

Definition at line 203 of file TransactionTable.cs.

203  {
204  // Ensure the row list is up to date.
206  var enumerator = RowIndex.GetEnumerator();
207  return new RowEnumerator(this, enumerator);
208  }
IEnumerator IEnumerable. Deveel.Data.Transactions.TransactionTable.GetEnumerator ( )
inlineprivate

Definition at line 210 of file TransactionTable.cs.

210  {
211  return GetEnumerator();
212  }
ColumnIndex Deveel.Data.Transactions.TransactionTable.GetIndex ( int  columnOffset)
inline

Gets an index for given column that can be used to select values from this table.

Parameters
columnOffsetThe zero-based offset of the column which to get the index.
Returns
Returns an instance of ColumnIndex that is used to select a subset of rows from the table.

Implements Deveel.Data.Sql.Tables.ITable.

Definition at line 156 of file TransactionTable.cs.

156  {
158 
159  if (columnOffset < 0 || columnOffset >= ColumnCount)
160  throw new ArgumentOutOfRangeException("columnOffset");
161 
162  var index = columnIndexes[columnOffset];
163 
164  // Cache the scheme in this object.
165  if (index == null) {
166  index = TableSource.CreateColumnIndex(indexSet, this, columnOffset);
167  columnIndexes[columnOffset] = index;
168  }
169 
170  // Update the underlying scheme to the most current version.
171  EnsureColumnIndexCurrent(columnOffset);
172 
173  return index;
174  }
ColumnIndex CreateColumnIndex(IIndexSet indexSet, ITable table, int columnOffset)
DataObject Deveel.Data.Transactions.TransactionTable.GetValue ( long  rowNumber,
int  columnOffset 
)
inline

Gets a single cell within the table that is located at the given column offset and row.

Parameters
rowNumberThe unique number of the row where the cell is located.
columnOffsetThe zero-based offset of the column of the cell to return.
Returns
Returns an instance of DataObject that is contained in the cell located by the row and column coordinates provided.
Exceptions
ArgumentOutOfRangeExceptionIf the given columnOffset is less than zero or greater or equal than the number of columns defined in the table metadata.
See also
Tables.TableInfo.IndexOfColumn(string)

Implements Deveel.Data.Sql.Tables.ITable.

Definition at line 150 of file TransactionTable.cs.

150  {
152 
153  return TableSource.GetValue((int) rowNumber, columnOffset);
154  }
DataObject GetValue(int rowIndex, int columnOffset)
void ILockable. Deveel.Data.Transactions.TransactionTable.Released ( Lock lock)
inlineprivate

Implements Deveel.Data.Transactions.ILockable.

Definition at line 656 of file TransactionTable.cs.

656  {
657  // TODO: decrement a count ref to disposal?
658  }
void Deveel.Data.Transactions.TransactionTable.RemoveLock ( )
inline
bool Deveel.Data.Transactions.TransactionTable.RemoveRow ( RowId  rowId)
inline

Deletes row identified by the given coordinates from the table.

Parameters
rowIdThe unique identifier of the row to be removed.
Returns
Returns true if the row identified was found and removed, false otherwise.
Exceptions
ArgumentExceptionThrown if the given rowId does not belong to this table.

Implements Deveel.Data.Sql.Tables.IMutableTable.

Definition at line 310 of file TransactionTable.cs.

310  {
312 
313  if (rowId.IsNull)
314  throw new ArgumentNullException("rowId");
315 
316  if (rowId.TableId != TableId)
317  throw new ArgumentException("The table part of the ROWID is not this table.");
318  if (rowId.RowNumber < 0)
319  throw new ArgumentException("The number part of the ROWID is not valid for remove.");
320 
321  if (Transaction.ReadOnly())
322  throw new Exception("Transaction is Read only.");
323 
324  // Check this isn't a Read only source
326  throw new InvalidOperationException("Can not remove row - table is Read only.");
327 
328  // NOTE: This must <b>NOT</b> call 'RemoveRow' in TableSource.
329  // We do not want to delete a row permanently from the underlying
330  // file because the transaction using this data source may yet decide
331  // to roll back the change and not delete the row.
332 
333  // Note this doesn't need to be synchronized because we are exclusive on
334  // this table.
335  EventRegistry.Register(new TableRowEvent(rowId.TableId, rowId.RowNumber, TableRowEventType.Remove));
336 
337  return true;
338  }
bool IsNull
Gets a boolean value indicating if the object equivales to a NULL.
Definition: RowId.cs:64
int RowNumber
Gets the number of the column within the table referenced.
Definition: RowId.cs:58
void Register(ITableEvent tableEvent)
int TableId
Gets the unique identifier of the table the row is contained.
Definition: RowId.cs:53
TableRowEventType
The kind of events that can happen on a table row during the life-time of a transaction.
void Deveel.Data.Transactions.TransactionTable.UpdateRow ( Row  row)
inline

Updates the values of a row into the table.

Parameters
rowThe object containing the values to update.
Exceptions
ArgumentNullExceptionIf the given row is null.

Implements Deveel.Data.Sql.Tables.IMutableTable.

Definition at line 270 of file TransactionTable.cs.

270  {
272 
273  if (Transaction.ReadOnly())
274  throw new Exception("Transaction is Read only.");
275 
276  // Check this isn't a Read only source
278  throw new InvalidOperationException("Can not update row - table is read-only.");
279 
280  if (row.RowId.IsNull)
281  throw new ArgumentException("The ROWID cannot be null in an update.");
282 
283  if (row.RowId.TableId != TableId)
284  throw new ArgumentException("The row was not created from this table.");
285 
286  var rowNum = row.RowId.RowNumber;
287 
288  if (rowNum < 0)
289  throw new ArgumentException("The number part of the ROWID is invalid.");
290 
291  // Note this doesn't need to be synchronized because we are exclusive on
292  // this table.
293  EventRegistry.Register(new TableRowEvent(TableId, rowNum, TableRowEventType.UpdateRemove));
294 
295  int newRowIndex;
296 
297  try {
298  newRowIndex = TableSource.AddRow(row);
299  } catch (IOException e) {
300  throw new InvalidOperationException("IO Error: " + e.Message, e);
301  }
302 
303  row.SetRowNumber(newRowIndex);
304 
305  // Note this doesn't need to be synchronized because we are exclusive on
306  // this table.
307  EventRegistry.Register(new TableRowEvent(TableId, newRowIndex, TableRowEventType.UpdateAdd));
308  }
bool IsNull
Gets a boolean value indicating if the object equivales to a NULL.
Definition: RowId.cs:64
int RowNumber
Gets the number of the column within the table referenced.
Definition: RowId.cs:58
void SetRowNumber(int rowNumber)
Sets the number component of the ID of this column.
Definition: Row.cs:484
void Register(ITableEvent tableEvent)
int TableId
Gets the unique identifier of the table the row is contained.
Definition: RowId.cs:53
TableRowEventType
The kind of events that can happen on a table row during the life-time of a transaction.
RowId RowId
Gets the row unique identifier within the database.
Definition: Row.cs:101

Member Data Documentation

ColumnIndex [] Deveel.Data.Transactions.TransactionTable.columnIndexes
private

Definition at line 34 of file TransactionTable.cs.

bool Deveel.Data.Transactions.TransactionTable.disposed
private

Definition at line 38 of file TransactionTable.cs.

int [] Deveel.Data.Transactions.TransactionTable.indexRebuilds
private

Definition at line 32 of file TransactionTable.cs.

IIndexSet Deveel.Data.Transactions.TransactionTable.indexSet
private

Definition at line 33 of file TransactionTable.cs.

int Deveel.Data.Transactions.TransactionTable.lastEntryRICheck
private

Definition at line 36 of file TransactionTable.cs.

IIndex Deveel.Data.Transactions.TransactionTable.rowIndex
private

Definition at line 30 of file TransactionTable.cs.

int Deveel.Data.Transactions.TransactionTable.rowListRebuild
private

Definition at line 29 of file TransactionTable.cs.

Property Documentation

int Deveel.Data.Transactions.TransactionTable.ColumnCount
get

Definition at line 58 of file TransactionTable.cs.

IContext Deveel.Data.Transactions.TransactionTable.Context
getprivate set

Definition at line 65 of file TransactionTable.cs.

TableEventRegistry Deveel.Data.Transactions.TransactionTable.EventRegistry
getprivate set

Definition at line 189 of file TransactionTable.cs.

ObjectName Deveel.Data.Transactions.TransactionTable.FullName
get

Definition at line 195 of file TransactionTable.cs.

DbObjectType Deveel.Data.Transactions.TransactionTable.ObjectType
get

Definition at line 199 of file TransactionTable.cs.

object ILockable. Deveel.Data.Transactions.TransactionTable.RefId
getprivate

Definition at line 652 of file TransactionTable.cs.

int Deveel.Data.Transactions.TransactionTable.RowCount
get

Definition at line 74 of file TransactionTable.cs.

IIndex Deveel.Data.Transactions.TransactionTable.RowIndex
getprivate

Definition at line 176 of file TransactionTable.cs.

int Deveel.Data.Transactions.TransactionTable.TableId
getprivate

Definition at line 191 of file TransactionTable.cs.

TableInfo Deveel.Data.Transactions.TransactionTable.TableInfo
get

Definition at line 67 of file TransactionTable.cs.

TableSource Deveel.Data.Transactions.TransactionTable.TableSource
getprivate set

Definition at line 187 of file TransactionTable.cs.

ITransaction Deveel.Data.Transactions.TransactionTable.Transaction
getprivate set

Definition at line 185 of file TransactionTable.cs.


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