Esempio n. 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="transBase">The parent <see cref="BaseTransaction" />.</param>
 /// <param name="position">The <see cref="ILogPosition" /> for the first <see cref="IOperation" /> for this transaction.</param>
 internal Transaction(BaseTransaction transBase, ILogPosition position)
 {
     this.syncLock     = transBase.Manager.SyncRoot;
     this.transBase    = transBase;
     this.position     = position;
     this.isOpen       = true;
     this.resourceData = null;
 }
Esempio n. 2
0
        /// <summary>
        /// Called by <see cref="BaseTransaction" /> when the transaction is complete.
        /// </summary>
        /// <param name="baseTrans"></param>
        internal void EndTransaction(BaseTransaction baseTrans)
        {
            using (TimedLock.Lock(this))
            {
                log.RemoveOperationLog(baseTrans.OperationLog);
                transactions.Remove(baseTrans.ID);

                if (!threadSpanning)
                {
                    this.CurrentTransaction = null;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initiates a new base transaction.
        /// </summary>
        /// <returns>The new <see cref="Transaction" />.</returns>
        /// <exception cref="InvalidOperationException">Thrown if transaction manager has not been started.</exception>
        /// <remarks>
        /// <para>
        /// Note that this method changes its behavior based on whether
        /// <b>allowThreadSpanning</b> was passed as <c>true</c> or <c>false</c>
        /// to the constructor.  If thread spanning is allowed then this method
        /// always creates a new <see cref="BaseTransaction" /> and returns a
        /// new <see cref="Transaction" /> pushed onto it.
        /// </para>
        /// <para>
        /// If single-thread transaction mode is enabled, then this method
        /// will first look to see if there's already a <see cref="BaseTransaction" />
        /// for then current thread.  If there is one, then a new <see cref="Transaction" />
        /// will be pushed onto it and returned.  If there no base transaction associated
        /// with the thread then a new one will be created.
        /// </para>
        /// </remarks>
        public Transaction BeginTransaction()
        {
            BaseTransaction transBase;

            using (TimedLock.Lock(this))
            {
                if (!running)
                {
                    throw new TransactionException("Transaction manager has not started for [{0}].", resource.Name);
                }

                if (stopPending)
                {
                    throw new TransactionException("Transaction manager stop is pending for [{0}].", resource.Name);
                }

                if (threadSpanning)
                {
                    transBase = new BaseTransaction(Helper.NewGuid(), this);
                    transactions.Add(transBase.ID, transBase);

                    return(transBase.BeginTransaction());
                }
                else
                {
                    transBase = this.CurrentTransaction;
                    if (transBase != null)
                    {
                        return(transBase.BeginTransaction());
                    }

                    this.CurrentTransaction = transBase = new BaseTransaction(Helper.NewGuid(), this);
                    transactions.Add(transBase.ID, transBase);

                    return(transBase.BeginTransaction());
                }
            }
        }