|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.jms.connection.TransactionAwareConnectionFactoryProxy
public class TransactionAwareConnectionFactoryProxy
Proxy for a target JMS ConnectionFactory
, adding awareness of
Spring-managed transactions. Similar to a transactional JNDI ConnectionFactory
as provided by a J2EE server.
Messaging code which should remain unaware of Spring's JMS support can work with
this proxy to seamlessly participate in Spring-managed transactions. Note that the
transaction manager, for example JmsTransactionManager
, still needs to work
with the underlying ConnectionFactory, not with this proxy.
Make sure that TransactionAwareConnectionFactoryProxy is the outermost
ConnectionFactory of a chain of ConnectionFactory proxies/adapters.
TransactionAwareConnectionFactoryProxy can delegate either directly to the
target factory or to some intermediary adapter like
UserCredentialsConnectionFactoryAdapter
.
Delegates to ConnectionFactoryUtils
for automatically participating
in thread-bound transactions, for example managed by JmsTransactionManager
.
createSession
calls and close
calls on returned Sessions
will behave properly within a transaction, that is, always work on the transactional
Session. If not within a transaction, normal ConnectionFactory behavior applies.
Note that transactional JMS Sessions will be registered on a per-Connection
basis. To share the same JMS Session across a transaction, make sure that you
operate on the same JMS Connection handle - either through reusing the handle
or through configuring a SingleConnectionFactory
underneath.
Returned transactional Session proxies will implement the SessionProxy
interface to allow for access to the underlying target Session. This is only
intended for accessing vendor-specific Session API or for testing purposes
(e.g. to perform manual transaction control). For typical application purposes,
simply use the standard JMS Session interface.
UserCredentialsConnectionFactoryAdapter
,
SingleConnectionFactory
Nested Class Summary | |
---|---|
private static class |
TransactionAwareConnectionFactoryProxy.CloseSuppressingSessionInvocationHandler
Invocation handler that suppresses close calls for a transactional JMS Session. |
private class |
TransactionAwareConnectionFactoryProxy.TransactionAwareConnectionInvocationHandler
Invocation handler that exposes transactional Sessions for the underlying Connection. |
Field Summary | |
---|---|
private boolean |
synchedLocalTransactionAllowed
|
private javax.jms.ConnectionFactory |
targetConnectionFactory
|
Constructor Summary | |
---|---|
TransactionAwareConnectionFactoryProxy()
Create a new TransactionAwareConnectionFactoryProxy. |
|
TransactionAwareConnectionFactoryProxy(javax.jms.ConnectionFactory targetConnectionFactory)
Create a new TransactionAwareConnectionFactoryProxy. |
Method Summary | |
---|---|
javax.jms.Connection |
createConnection()
|
javax.jms.Connection |
createConnection(java.lang.String username,
java.lang.String password)
|
javax.jms.QueueConnection |
createQueueConnection()
|
javax.jms.QueueConnection |
createQueueConnection(java.lang.String username,
java.lang.String password)
|
javax.jms.TopicConnection |
createTopicConnection()
|
javax.jms.TopicConnection |
createTopicConnection(java.lang.String username,
java.lang.String password)
|
protected javax.jms.ConnectionFactory |
getTargetConnectionFactory()
Return the target ConnectionFactory that this ConnectionFactory should delegate to. |
protected javax.jms.Connection |
getTransactionAwareConnectionProxy(javax.jms.Connection target)
Wrap the given Connection with a proxy that delegates every method call to it but handles Session lookup in a transaction-aware fashion. |
protected boolean |
isSynchedLocalTransactionAllowed()
Return whether to allow for a local JMS transaction that is synchronized with a Spring-managed transaction. |
void |
setSynchedLocalTransactionAllowed(boolean synchedLocalTransactionAllowed)
Set whether to allow for a local JMS transaction that is synchronized with a Spring-managed transaction (where the main transaction might be a JDBC-based one for a specific DataSource, for example), with the JMS transaction committing right after the main transaction. |
void |
setTargetConnectionFactory(javax.jms.ConnectionFactory targetConnectionFactory)
Set the target ConnectionFactory that this ConnectionFactory should delegate to. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private boolean synchedLocalTransactionAllowed
private javax.jms.ConnectionFactory targetConnectionFactory
Constructor Detail |
---|
public TransactionAwareConnectionFactoryProxy()
public TransactionAwareConnectionFactoryProxy(javax.jms.ConnectionFactory targetConnectionFactory)
targetConnectionFactory
- the target ConnectionFactoryMethod Detail |
---|
public final void setTargetConnectionFactory(javax.jms.ConnectionFactory targetConnectionFactory)
protected javax.jms.ConnectionFactory getTargetConnectionFactory()
public void setSynchedLocalTransactionAllowed(boolean synchedLocalTransactionAllowed)
Default is "false": If not within a managed transaction that encompasses the underlying JMS ConnectionFactory, standard Sessions will be returned. Turn this flag on to allow participation in any Spring-managed transaction, with a local JMS transaction synchronized with the main transaction.
protected boolean isSynchedLocalTransactionAllowed()
public javax.jms.Connection createConnection() throws javax.jms.JMSException
createConnection
in interface javax.jms.ConnectionFactory
javax.jms.JMSException
public javax.jms.Connection createConnection(java.lang.String username, java.lang.String password) throws javax.jms.JMSException
createConnection
in interface javax.jms.ConnectionFactory
javax.jms.JMSException
public javax.jms.QueueConnection createQueueConnection() throws javax.jms.JMSException
createQueueConnection
in interface javax.jms.QueueConnectionFactory
javax.jms.JMSException
public javax.jms.QueueConnection createQueueConnection(java.lang.String username, java.lang.String password) throws javax.jms.JMSException
createQueueConnection
in interface javax.jms.QueueConnectionFactory
javax.jms.JMSException
public javax.jms.TopicConnection createTopicConnection() throws javax.jms.JMSException
createTopicConnection
in interface javax.jms.TopicConnectionFactory
javax.jms.JMSException
public javax.jms.TopicConnection createTopicConnection(java.lang.String username, java.lang.String password) throws javax.jms.JMSException
createTopicConnection
in interface javax.jms.TopicConnectionFactory
javax.jms.JMSException
protected javax.jms.Connection getTransactionAwareConnectionProxy(javax.jms.Connection target)
target
- the original Connection to wrap
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |