SetTransaction() static private method

static private SetTransaction ( ITransactionProvider transaction ) : void
transaction ITransactionProvider
return void
Example #1
0
        /// <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();
            }
        }
Example #2
0
        /// <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;
            }

            ContextHandler.SetTransaction(tran);
            OnBeginTransaction(tran, EventArgs.Empty);
        }
        /// <summary>
        /// Rollbacks the current transaction and all its participants.
        /// </summary>
        public static void Rollback()
        {
            if (_notSupported)
            {
                return;
            }

            var tran = ContextHandler.GetTransaction();

            if (tran == null)
            {
                throw new InvalidOperationException("Transaction is not active");
            }

            try
            {
                tran.Rollback();

                var queue = ContextHandler.GetTransactionQueue();
                queue?.Rollback();

                OnRollbackTransaction(tran, EventArgs.Empty);
            }
            finally
            {
                SnTrace.Database.Write("Transaction ROLLBACK: {0}. Running time: {1}", tran.Id, (DateTime.UtcNow - tran.Started));
                ContextHandler.SetTransaction(null);
                ContextHandler.SetTransactionQueue(null);
                tran.Dispose();
            }
        }
        /// <summary>
        /// Commits the transaction and all its participants.
        /// </summary>
        public static void Commit()
        {
            if (_notSupported)
            {
                return;
            }

            var tran = ContextHandler.GetTransaction();

            if (tran == null)                          // !IsActive
            {
                throw new InvalidOperationException(); // Transaction is not Active.
            }
            try
            {
                tran.Commit();

                var queue = ContextHandler.GetTransactionQueue();
                queue?.Commit();

                OnCommitTransaction(tran, EventArgs.Empty);
            }
            finally
            {
                SnTrace.Database.Write("Transaction COMMIT: {0}. Running time: {1}", tran.Id, (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);
        }
Example #6
0
        /// <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();
            }
        }
Example #7
0
        /// <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();

                ContextHandler.SetTransaction(null);
                ContextHandler.SetTransactionQueue(null);
                tran.Dispose();
            }
        }