/// <summary> /// Begins the transaction with the specified isolation level. /// </summary> /// <param name="isolationLevel">The isolation level.</param> public static void Begin(IsolationLevel isolationLevel) { if (IsActive) { throw new InvalidOperationException(); // Transaction is already Active (Parallel transactions msg..). } ITransactionProvider tran = null; try { tran = DataProvider.Current.CreateTransaction(); if (tran == null) { // Transactions are not supported at the current provider. _notSupported = true; return; } tran.Begin(isolationLevel); } catch //rethrow { if (tran != null) { tran.Dispose(); } throw; } Logger.WriteVerbose("Transaction: " + tran.Id + " BEGIN."); ContextHandler.SetTransaction(tran); OnBeginTransaction(tran, EventArgs.Empty); }
/// <summary> /// Commits the transaction. /// </summary> public static void Commit() { if (_notSupported) { return; } ITransactionProvider tran = ContextHandler.GetTransaction(); if (tran == null) // !IsActive { throw new InvalidOperationException(); // Transaction is not Active. } try { tran.Commit(); var queue = ContextHandler.GetTransactionQueue(); if (queue != null) { queue.Commit(); } OnCommitTransaction(tran, EventArgs.Empty); } finally { ContextHandler.SetTransaction(null); ContextHandler.SetTransactionQueue(null); tran.Dispose(); } }
/// <summary> /// Commits the transaction. /// </summary> public static void Commit() { if (_notSupported) { return; } ITransactionProvider tran = ContextHandler.GetTransaction(); if (tran == null) // !IsActive { throw new InvalidOperationException(); // Transaction is not Active. } try { tran.Commit(); var queue = ContextHandler.GetTransactionQueue(); if (queue != null) { queue.Commit(); } OnCommitTransaction(tran, EventArgs.Empty); } finally { Logger.WriteVerbose("Transaction: " + tran.Id + " COMMIT. Running time: " + (DateTime.UtcNow - tran.Started)); ContextHandler.SetTransaction(null); ContextHandler.SetTransactionQueue(null); tran.Dispose(); } }
/// <summary> /// Begins the transaction with the specified isolation level and timeout in seconds. /// </summary> /// <param name="isolationLevel">The isolation level.</param> /// <param name="timeout">The timeout in seconds.</param> public static void Begin(IsolationLevel isolationLevel, TimeSpan timeout) { if (IsActive) { throw new InvalidOperationException(); // Transaction is already Active (Parallel transactions msg..). } ITransactionProvider tran = null; try { tran = CommonComponents.TransactionFactory?.CreateTransaction(); if (tran == null) { // Transactions are not supported at the current provider. _notSupported = true; return; } tran.Begin(isolationLevel, timeout); } catch // rethrow { if (tran != null) { tran.Dispose(); } throw; } SnTrace.Database.Write("Transaction BEGIN: {0}.", tran.Id); ContextHandler.SetTransaction(tran); OnBeginTransaction(tran, EventArgs.Empty); }
/// <summary> /// Rollbacks the current transaction. /// </summary> public static void Rollback() { if (_notSupported) { return; } ITransactionProvider tran = ContextHandler.GetTransaction(); if (tran == null) // Means: !IsActive (Transaction is not Active) { throw new InvalidOperationException("Transaction is not active"); } try { tran.Rollback(); var queue = ContextHandler.GetTransactionQueue(); if (queue != null) { queue.Rollback(); } OnRollbackTransaction(tran, EventArgs.Empty); } finally { ////Cache.Clear(); // State "rollback" in cache. TODO: cache clear in cluster must be ensured. ////CACHE: Ez sose mûködött jól... Cache.Clear kéne. //DistributedApplication.Cache.Reset(); Logger.WriteVerbose("Transaction: " + tran.Id + " ROLLBACK. Running time: " + (DateTime.UtcNow - tran.Started)); ContextHandler.SetTransaction(null); ContextHandler.SetTransactionQueue(null); tran.Dispose(); } }