/// <summary>
        /// Cleanup resources after transaction completion.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <remarks>
        /// <para>
        /// Called after <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoCommit"/>
        /// and
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoRollback"/>
        /// execution on any outcome.
        /// </para>
        /// </remarks>
        protected override void DoCleanupAfterCompletion(object transaction)
        {
            MessageQueueTransactionObject txObject = (MessageQueueTransactionObject)transaction;

            TransactionSynchronizationManager.UnbindResource(CURRENT_TRANSACTION_SLOTNAME);
            txObject.ResourceHolder.Clear();
        }
        /// <summary>
        /// Suspend the resources of the current transaction.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <returns>
        /// An object that holds suspended resources (will be kept unexamined for passing it into
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoResume"/>.)
        /// </returns>
        protected override object DoSuspend(object transaction)
        {
            MessageQueueTransactionObject txObject = (MessageQueueTransactionObject)transaction;

            txObject.ResourceHolder = null;
            return(TransactionSynchronizationManager.UnbindResource(CURRENT_TRANSACTION_SLOTNAME));
        }
        /// <summary>
        /// Return the current transaction object.
        /// </summary>
        /// <returns>The current transaction object.</returns>
        /// <exception cref="Spring.Transaction.CannotCreateTransactionException">
        /// If transaction support is not available.
        /// </exception>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In the case of lookup or system errors.
        /// </exception>
        protected override object DoGetTransaction()
        {
            MessageQueueTransactionObject txObject = new MessageQueueTransactionObject();

            txObject.ResourceHolder =
                (MessageQueueResourceHolder)TransactionSynchronizationManager.GetResource(CURRENT_TRANSACTION_SLOTNAME);
            return(txObject);
        }
        /// <summary>
        /// Perform an actual rollback on the given transaction, calls Transaction.Abort().
        /// </summary>
        /// <param name="status">The status representation of the transaction.</param>
        /// <remarks>
        /// An implementation does not need to check the new transaction flag.
        /// </remarks>
        protected override void DoRollback(DefaultTransactionStatus status)
        {
            MessageQueueTransactionObject txObject    = (MessageQueueTransactionObject)status.Transaction;
            MessageQueueTransaction       transaction = txObject.ResourceHolder.MessageQueueTransaction;

            try
            {
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Committing MessageQueueTransaction");
                }
                transaction.Abort();
            }
            catch (MessageQueueException ex)
            {
                throw new TransactionSystemException("Could not roll back DefaultMessageQueue transaction", ex);
            }
        }
        /// <summary>
        /// Begin a new transaction with the given transaction definition.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <param name="definition"><see cref="Spring.Transaction.ITransactionDefinition"/> instance, describing
        /// propagation behavior, isolation level, timeout etc.</param>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In the case of creation or system errors.
        /// </exception>
        protected override void DoBegin(object transaction, ITransactionDefinition definition)
        {
            MessageQueueTransactionObject txObject = (MessageQueueTransactionObject)transaction;

            MessageQueueTransaction mqt = new MessageQueueTransaction();

            mqt.Begin();

            txObject.ResourceHolder = new MessageQueueResourceHolder(mqt);
            txObject.ResourceHolder.SynchronizedWithTransaction = true;

            int timeout = DetermineTimeout(definition);

            if (timeout != DefaultTransactionDefinition.TIMEOUT_DEFAULT)
            {
                txObject.ResourceHolder.TimeoutInSeconds = timeout;
            }
            TransactionSynchronizationManager.BindResource(CURRENT_TRANSACTION_SLOTNAME, txObject.ResourceHolder);
        }
 /// <summary>
 /// Return the current transaction object.
 /// </summary>
 /// <returns>The current transaction object.</returns>
 /// <exception cref="Spring.Transaction.CannotCreateTransactionException">
 /// If transaction support is not available.
 /// </exception>
 /// <exception cref="Spring.Transaction.TransactionException">
 /// In the case of lookup or system errors.
 /// </exception>
 protected override object DoGetTransaction()
 {
     MessageQueueTransactionObject txObject = new MessageQueueTransactionObject();
     txObject.ResourceHolder =
         (MessageQueueResourceHolder) TransactionSynchronizationManager.GetResource(CURRENT_TRANSACTION_SLOTNAME);
     return txObject;
 }
        /// <summary>
        /// Set the given transaction rollback-only. Only called on rollback
        /// if the current transaction takes part in an existing one.
        /// </summary>
        /// <param name="status">The status representation of the transaction.</param>
        /// <remarks>Default implementation throws an IllegalTransactionStateException,
        /// assuming that participating in existing transactions is generally not
        /// supported. Subclasses are of course encouraged to provide such support.
        /// </remarks>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In the case of system errors.
        /// </exception>
        protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
        {
            MessageQueueTransactionObject txObject = (MessageQueueTransactionObject)status.Transaction;

            txObject.ResourceHolder.RollbackOnly = true;
        }
        /// <summary>
        /// Check if the given transaction object indicates an existing transaction
        /// (that is, a transaction which has already started).
        /// </summary>
        /// <param name="transaction">MessageQueueTransactionObject object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <returns>
        /// True if there is an existing transaction.
        /// </returns>
        protected override bool IsExistingTransaction(object transaction)
        {
            MessageQueueTransactionObject txObject = (MessageQueueTransactionObject)transaction;

            return(txObject.ResourceHolder != null);
        }