public override string GetDescription() { ITransactionStatus txStatus = TransactionInterceptor.CurrentTransactionStatus; txStatus.SetRollbackOnly(); return("test description"); }
private object TransactionMethod(ITransactionStatus status) { Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active"); Assert.IsTrue(status.IsNewTransaction, "Is new transaction"); Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly); Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive); status.SetRollbackOnly(); return(null); }
private object TransactionMethod(ITransactionStatus status) { Assert.IsTrue(TransactionSynchronizationManager.HasResource(sf), "Has thread session"); HibernateTemplate ht = new HibernateTemplate(sf); object returnValue = ht.Execute(new HibernateDelegate(Del)); status.SetRollbackOnly(); return(null); }
public object DoInTransaction(ITransactionStatus status) { Assert.IsTrue(TransactionSynchronizationManager.HasResource(sf), "Has thread session"); HibernateTemplate ht = new HibernateTemplate(sf); ht.TemplateFlushMode = TemplateFlushMode.Eager; ht.Execute(new HibernateDelegate(Del)); status.SetRollbackOnly(); return(null); }
/// <summary> /// Does the receive and execute using TxPlatformTransactionManager. Starts a distributed /// transaction before calling Receive. /// </summary> /// <param name="mq">The message queue.</param> /// <param name="status">The transactional status.</param> /// <returns> /// true if should continue peeking, false otherwise. /// </returns> protected override bool DoReceiveAndExecuteUsingPlatformTransactionManager(MessageQueue mq, ITransactionStatus status) { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Executing DoReceiveAndExecuteUsingTxScopeTransactionManager"); } #endregion Logging //We are sure to be talking to a second resource manager, so avoid going through //the promotable transaction and force a distributed transaction right from the start. TransactionInterop.GetTransmitterPropagationToken(System.Transactions.Transaction.Current); Message message; try { message = mq.Receive(TimeSpan.Zero, MessageQueueTransactionType.Automatic); } catch (MessageQueueException ex) { if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { //expected to occur occasionally #region Logging if (LOG.IsTraceEnabled) { LOG.Trace( "MessageQueueErrorCode.IOTimeout: No message available to receive. May have been processed by another thread."); } #endregion status.SetRollbackOnly(); return(false); // no more peeking unless this is the last listener thread } else { // A real issue in receiving the message lock (messageQueueMonitor) { mq.Close(); MessageQueue.ClearConnectionCache(); } throw; // will cause rollback in surrounding platform transaction manager and log exception } } if (message == null) { #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Message recieved is null from Queue = [" + mq.Path + "]"); } #endregion status.SetRollbackOnly(); return(false); // no more peeking unless this is the last listener thread } try { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Received message [" + message.Id + "] on queue [" + mq.Path + "]"); } #endregion MessageReceived(message); if (DistributedTransactionExceptionHandler != null) { if (DistributedTransactionExceptionHandler.IsPoisonMessage(message)) { DistributedTransactionExceptionHandler.HandlePoisonMessage(message); return(true); // will remove from queue and continue receive loop. } } DoExecuteListener(message); } catch (Exception ex) { HandleDistributedTransactionListenerException(ex, message); throw; // will rollback and keep message on the queue. } finally { message.Dispose(); } return(true); }
private object TransactionMethod(ITransactionStatus status) { Assert.IsTrue(TransactionSynchronizationManager.HasResource(sf), "Has thread session"); HibernateTemplate ht = new HibernateTemplate(sf); object returnValue = ht.Execute(new HibernateDelegate(Del)); status.SetRollbackOnly(); return null; }
public object DoInTransaction(ITransactionStatus status) { Assert.IsTrue(TransactionSynchronizationManager.HasResource(sf), "Has thread session"); HibernateTemplate ht = new HibernateTemplate(sf); ht.TemplateFlushMode = TemplateFlushMode.Eager; ht.Execute(new HibernateDelegate(Del)); status.SetRollbackOnly(); return null; }
/// <summary> /// Does the recieve and execute using a local MessageQueueTransaction. /// </summary> /// <param name="mq">The mqessage queue.</param> /// <param name="status">The transactional status.</param> /// <returns>true if should continue peeking, false otherwise.</returns> protected virtual bool DoRecieveAndExecuteUsingResourceTransactionManagerWithTxQueue(MessageQueue mq, ITransactionStatus status) { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Executing DoRecieveAndExecuteUsingResourceTransactionManagerWithTxQueue"); } #endregion Logging using (MessageQueueTransaction messageQueueTransaction = new MessageQueueTransaction()) { messageQueueTransaction.Begin(); #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Started MessageQueueTransaction for queue = [" + mq.Path + "]"); } #endregion Message message; #region ReceiveMessage try { #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Receiving message with zero timeout for queue = [" + mq.Path + "]"); } #endregion message = mq.Receive(TimeSpan.Zero, messageQueueTransaction); } catch (MessageQueueException ex) { if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { //expected to occur occasionally #region Logging if (LOG.IsTraceEnabled) { LOG.Trace( "MessageQueueErrorCode.IOTimeout: No message available to receive. May have been processed by another thread."); } #endregion status.SetRollbackOnly(); return(false); // no more peeking unless this is the last listener thread } else { // A real issue in receiving the message #region Logging if (LOG.IsErrorEnabled) { LOG.Error("Error receiving message from DefaultMessageQueue [" + mq.Path + "], closing queue and clearing connection cache."); } #endregion lock (messageQueueMonitor) { mq.Close(); MessageQueue.ClearConnectionCache(); } throw; // will cause rollback in surrounding platform transaction manager and log exception } } #endregion if (message == null) { #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Message recieved is null from Queue = [" + mq.Path + "]"); } #endregion status.SetRollbackOnly(); return(false); // no more peeking unless this is the last listener thread } try { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Received message [" + message.Id + "] on queue [" + mq.Path + "]"); } #endregion MessageReceived(message); if (ExposeContainerManagedMessageQueueTransaction) { TransactionSynchronizationManager.BindResource( MessageQueueTransactionManager.CURRENT_TRANSACTION_SLOTNAME, new LocallyExposedMessageQueueResourceHolder(messageQueueTransaction)); } DoExecuteListener(message); #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("MessageListener executed"); } #endregion messageQueueTransaction.Commit(); #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Committed MessageQueueTransaction for queue [" + mq.Path + "]"); } #endregion } catch (Exception ex) { TransactionAction action = HandleTransactionalListenerException(ex, message, messageQueueTransaction); if (action == TransactionAction.Rollback) { messageQueueTransaction.Abort(); #region Logging if (LOG.IsDebugEnabled) { LOG.Debug( "Exception handler's TransactionAction has rolled back MessageQueueTransaction for queue [" + mq.Path + "]"); } #endregion } else { // Will remove from the message queue messageQueueTransaction.Commit(); #region Logging if (LOG.IsDebugEnabled) { LOG.Debug( "Exception handler's TransactionAction has committed MessageQueueTransaction for queue [" + mq.Path + "]"); } #endregion } //Outer db-tx will rollback throw; } finally { if (ExposeContainerManagedMessageQueueTransaction) { TransactionSynchronizationManager.UnbindResource( MessageQueueTransactionManager.CURRENT_TRANSACTION_SLOTNAME); } message.Dispose(); } return(true); } }
/// <summary> /// Does the recieve and execute using message queue transaction manager. /// </summary> /// <param name="mq">The message queue.</param> /// <param name="status">The transactional status.</param> /// <returns>true if should continue peeking, false otherise</returns> protected virtual bool DoRecieveAndExecuteUsingMessageQueueTransactionManager(MessageQueue mq, ITransactionStatus status) { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Executing DoRecieveAndExecuteUsingMessageQueueTransactionManager"); } #endregion Logging Message message; #region Receive message try { message = mq.Receive(TimeSpan.Zero, QueueUtils.GetMessageQueueTransaction(null)); } catch (MessageQueueException ex) { if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { //expected to occur occasionally if (LOG.IsTraceEnabled) { LOG.Trace("IOTimeout: Message to receive was already processed by another thread."); } status.SetRollbackOnly(); return(false); // no more peeking unless this is the last listener thread } else { // A real issue in receiving the message #region Logging if (LOG.IsErrorEnabled) { LOG.Error("Error receiving message from DefaultMessageQueue [" + mq.Path + "], closing queue and clearing connection cache."); } #endregion lock (messageQueueMonitor) { mq.Close(); MessageQueue.ClearConnectionCache(); } throw; // will cause rollback in MessageQueueTransactionManager and log exception } } #endregion if (message == null) { #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Message recieved is null from Queue = [" + mq.Path + "]"); } #endregion status.SetRollbackOnly(); return(false); // no more peeking unless this is the last listener thread } try { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Received message [" + message.Id + "] on queue [" + mq.Path + "]"); } #endregion MessageReceived(message); DoExecuteListener(message); #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("MessageListener executed"); } #endregion } catch (Exception ex) { //Exception may indicate rollback of database transaction in service layer. //Let the handler determine if the message should be removed from the queue. TransactionAction action = HandleTransactionalListenerException(ex, message, QueueUtils.GetMessageQueueTransaction(null)); if (action == TransactionAction.Rollback) { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug( "Exception handler's TransactionAction has rolled back MessageQueueTransaction for queue [" + mq.Path + "]"); } #endregion status.SetRollbackOnly(); return(false); // no more peeking unless this is the last listener thread } else { LOG.Info("Committing MessageQueueTransaction due to explicit commit request by exception handler."); } } finally { message.Dispose(); } return(true); }
private object TransactionMethod(ITransactionStatus status) { Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active"); Assert.IsTrue(status.IsNewTransaction, "Is new transaction"); Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly); Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive); status.SetRollbackOnly(); return null; }
/// <summary> /// Does the receive and execute using TxPlatformTransactionManager. Starts a distributed /// transaction before calling Receive. /// </summary> /// <param name="mq">The message queue.</param> /// <param name="status">The transactional status.</param> /// <returns> /// true if should continue peeking, false otherwise. /// </returns> protected override bool DoReceiveAndExecuteUsingPlatformTransactionManager(MessageQueue mq, ITransactionStatus status) { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Executing DoReceiveAndExecuteUsingTxScopeTransactionManager"); } #endregion Logging //We are sure to be talking to a second resource manager, so avoid going through //the promotable transaction and force a distributed transaction right from the start. TransactionInterop.GetTransmitterPropagationToken(System.Transactions.Transaction.Current); Message message; try { message = mq.Receive(TimeSpan.Zero, MessageQueueTransactionType.Automatic); } catch (MessageQueueException ex) { if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { //expected to occur occasionally #region Logging if (LOG.IsTraceEnabled) { LOG.Trace( "MessageQueueErrorCode.IOTimeout: No message available to receive. May have been processed by another thread."); } #endregion status.SetRollbackOnly(); return false; // no more peeking unless this is the last listener thread } else { // A real issue in receiving the message lock (messageQueueMonitor) { mq.Close(); MessageQueue.ClearConnectionCache(); } throw; // will cause rollback in surrounding platform transaction manager and log exception } } if (message == null) { #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Message recieved is null from Queue = [" + mq.Path + "]"); } #endregion status.SetRollbackOnly(); return false; // no more peeking unless this is the last listener thread } try { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Received message [" + message.Id + "] on queue [" + mq.Path + "]"); } #endregion MessageReceived(message); if (DistributedTransactionExceptionHandler != null) { if (DistributedTransactionExceptionHandler.IsPoisonMessage(message)) { DistributedTransactionExceptionHandler.HandlePoisonMessage(message); return true; // will remove from queue and continue receive loop. } } DoExecuteListener(message); } catch (Exception ex) { HandleDistributedTransactionListenerException(ex, message); throw; // will rollback and keep message on the queue. } finally { message.Dispose(); } return true; }
private object TransactionWithExceptionOnRollbackMethod(ITransactionStatus status) { status.SetRollbackOnly(); return null; }
private object TransactionWithPropagationNestedAndRollbackMethod(ITransactionStatus status) { Assert.IsTrue(status.IsNewTransaction, "Is new transaction"); status.SetRollbackOnly(); return null; }
public object DoInTransaction(ITransactionStatus status) { Assert.IsTrue(TransactionSynchronizationManager.HasResource(dbProvider), "Has thread connection"); Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active"); Assert.IsTrue(status.IsNewTransaction, "Is new transaction"); Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly); Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive); status.SetRollbackOnly(); return null; }
public object DoInTransaction(ITransactionStatus status) { status.SetRollbackOnly(); return null; }
public object DoInTransaction(ITransactionStatus status) { Assert.IsTrue(TransactionSynchronizationManager.HasResource(dbProvider), "Has thread connection"); Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active"); Assert.IsTrue(!status.IsNewTransaction, "Is existing transaction"); status.SetRollbackOnly(); return null; }
/// <summary> /// Does the recieve and execute using a local MessageQueueTransaction. /// </summary> /// <param name="mq">The mqessage queue.</param> /// <param name="status">The transactional status.</param> /// <returns>true if should continue peeking, false otherwise.</returns> protected virtual bool DoRecieveAndExecuteUsingResourceTransactionManagerWithTxQueue(MessageQueue mq, ITransactionStatus status) { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Executing DoRecieveAndExecuteUsingResourceTransactionManagerWithTxQueue"); } #endregion Logging using (MessageQueueTransaction messageQueueTransaction = new MessageQueueTransaction()) { messageQueueTransaction.Begin(); #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Started MessageQueueTransaction for queue = [" + mq.Path + "]"); } #endregion Message message; #region ReceiveMessage try { #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Receiving message with zero timeout for queue = [" + mq.Path + "]"); } #endregion message = mq.Receive(TimeSpan.Zero, messageQueueTransaction); } catch (MessageQueueException ex) { if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { //expected to occur occasionally #region Logging if (LOG.IsTraceEnabled) { LOG.Trace( "MessageQueueErrorCode.IOTimeout: No message available to receive. May have been processed by another thread."); } #endregion status.SetRollbackOnly(); return false; // no more peeking unless this is the last listener thread } else { // A real issue in receiving the message #region Logging if (LOG.IsErrorEnabled) { LOG.Error("Error receiving message from DefaultMessageQueue [" + mq.Path + "], closing queue and clearing connection cache."); } #endregion lock (messageQueueMonitor) { mq.Close(); MessageQueue.ClearConnectionCache(); } throw; // will cause rollback in surrounding platform transaction manager and log exception } } #endregion if (message == null) { #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Message recieved is null from Queue = [" + mq.Path + "]"); } #endregion status.SetRollbackOnly(); return false; // no more peeking unless this is the last listener thread } try { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Received message [" + message.Id + "] on queue [" + mq.Path + "]"); } #endregion MessageReceived(message); if (ExposeContainerManagedMessageQueueTransaction) { TransactionSynchronizationManager.BindResource( MessageQueueTransactionManager.CURRENT_TRANSACTION_SLOTNAME, new LocallyExposedMessageQueueResourceHolder(messageQueueTransaction)); } DoExecuteListener(message); #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("MessageListener executed"); } #endregion messageQueueTransaction.Commit(); #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Committed MessageQueueTransaction for queue [" + mq.Path + "]"); } #endregion } catch (Exception ex) { TransactionAction action = HandleTransactionalListenerException(ex, message, messageQueueTransaction); if (action == TransactionAction.Rollback) { messageQueueTransaction.Abort(); #region Logging if (LOG.IsDebugEnabled) { LOG.Debug( "Exception handler's TransactionAction has rolled back MessageQueueTransaction for queue [" + mq.Path + "]"); } #endregion } else { // Will remove from the message queue messageQueueTransaction.Commit(); #region Logging if (LOG.IsDebugEnabled) { LOG.Debug( "Exception handler's TransactionAction has committed MessageQueueTransaction for queue [" + mq.Path + "]"); } #endregion } //Outer db-tx will rollback throw; } finally { if (ExposeContainerManagedMessageQueueTransaction) { TransactionSynchronizationManager.UnbindResource( MessageQueueTransactionManager.CURRENT_TRANSACTION_SLOTNAME); } message.Dispose(); } return true; } }
/// <summary> /// Does the recieve and execute using message queue transaction manager. /// </summary> /// <param name="mq">The message queue.</param> /// <param name="status">The transactional status.</param> /// <returns>true if should continue peeking, false otherise</returns> protected virtual bool DoRecieveAndExecuteUsingMessageQueueTransactionManager(MessageQueue mq, ITransactionStatus status) { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Executing DoRecieveAndExecuteUsingMessageQueueTransactionManager"); } #endregion Logging Message message; #region Receive message try { message = mq.Receive(TimeSpan.Zero, QueueUtils.GetMessageQueueTransaction(null)); } catch (MessageQueueException ex) { if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { //expected to occur occasionally if (LOG.IsTraceEnabled) { LOG.Trace("IOTimeout: Message to receive was already processed by another thread."); } status.SetRollbackOnly(); return false; // no more peeking unless this is the last listener thread } else { // A real issue in receiving the message #region Logging if (LOG.IsErrorEnabled) { LOG.Error("Error receiving message from DefaultMessageQueue [" + mq.Path + "], closing queue and clearing connection cache."); } #endregion lock (messageQueueMonitor) { mq.Close(); MessageQueue.ClearConnectionCache(); } throw; // will cause rollback in MessageQueueTransactionManager and log exception } } #endregion if (message == null) { #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("Message recieved is null from Queue = [" + mq.Path + "]"); } #endregion status.SetRollbackOnly(); return false; // no more peeking unless this is the last listener thread } try { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug("Received message [" + message.Id + "] on queue [" + mq.Path + "]"); } #endregion MessageReceived(message); DoExecuteListener(message); #region Logging if (LOG.IsTraceEnabled) { LOG.Trace("MessageListener executed"); } #endregion } catch (Exception ex) { //Exception may indicate rollback of database transaction in service layer. //Let the handler determine if the message should be removed from the queue. TransactionAction action = HandleTransactionalListenerException(ex, message, QueueUtils.GetMessageQueueTransaction(null)); if (action == TransactionAction.Rollback) { #region Logging if (LOG.IsDebugEnabled) { LOG.Debug( "Exception handler's TransactionAction has rolled back MessageQueueTransaction for queue [" + mq.Path + "]"); } #endregion status.SetRollbackOnly(); return false; // no more peeking unless this is the last listener thread } else { LOG.Info("Committing MessageQueueTransaction due to explicit commit request by exception handler."); } } finally { message.Dispose(); } return true; }