Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » jms » connection » [javadoc | source]
org.springframework.jms.connection
public class: JmsTransactionManager [javadoc | source]
java.lang.Object
   org.springframework.transaction.support.AbstractPlatformTransactionManager
      org.springframework.jms.connection.JmsTransactionManager

All Implemented Interfaces:
    InitializingBean, ResourceTransactionManager, PlatformTransactionManager, Serializable

Direct Known Subclasses:
    JmsTransactionManager102

org.springframework.transaction.PlatformTransactionManager implementation for a single JMS javax.jms.ConnectionFactory . Binds a JMS Connection/Session pair from the specified ConnectionFactory to the thread, potentially allowing for one thread-bound Session per ConnectionFactory.

NOTE: This class requires a JMS 1.1+ provider because it builds on the domain-independent API. Use the JmsTransactionManager102 subclass for a JMS 1.0.2 provider, e.g. when running on a J2EE 1.3 server.

This local strategy is an alternative to executing JMS operations within JTA transactions. Its advantage is that it is able to work in any environment, for example a standalone application or a test suite, with any message broker as target. However, this strategy is not able to provide XA transactions, for example in order to share transactions between messaging and database access. A full JTA/XA setup is required for XA transactions, typically using Spring's org.springframework.transaction.jta.JtaTransactionManager as strategy.

Application code is required to retrieve the transactional JMS Session via ConnectionFactoryUtils#getTransactionalSession instead of a standard J2EE-style ConnectionFactory#createConnection() call with subsequent Session creation. Spring's org.springframework.jms.core.JmsTemplate will autodetect a thread-bound Session and automatically participate in it.

Alternatively, you can allow application code to work with the standard J2EE-style lookup pattern on a ConnectionFactory, for example for legacy code that is not aware of Spring at all. In that case, define a TransactionAwareConnectionFactoryProxy for your target ConnectionFactory, which will automatically participate in Spring-managed transactions.

This transaction strategy will typically be used in combination with SingleConnectionFactory , which uses a single JMS Connection for all JMS access in order to avoid the overhead of repeated Connection creation, typically in a standalone application. Each transaction will then share the same JMS Connection, while still using its own individual JMS Session.

Transaction synchronization is turned off by default, as this manager might be used alongside a datastore-based Spring transaction manager such as the JDBC org.springframework.jdbc.datasource.DataSourceTransactionManager , which has stronger needs for synchronization.

Fields inherited from org.springframework.transaction.support.AbstractPlatformTransactionManager:
SYNCHRONIZATION_ALWAYS,  SYNCHRONIZATION_ON_ACTUAL_TRANSACTION,  SYNCHRONIZATION_NEVER,  logger
Constructor:
 public JmsTransactionManager() 
 public JmsTransactionManager(ConnectionFactory connectionFactory) 
    Create a new JmsTransactionManager, given a ConnectionFactory.
    Parameters:
    connectionFactory - the ConnectionFactory to obtain connections from
Method from org.springframework.jms.connection.JmsTransactionManager Summary:
afterPropertiesSet,   createConnection,   createSession,   doBegin,   doCleanupAfterCompletion,   doCommit,   doGetTransaction,   doResume,   doRollback,   doSetRollbackOnly,   doSuspend,   getConnectionFactory,   getResourceFactory,   isExistingTransaction,   setConnectionFactory
Methods from org.springframework.transaction.support.AbstractPlatformTransactionManager:
commit,   determineTimeout,   doBegin,   doCleanupAfterCompletion,   doCommit,   doGetTransaction,   doResume,   doRollback,   doSetRollbackOnly,   doSuspend,   getDefaultTimeout,   getTransaction,   getTransactionSynchronization,   invokeAfterCompletion,   isExistingTransaction,   isFailEarlyOnGlobalRollbackOnly,   isGlobalRollbackOnParticipationFailure,   isNestedTransactionAllowed,   isRollbackOnCommitFailure,   isValidateExistingTransaction,   newTransactionStatus,   prepareForCommit,   registerAfterCompletionWithExistingTransaction,   resume,   rollback,   setDefaultTimeout,   setFailEarlyOnGlobalRollbackOnly,   setGlobalRollbackOnParticipationFailure,   setNestedTransactionAllowed,   setRollbackOnCommitFailure,   setTransactionSynchronization,   setTransactionSynchronizationName,   setValidateExistingTransaction,   shouldCommitOnGlobalRollbackOnly,   suspend,   triggerBeforeCommit,   triggerBeforeCompletion,   useSavepointForNestedTransaction
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.jms.connection.JmsTransactionManager Detail:
 public  void afterPropertiesSet() 
    Make sure the ConnectionFactory has been set.
 protected Connection createConnection() throws JMSException 
    Create a JMS Connection via this template's ConnectionFactory.

    This implementation uses JMS 1.1 API.

 protected Session createSession(Connection con) throws JMSException 
    Create a JMS Session for the given Connection.

    This implementation uses JMS 1.1 API.

 protected  void doBegin(Object transaction,
    TransactionDefinition definition) 
 protected  void doCleanupAfterCompletion(Object transaction) 
 protected  void doCommit(DefaultTransactionStatus status) 
 protected Object doGetTransaction() 
 protected  void doResume(Object transaction,
    Object suspendedResources) 
 protected  void doRollback(DefaultTransactionStatus status) 
 protected  void doSetRollbackOnly(DefaultTransactionStatus status) 
 protected Object doSuspend(Object transaction) 
 public ConnectionFactory getConnectionFactory() 
    Return the JMS ConnectionFactory that this instance should manage transactions for.
 public Object getResourceFactory() 
 protected boolean isExistingTransaction(Object transaction) 
 public  void setConnectionFactory(ConnectionFactory cf) 
    Set the JMS ConnectionFactory that this instance should manage transactions for.