/// <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> /// <remarks> /// Transaction synchronization will already have been suspended. /// </remarks> /// <exception cref="Spring.Transaction.TransactionException"> /// in case of system errors. /// </exception> protected override object DoSuspend(object transaction) { MessageTransactionObject txObject = (MessageTransactionObject)transaction; txObject.ResourceHolder = null; return(TransactionSynchronizationManager.UnbindResource(ConnectionFactory)); }
/// <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) { MessageTransactionObject txObject = (MessageTransactionObject)transaction; TransactionSynchronizationManager.UnbindResource(ConnectionFactory); txObject.ResourceHolder.CloseAll(); txObject.ResourceHolder.Clear(); }
/// <summary> /// Get the MessageTransactionObject. /// </summary> /// <returns>he MessageTransactionObject.</returns> protected override object DoGetTransaction() { MessageTransactionObject txObject = new MessageTransactionObject(); txObject.ResourceHolder = (NmsResourceHolder)TransactionSynchronizationManager.GetResource(ConnectionFactory); return(txObject); }
/// <summary> /// Check if the given transaction object indicates an existing transaction /// (that is, a transaction which has already started). /// </summary> /// <param name="transaction">Transaction object returned by /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param> /// <returns> /// True if there is an existing transaction. /// </returns> /// <exception cref="Spring.Transaction.TransactionException"> /// In the case of system errors. /// </exception> protected override bool IsExistingTransaction(object transaction) { MessageTransactionObject txObject = transaction as MessageTransactionObject; if (txObject != null) { return(txObject.ResourceHolder != null); } return(false); }
/// <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> /// <remarks> /// Does not have to care about applying the propagation behavior, /// as this has already been handled by this abstract manager. /// </remarks> /// <exception cref="Spring.Transaction.TransactionException"> /// In the case of creation or system errors. /// </exception> protected override void DoBegin(object transaction, ITransactionDefinition definition) { //This is the default value defined in DefaultTransactionDefinition if (definition.TransactionIsolationLevel != IsolationLevel.ReadCommitted) { throw new InvalidIsolationLevelException("NMS does not support an isoliation level concept"); } MessageTransactionObject txObject = (MessageTransactionObject)transaction; IConnection con = null; ISession session = null; try { con = CreateConnection(); session = CreateSession(con); if (LOG.IsDebugEnabled) { log.Debug("Created NMS transaction on Session [" + session + "] from Connection [" + con + "]"); } txObject.ResourceHolder = new NmsResourceHolder(ConnectionFactory, con, session); txObject.ResourceHolder.SynchronizedWithTransaction = true; int timeout = DetermineTimeout(definition); if (timeout != DefaultTransactionDefinition.TIMEOUT_DEFAULT) { txObject.ResourceHolder.TimeoutInSeconds = timeout; } TransactionSynchronizationManager.BindResource(ConnectionFactory, txObject.ResourceHolder); } catch (NMSException ex) { if (session != null) { try { session.Close(); } catch (Exception) {} } if (con != null) { try { con.Close(); } catch (Exception) {} } throw new CannotCreateTransactionException("Could not create NMS Transaction", ex); } }
/// <summary> /// Perform an actual rollback on the given transaction. /// </summary> /// <param name="status">The status representation of the transaction.</param> /// <exception cref="Spring.Transaction.TransactionException"> /// In the case of system errors. /// </exception> protected override void DoRollback(DefaultTransactionStatus status) { MessageTransactionObject txObject = (MessageTransactionObject)status.Transaction; ISession session = txObject.ResourceHolder.GetSession(); try { if (status.Debug) { LOG.Debug("Rolling back NMS transaction on Session [" + session + "]"); } session.Rollback(); } catch (NMSException ex) { throw new TransactionSystemException("Could not roll back NMS transaction.", ex); } }
/// <summary> /// Perform an actual commit on the given transaction. /// </summary> /// <param name="status">The status representation of the transaction.</param> /// <exception cref="Spring.Transaction.TransactionException"> /// In the case of system errors. /// </exception> protected override void DoCommit(DefaultTransactionStatus status) { MessageTransactionObject txObject = (MessageTransactionObject)status.Transaction; ISession session = txObject.ResourceHolder.GetSession(); try { if (status.Debug) { LOG.Debug("Committing NMS transaction on Session [" + session + "]"); } session.Commit(); //Note that NMS does not have, TransactionRolledBackException //See https://issues.apache.org/activemq/browse/AMQNET-93 } catch (NMSException ex) { throw new TransactionSystemException("Could not commit NMS transaction.", ex); } }
/// <summary> /// Get the MessageTransactionObject. /// </summary> /// <returns>he MessageTransactionObject.</returns> protected override object DoGetTransaction() { MessageTransactionObject txObject = new MessageTransactionObject(); txObject.ResourceHolder = (NmsResourceHolder) TransactionSynchronizationManager.GetResource(ConnectionFactory); 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> /// <exception cref="Spring.Transaction.TransactionException"> /// In the case of system errors. /// </exception> protected override void DoSetRollbackOnly(DefaultTransactionStatus status) { MessageTransactionObject txObject = (MessageTransactionObject)status.Transaction; txObject.ResourceHolder.RollbackOnly = true; }