DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Package Functions | Properties | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Deveel.Data.Transactions.Transaction Class Reference

The system implementation of a transaction model that handles isolated operations within a database context. More...

Inheritance diagram for Deveel.Data.Transactions.Transaction:
Deveel.Data.Transactions.ITransaction Deveel.Data.Transactions.ICallbackHandler Deveel.Data.Sql.Triggers.ITableStateHandler Deveel.Data.Diagnostics.IEventSource

Classes

class  OldAndNewTableContainer
 
class  TransactionTableContainer
 

Public Member Functions

void SetTableState (OldNewTableState tableState)
 
void Commit ()
 Commits all write operation done during the lifetime of this transaction and invalidates it. More...
 
void RegisterOnCommit (Action< TableCommitInfo > action)
 
void UnregisterOnCommit (Action< TableCommitInfo > action)
 
void Rollback ()
 Rollback any write operations done during the lifetime of this transaction and invalidates it. More...
 
void Dispose ()
 

Package Functions

 Transaction (ITransactionContext context, Database database, int commitId, IsolationLevel isolation, IEnumerable< TableSource > committedTables, IEnumerable< IIndexSet > indexSets)
 
 Transaction (ITransactionContext context, Database database, int commitId, IsolationLevel isolation)
 

Properties

int CommitId [get, private set]
 
IsolationLevel Isolation [get, private set]
 
bool IsClosed [get, set]
 
OldNewTableState TableState [get, private set]
 
ITransactionContext Context [get, private set]
 
IDatabase ITransaction. Database [get]
 
Database Database [get, private set]
 
IEventSource IEventSource. ParentSource [get]
 
IEnumerable< KeyValuePair< string, object > > IEventSource. Metadata [get]
 
IContext IEventSource. Context [get]
 
IDatabaseContext DatabaseContext [get]
 
TableSourceComposite TableComposite [get]
 
SequenceManager SequenceManager [get]
 
ViewManager ViewManager [get]
 
TriggerManager TriggerManager [get]
 
TransactionRegistry Registry [get, private set]
 
TableManager TableManager [get]
 
- Properties inherited from Deveel.Data.Transactions.ITransaction
new ITransactionContext Context [get]
 
int CommitId [get]
 Gets a number uniquely identifying a transaction within a database context. More...
 
IsolationLevel Isolation [get]
 Gets the isolation level of the transaction. More...
 
IDatabase Database [get]
 Gets the database this transaction belongs to. More...
 
TransactionRegistry Registry [get]
 
- Properties inherited from Deveel.Data.Diagnostics.IEventSource
IContext Context [get]
 
IEventSource ParentSource [get]
 Gets an optional parent source. More...
 
IEnumerable< KeyValuePair< string, object > > Metadata [get]
 Gets the list of metadata associated to the source. More...
 
- Properties inherited from Deveel.Data.Sql.Triggers.ITableStateHandler
OldNewTableState TableState [get]
 Gets an object that olds the state before and after a table event. More...
 

Private Member Functions

 ~Transaction ()
 
void AddInternalTables ()
 
void AssertNotReadOnly ()
 
void Finish ()
 
void Dispose (bool disposing)
 
void ICallbackHandler. OnCallbackAttached (TableCommitCallback callback)
 
void ICallbackHandler. OnCallbackDetached (TableCommitCallback callback)
 

Static Private Member Functions

static Transaction ()
 

Private Attributes

List< TableCommitCallbackcallbacks
 
Action< TableCommitInfocommitActions
 
readonly bool dbReadOnly
 

Static Private Attributes

static readonly TableInfo[] IntTableInfo
 

Detailed Description

The system implementation of a transaction model that handles isolated operations within a database context.

See also
ITransaction

Definition at line 35 of file Transaction.cs.

Constructor & Destructor Documentation

Deveel.Data.Transactions.Transaction.Transaction ( ITransactionContext  context,
Database  database,
int  commitId,
IsolationLevel  isolation,
IEnumerable< TableSource committedTables,
IEnumerable< IIndexSet indexSets 
)
inlinepackage

Definition at line 44 of file Transaction.cs.

44  {
45  CommitId = commitId;
46  Database = database;
47  Isolation = isolation;
48  Context = context;
49 
50  context.RegisterInstance<ITransaction>(this);
51 
52  Registry = new TransactionRegistry(this);
53  TableManager.AddVisibleTables(committedTables, indexSets);
54 
56 
58 
59  IsClosed = false;
60 
61  Database.TransactionFactory.OpenTransactions.AddTransaction(this);
62 
63  this.CurrentSchema(database.Context.DefaultSchema());
64  this.ReadOnly(database.Context.ReadOnly());
65  this.AutoCommit(database.Context.AutoCommit());
66  this.IgnoreIdentifiersCase(database.Context.IgnoreIdentifiersCase());
67  this.ParameterStyle(QueryParameterStyle.Marker);
68  }
IDatabase ITransaction. Database
Definition: Transaction.cs:105
void AddVisibleTables(IEnumerable< TableSource > tableSources, IEnumerable< IIndexSet > indexSets)
QueryParameterStyle
In a SQL query object, this is the form of parameters passed from the client side to the server side...
ITransactionFactory TransactionFactory
Gets an object that is used to create new transactions to this database
Definition: IDatabase.cs:56
Deveel.Data.Transactions.Transaction.Transaction ( ITransactionContext  context,
Database  database,
int  commitId,
IsolationLevel  isolation 
)
inlinepackage

Definition at line 70 of file Transaction.cs.

71  : this(context, database, commitId, isolation, new TableSource[0], new IIndexSet[0]) {
72  }
An object that access to a set of indexes.
Definition: IIndexSet.cs:27
Deveel.Data.Transactions.Transaction.~Transaction ( )
inlineprivate

Definition at line 74 of file Transaction.cs.

74  {
75  Dispose(false);
76  }
static Deveel.Data.Transactions.Transaction.Transaction ( )
inlinestaticprivate

Definition at line 78 of file Transaction.cs.

78  {
79  IntTableInfo = new TableInfo[9];
80  IntTableInfo[0] = SystemSchema.TableInfoTableInfo;
81  IntTableInfo[1] = SystemSchema.TableColumnsTableInfo;
82  IntTableInfo[2] = SystemSchema.ProductInfoTableInfo;
83  IntTableInfo[3] = SystemSchema.VariablesTableInfo;
84  IntTableInfo[4] = SystemSchema.StatisticsTableInfo;
85  IntTableInfo[5] = SystemSchema.SessionInfoTableInfo;
86  IntTableInfo[6] = SystemSchema.OpenSessionsTableInfo;
87  IntTableInfo[7] = SystemSchema.SqlTypesTableInfo;
88  IntTableInfo[8] = SystemSchema.PrivilegesTableInfo;
89  }
static readonly TableInfo[] IntTableInfo
Definition: Transaction.cs:40
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41

Member Function Documentation

void Deveel.Data.Transactions.Transaction.AddInternalTables ( )
inlineprivate

Definition at line 155 of file Transaction.cs.

155  {
156  TableManager.AddInternalTables(new TransactionTableContainer(this, IntTableInfo));
157 
158  // OLD and NEW system tables (if applicable)
159  TableManager.AddInternalTables(new OldAndNewTableContainer(this));
160 
161  // Model views as tables (obviously)
163 
165  //tableManager.AddInternalTables(routineManager.CreateInternalTableInfo());
166 
167  // Model sequences as tables
169 
170  // Model triggers as tables
172  }
static readonly TableInfo[] IntTableInfo
Definition: Transaction.cs:40
ITableContainer CreateInternalTableInfo()
Definition: ViewManager.cs:236
A default implementation of a sequence manager that is backed by a given transaction.
void AddInternalTables(ITableContainer container)
void Deveel.Data.Transactions.Transaction.AssertNotReadOnly ( )
inlineprivate

Definition at line 174 of file Transaction.cs.

174  {
175  if (this.ReadOnly())
176  throw new TransactionException(TransactionErrorCodes.ReadOnly, "The transaction is in read-only mode.");
177  }
void Deveel.Data.Transactions.Transaction.Commit ( )
inline

Commits all write operation done during the lifetime of this transaction and invalidates it.

See also
TransactionExtensions.ReadOnly(ITransaction), Rollback

When a transaction is disposed without explicitly calling Commit, all the operations are implicitly rolled-back.

Implements Deveel.Data.Transactions.ITransaction.

Definition at line 179 of file Transaction.cs.

179  {
180  if (!IsClosed) {
181  try {
182  var touchedTables = TableManager.AccessedTables.ToList();
183  var visibleTables = TableManager.GetVisibleTables().ToList();
184  var selected = TableManager.SelectedTables.ToArray();
185  TableComposite.Commit(this, visibleTables, selected, touchedTables, Registry, commitActions);
186 
187 
188  } finally {
189  Finish();
190  }
191  }
192  }
void Commit(Transaction transaction, IList< ITableSource > visibleTables, IEnumerable< ITableSource > selectedFromTables, IEnumerable< IMutableTable > touchedTables, TransactionRegistry journal, Action< TableCommitInfo > commitActions)
IEnumerable< IMutableTable > AccessedTables
Definition: TableManager.cs:61
IEnumerable< ITableSource > SelectedTables
Definition: TableManager.cs:65
TableSourceComposite TableComposite
Definition: Transaction.cs:133
IEnumerable< ITableSource > GetVisibleTables()
Action< TableCommitInfo > commitActions
Definition: Transaction.cs:38
void Deveel.Data.Transactions.Transaction.Dispose ( )
inline

Definition at line 251 of file Transaction.cs.

251  {
252  Dispose(true);
253  GC.SuppressFinalize(this);
254  }
void Deveel.Data.Transactions.Transaction.Dispose ( bool  disposing)
inlineprivate

Definition at line 256 of file Transaction.cs.

256  {
257  if (disposing) {
258  //if (!IsClosed)
259  // Rollback();
260  // TODO: review this ...
261  Finish();
262  }
263  }
void Deveel.Data.Transactions.Transaction.Finish ( )
inlineprivate

Definition at line 208 of file Transaction.cs.

208  {
209  try {
210  // Dispose all the table we touched
211  try {
213 
214  if (Context != null)
215  Context.Dispose();
216 
217  } catch (Exception ex) {
218  this.OnError(ex);
219  }
220 
221  Registry = null;
222 
223  if (callbacks != null) {
224  foreach (var callback in callbacks) {
225  callback.OnTransactionEnd();
226  callback.DetachFrom(this);
227  }
228  }
229 
230  callbacks = null;
231  Context = null;
232 
233  // Dispose all the objects in the transaction
234  } finally {
235  IsClosed = true;
236  }
237  }
List< TableCommitCallback > callbacks
Definition: Transaction.cs:36
void ICallbackHandler. Deveel.Data.Transactions.Transaction.OnCallbackAttached ( TableCommitCallback  callback)
inlineprivate

Implements Deveel.Data.Transactions.ICallbackHandler.

Definition at line 655 of file Transaction.cs.

655  {
656  if (callbacks == null)
657  callbacks = new List<TableCommitCallback>();
658 
659  callbacks.Add(callback);
660  }
List< TableCommitCallback > callbacks
Definition: Transaction.cs:36
void ICallbackHandler. Deveel.Data.Transactions.Transaction.OnCallbackDetached ( TableCommitCallback  callback)
inlineprivate

Implements Deveel.Data.Transactions.ICallbackHandler.

Definition at line 662 of file Transaction.cs.

662  {
663  if (callbacks == null)
664  return;
665 
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);
670  }
671  }
List< TableCommitCallback > callbacks
Definition: Transaction.cs:36
void Deveel.Data.Transactions.Transaction.RegisterOnCommit ( Action< TableCommitInfo action)
inline

Implements Deveel.Data.Transactions.ITransaction.

Definition at line 194 of file Transaction.cs.

194  {
195  if (commitActions == null) {
196  commitActions = action;
197  } else {
198  commitActions = Delegate.Combine(commitActions, action) as Action<TableCommitInfo>;
199  }
200  }
Action< TableCommitInfo > commitActions
Definition: Transaction.cs:38
void Deveel.Data.Transactions.Transaction.Rollback ( )
inline

Rollback any write operations done during the lifetime of this transaction and invalidates it.

When a transaction is disposed without explicitly calling Commit, all the operations are implicitly rolled-back.

See also
IDisposable.Dispose, Commit, TransactionExtensions.ReadOnly(Deveel.Data.Transactions.ITransaction)

Implements Deveel.Data.Transactions.ITransaction.

Definition at line 239 of file Transaction.cs.

239  {
240  if (!IsClosed) {
241  try {
242  var touchedTables = TableManager.AccessedTables.ToList();
243  TableComposite.Rollback(this, touchedTables, Registry);
244  } finally {
245  IsClosed = true;
246  Finish();
247  }
248  }
249  }
IEnumerable< IMutableTable > AccessedTables
Definition: TableManager.cs:61
TableSourceComposite TableComposite
Definition: Transaction.cs:133
void Rollback(Transaction transaction, IList< IMutableTable > touchedTables, TransactionRegistry journal)
void Deveel.Data.Transactions.Transaction.SetTableState ( OldNewTableState  tableState)
inline

Implements Deveel.Data.Sql.Triggers.ITableStateHandler.

Definition at line 101 of file Transaction.cs.

101  {
102  TableState = tableState;
103  }
void Deveel.Data.Transactions.Transaction.UnregisterOnCommit ( Action< TableCommitInfo action)
inline

Implements Deveel.Data.Transactions.ITransaction.

Definition at line 202 of file Transaction.cs.

202  {
203  if (commitActions != null)
204  commitActions = Delegate.Remove(commitActions, action) as Action<TableCommitInfo>;
205  }
Action< TableCommitInfo > commitActions
Definition: Transaction.cs:38

Member Data Documentation

List<TableCommitCallback> Deveel.Data.Transactions.Transaction.callbacks
private

Definition at line 36 of file Transaction.cs.

Action<TableCommitInfo> Deveel.Data.Transactions.Transaction.commitActions
private

Definition at line 38 of file Transaction.cs.

readonly bool Deveel.Data.Transactions.Transaction.dbReadOnly
private

Definition at line 42 of file Transaction.cs.

readonly TableInfo [] Deveel.Data.Transactions.Transaction.IntTableInfo
staticprivate

Definition at line 40 of file Transaction.cs.

Property Documentation

int Deveel.Data.Transactions.Transaction.CommitId
getprivate set

Definition at line 91 of file Transaction.cs.

ITransactionContext Deveel.Data.Transactions.Transaction.Context
getprivate set

Definition at line 99 of file Transaction.cs.

IContext IEventSource. Deveel.Data.Transactions.Transaction.Context
getprivate

Definition at line 125 of file Transaction.cs.

IDatabase ITransaction. Deveel.Data.Transactions.Transaction.Database
getprivate

Definition at line 105 of file Transaction.cs.

Database Deveel.Data.Transactions.Transaction.Database
getprivate set

Definition at line 109 of file Transaction.cs.

IDatabaseContext Deveel.Data.Transactions.Transaction.DatabaseContext
get

Definition at line 129 of file Transaction.cs.

bool Deveel.Data.Transactions.Transaction.IsClosed
getsetprivate

Definition at line 95 of file Transaction.cs.

IsolationLevel Deveel.Data.Transactions.Transaction.Isolation
getprivate set

Definition at line 93 of file Transaction.cs.

IEnumerable<KeyValuePair<string, object> > IEventSource. Deveel.Data.Transactions.Transaction.Metadata
getprivate

Definition at line 115 of file Transaction.cs.

IEventSource IEventSource. Deveel.Data.Transactions.Transaction.ParentSource
getprivate

Definition at line 111 of file Transaction.cs.

TransactionRegistry Deveel.Data.Transactions.Transaction.Registry
getprivate set

Definition at line 149 of file Transaction.cs.

SequenceManager Deveel.Data.Transactions.Transaction.SequenceManager
getprivate

Definition at line 137 of file Transaction.cs.

TableSourceComposite Deveel.Data.Transactions.Transaction.TableComposite
getprivate

Definition at line 133 of file Transaction.cs.

TableManager Deveel.Data.Transactions.Transaction.TableManager
getprivate

Definition at line 151 of file Transaction.cs.

OldNewTableState Deveel.Data.Transactions.Transaction.TableState
getprivate set

Definition at line 97 of file Transaction.cs.

TriggerManager Deveel.Data.Transactions.Transaction.TriggerManager
getprivate

Definition at line 145 of file Transaction.cs.

ViewManager Deveel.Data.Transactions.Transaction.ViewManager
getprivate

Definition at line 141 of file Transaction.cs.


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