Example #1
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Get a transaction by id.
        /// </summary>
        /// <param name="index">
        ///  Zero-based index of the.
        /// </param>
        /// <returns>
        ///  The transaction.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public MemoryTransaction GetTransaction(long index)
        {
            if (index == 0)
            {
                return(null);
            }
            MemoryTransaction tx = null;

            _transactions.TryGetValue(index, out tx);
            return(tx);
        }
Example #2
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Executes the transaction terminated action.
        /// </summary>
        /// <param name="transaction">
        ///  The transaction.
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        public void OnTransactionTerminated(MemoryTransaction transaction)
        {
            Debug.Assert(transaction.Status != TransactionStatus.Active);
            Debug.Assert(!transaction.IsNested);

            lock (_activeTransactions)
                _activeTransactions.Remove(transaction);

            OnTransactionEnded(transaction, transaction.Status == TransactionStatus.Committed);
            if (_trace.IsEnabled(TraceCategory.MemoryStore))
            {
                _trace.WriteTrace(TraceCategory.MemoryStore, "Memory transaction ended " + transaction.Id);
            }
        }
Example #3
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Create a new command context. If there is no current transaction, a transaction is created
        ///  and will be terminated when the context will be disposed.
        /// </summary>
        /// <param name="transactionManager">
        ///  .
        /// </param>
        /// <param name="readOnly">
        ///  true to read only.
        /// </param>
        /// <param name="isolationLevel">
        ///  (Optional)
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        public CommandContext(ITransactionManager transactionManager, bool readOnly = false, SessionIsolationLevel isolationLevel = SessionIsolationLevel.Unspecified)
        {
            DebugContract.Requires(transactionManager, "transactionManager");

            _transactionManager = transactionManager;
            _currentTransaction = _transactionManager.CurrentTransaction ?? (_transaction = transactionManager.BeginTransaction(isolationLevel, readOnly));

            // On s'assure qu' il existe une transaction courante

            if (_currentTransaction.SessionIsolationLevel != SessionIsolationLevel.Serializable)
            {
                _activeTransactionsWhenStarted = transactionManager.GetActiveTransactions();
            }

            // N° de la commande dans le contexte de la transaction courante
            CommandId = _currentTransaction.GetAnIncrementCurrentCommandId();
        }
Example #4
0
        private void OnTransactionEnded(MemoryTransaction transaction, bool committed)
        {
            DebugContract.Requires(transaction);

            var tmp = TransactionCompleted;

            if (tmp != null)
            {
                try
                {
                    tmp(transaction, new TransactionCompletedEventArgs(transaction.Id, committed, transaction.IsNested));
                }
                catch
                {
                }
            }
        }
Example #5
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Création d'une transaction (Scope = RequiredNested)
        /// </summary>
        /// <param name="isolationLevel">
        ///  .
        /// </param>
        /// <param name="readOnly">
        ///  true to read only.
        /// </param>
        /// <returns>
        ///  The new transaction.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        private MemoryTransaction CreateTransaction(SessionIsolationLevel isolationLevel, bool readOnly)
        {
            var current = CurrentTransaction;

            if (current == null)
            {
                var xid = Interlocked.Increment(ref _transactionNumber);
                if (_trace.IsEnabled(TraceCategory.MemoryStore))
                {
                    _trace.WriteTrace(TraceCategory.MemoryStore, "Create memory transaction {0} - Thread {1}", xid, ThreadHelper.CurrentThreadId);
                }

                current = new MemoryTransaction(_trace, this, xid, isolationLevel);
                if (Session.Current != null)
                {
                    CurrentTransaction = current;
                }

                if (!readOnly)
                {
                    lock (_sync)
                    {
                        _transactions.Add(current.Id, current);
                        lock (_activeTransactions)
                        {
                            _activeTransactions.Add(current);
                        }

                        if (Session.Current != null)
                        {
                            Session.Current.Enlist(current);
                        }
                    }
                }
            }
            else if (!readOnly)
            {
                current.PushNestedTransaction();
            }

            return(current);
        }