18 using System.Collections.Generic;
29 namespace Deveel.Data.Transactions {
47 Isolation = isolation;
63 this.CurrentSchema(database.
Context.DefaultSchema());
64 this.ReadOnly(database.
Context.ReadOnly());
65 this.AutoCommit(database.
Context.AutoCommit());
66 this.IgnoreIdentifiersCase(database.
Context.IgnoreIdentifiersCase());
91 public int CommitId {
get;
private set; }
95 private bool IsClosed {
get; set; }
102 TableState = tableState;
116 get {
return new Dictionary<string, object> {
152 get {
return this.GetTableManager(); }
185 TableComposite.Commit(
this, visibleTables, selected, touchedTables, Registry, commitActions);
195 if (commitActions == null) {
196 commitActions = action;
198 commitActions = Delegate.Combine(commitActions, action) as Action<TableCommitInfo>;
203 if (commitActions != null)
204 commitActions = Delegate.Remove(commitActions, action) as Action<TableCommitInfo>;
217 }
catch (Exception ex) {
223 if (callbacks != null) {
224 foreach (var callback
in callbacks) {
225 callback.OnTransactionEnd();
226 callback.DetachFrom(
this);
243 TableComposite.Rollback(
this, touchedTables, Registry);
253 GC.SuppressFinalize(
this);
265 #region TransactionTableContainer
272 this.transaction = transaction;
273 this.tableInfos = tableInfos;
276 public int TableCount {
277 get {
return tableInfos.Length; }
281 var ignoreCase = transaction.IgnoreIdentifiersCase();
282 for (
int i = 0; i < tableInfos.Length; i++) {
283 var info = tableInfos[i];
285 info.TableName.Equals(name, ignoreCase))
293 if (offset < 0 || offset >= tableInfos.Length)
294 throw new ArgumentOutOfRangeException(
"offset");
296 return tableInfos[offset].TableName;
300 if (offset < 0 || offset >= tableInfos.Length)
301 throw new ArgumentOutOfRangeException(
"offset");
303 return tableInfos[offset];
311 return FindByName(name) >= 0;
337 throw new ArgumentOutOfRangeException(
"offset");
343 #region OldAndNewTableContainer
349 this.transaction = transaction;
352 private bool HasOldTable {
356 private bool HasNewTable {
357 get {
return transaction.TableState.NewDataRow != null; }
361 public int TableCount {
378 return HasOldTable ? 1 : 0;
383 if (HasOldTable && offset == 0)
390 var tableInfo = transaction.GetTableInfo(transaction.TableState.TableSource);
391 return tableInfo.
Alias(GetTableName(offset));
399 return FindByName(name) > 0;
403 var tableInfo = GetTableInfo(offset);
405 var table =
new TriggeredOldNew(transaction.DatabaseContext, tableInfo);
410 var dtable = transaction.GetTable(transaction.TableState.TableSource);
411 var oldRow =
new Row(table);
412 int rowIndex = transaction.TableState.OldRowIndex;
413 for (
int i = 0; i < tableInfo.ColumnCount; ++i) {
414 oldRow.SetValue(i, dtable.GetValue(rowIndex, i));
418 table.SetReadOnly(
true);
419 table.SetData(oldRow);
425 table.SetReadOnly(!transaction.TableState.IsNewMutable);
426 table.SetData(transaction.TableState.NewDataRow);
431 #region TriggeredOldNew
440 this.tableInfo = tableInfo;
444 get {
return tableInfo; }
447 public override int RowCount {
460 if (rowNumber < 0 || rowNumber >= 1)
461 throw new ArgumentOutOfRangeException(
"rowNumber");
467 get {
throw new InvalidOperationException(); }
471 throw new NotSupportedException(String.Format(
"Inserting data into '{0}' is not allowed.", tableInfo.TableName));
477 throw new ArgumentOutOfRangeException();
479 throw new NotSupportedException(String.Format(
"Updating '{0}' is not permitted.", tableInfo.TableName));
482 for (
int i = 0; i < sz; ++i) {
488 throw new NotSupportedException(String.Format(
"Deleting data from '{0}' is not allowed.", tableInfo.TableName));
656 if (callbacks == null)
657 callbacks =
new List<TableCommitCallback>();
659 callbacks.Add(callback);
663 if (callbacks == null)
666 for (
int i = callbacks.Count - 1; i >= 0; i--) {
667 var other = callbacks[i];
668 if (other.TableName.Equals(callback.
TableName))
669 callbacks.RemoveAt(i);
static readonly TableInfo SqlTypesTableInfo
static ITable GetPrivilegesTable(ITransaction transaction)
Defines the contract to access the data contained into a table of a database.
static ITable GetOpenSessionsTable(ITransaction transaction)
void OnCallbackDetached(TableCommitCallback callback)
static readonly TableInfo[] IntTableInfo
ObjectName GetTableName(int offset)
Gets the name of the table at the given index in this container.
void OnCallbackAttached(TableCommitCallback callback)
The context of a single database within a system.
The system implementation of a transaction model that handles isolated operations within a database c...
static ITable GetSqlTypesTable(ITransaction transaction)
ObjectName GetTableName(int offset)
Gets the name of the table at the given index in this container.
IEnumerable< IMutableTable > AccessedTables
void Commit()
Commits all write operation done during the lifetime of this transaction and invalidates it...
void RegisterOnCommit(Action< TableCommitInfo > action)
DataObject GetValue(int columnOffset)
Gets or the value of a cell of the row at the given offset.
bool RemoveRow(RowId rowId)
Deletes row identified by the given coordinates from the table.
string GetTableType(int offset)
Gets the type of the table at the given offset.
ITable GetTable(int offset)
Gets the table contained at the given offset within the context.
int FindByName(ObjectName name)
Finds the index in this container of the given table by its name.
static readonly TableInfo TableInfoTableInfo
virtual void Dispose(bool disposing)
TableInfo GetTableInfo(int offset)
Gets the information of the table at the given offset in this container.
IEnumerable< ITableSource > SelectedTables
The default implementation of a database in a system.
Describes the name of an object within a database.
IDatabase Database
Gets the database this transaction belongs to.
static readonly TableInfo TableColumnsTableInfo
void SetTableState(OldNewTableState tableState)
static ITable GetVariablesTable(ITransaction transaction)
A single row in a table of a database.
ITableContainer CreateInternalTableInfo()
override bool Equals(object obj)
void AddVisibleTables(IEnumerable< TableSource > tableSources, IEnumerable< IIndexSet > indexSets)
The representation of a single database in the system.
IContext IEventSource. Context
string GetTableType(int offset)
Gets the type of the table at the given offset.
static readonly TableInfo PrivilegesTableInfo
int RowNumber
Gets the number of the column within the table referenced.
void AssertConstraints()
Performs all constraint integrity checks and actions to any modifications based on any changes that h...
TableInfo Alias(ObjectName alias)
IEventSource ParentSource
Gets an optional parent source.
void Rollback()
Rollback any write operations done during the lifetime of this transaction and invalidates it...
A default implementation of a sequence manager that is backed by a given transaction.
static ITable GetStatisticsTable(ITransaction transaction)
IEnumerable< KeyValuePair< string, object > > Metadata
Gets the list of metadata associated to the source.
static readonly TableInfo ProductInfoTableInfo
ITableContainer TableContainer
ITableContainer CreateTriggersTableContainer()
bool ContainsTable(ObjectName name)
Checks if a table with the given name is contained in the current context.
readonly TableInfo[] tableInfos
static readonly TableInfo StatisticsTableInfo
Provides the constant names of the types of tables in a database system.
void AddInternalTables(ITableContainer container)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
readonly Transaction transaction
Transaction(ITransactionContext context, Database database, int commitId, IsolationLevel isolation, IEnumerable< TableSource > committedTables, IEnumerable< IIndexSet > indexSets)
A container for any system tables that are generated from information inside the database engine...
static readonly TableInfo VariablesTableInfo
TriggeredOldNew(IDatabaseContext dbContext, TableInfo tableInfo)
ITransactionFactory TransactionFactory
Gets an object that is used to create new transactions to this database
QueryParameterStyle
In a SQL query object, this is the form of parameters passed from the client side to the server side...
Provides utilities and properties for handling the SYSTEN schema of a database.
static readonly TableInfo OpenSessionsTableInfo
An object that access to a set of indexes.
bool ContainsTable(ObjectName name)
Checks if a table with the given name is contained in the current context.
OldAndNewTableContainer(Transaction transaction)
void Dispose(bool disposing)
IEnumerable< ITableSource > GetVisibleTables()
readonly Transaction transaction
Defines the value of a ROWID object, that is a unique reference within a database system to a single ...
void UnregisterOnCommit(Action< TableCommitInfo > action)
void FlushIndexes()
Flushes all changes made on this table to the backing index scheme.
List< TableCommitCallback > callbacks
void SetValue(int columnOffset, DataObject value)
Sets the value of a cell of the row at the given offset.
TableInfo GetTableInfo(int offset)
Gets the information of the table at the given offset in this container.
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
readonly TableInfo tableInfo
int ColumnCount
Gets a count of the columns defined by this object.
ITable GetTable(int offset)
Gets the table contained at the given offset within the context.
int FindByName(ObjectName name)
Finds the index in this container of the given table by its name.
TableSourceComposite TableComposite
RowId AddRow(Row row)
Persists a new row to the table.
static readonly ObjectName OldTriggerTableName
The simplest implementation of a transaction.
Transaction(ITransactionContext context, Database database, int commitId, IsolationLevel isolation)
DbObjectType
The kind of objects that can be handled by a database system and its managers
Action< TableCommitInfo > commitActions
Defines the metadata properties of a table existing within a database.
static ITable GetTableColumnsTable(ITransaction transaction)
OldNewTableState TableState
static ITable GetTableInfoTable(ITransaction transaction)
static readonly TableInfo SessionInfoTableInfo
static ITable GetProductInfoTable(ITransaction transaction)
An interface that defines contracts to alter the contents of a table.
TransactionTableContainer(Transaction transaction, TableInfo[] tableInfos)
void UpdateRow(Row row)
Updates the values of a row into the table.
void SetReadOnly(bool flag)
Represents the origin of system events, providing a mechanism to fill the metadata before dispatching...
static readonly ObjectName NewTriggerTableName
RowId RowId
Gets the row unique identifier within the database.