public class WebSphereUowTransactionManager extends JtaTransactionManager implements CallbackPreferringPlatformTransactionManager
UOWManager
instance, obtained from WebSphere's
JNDI environment. This allows Spring to leverage the full power of the WebSphere
transaction coordinator, including transaction suspension, in a manner that is
perfectly compliant with officially supported WebSphere API.
The CallbackPreferringPlatformTransactionManager
interface
implemented by this class indicates that callers should preferably pass in
a TransactionCallback
through the execute(org.springframework.transaction.TransactionDefinition, org.springframework.transaction.support.TransactionCallback<T>)
method, which
will be handled through the callback-based WebSphere UOWManager API instead
of through standard JTA API (UserTransaction / TransactionManager). This avoids
the use of the non-public javax.transaction.TransactionManager
API on WebSphere, staying within supported WebSphere API boundaries.
This transaction manager implementation derives from Spring's standard
JtaTransactionManager
, inheriting the capability to support programmatic
transaction demarcation via getTransaction
/ commit
/
rollback
calls through a JTA UserTransaction handle, for callers
that do not use the TransactionCallback-based execute(org.springframework.transaction.TransactionDefinition, org.springframework.transaction.support.TransactionCallback<T>)
method. However,
transaction suspension is not supported in this getTransaction
style (unless you explicitly specify a JtaTransactionManager.setTransactionManager(javax.transaction.TransactionManager)
reference,
despite the official WebSphere recommendations). Use the execute(org.springframework.transaction.TransactionDefinition, org.springframework.transaction.support.TransactionCallback<T>)
style
for any code that might require transaction suspension.
This transaction manager is compatible with WebSphere 6.1.0.9 and above. The default JNDI location for the UOWManager is "java:comp/websphere/UOWManager". If the location happens to differ according to your WebSphere documentation, simply specify the actual location through this transaction manager's "uowManagerName" bean property.
NOTE: This JtaTransactionManager is intended to refine specific transaction demarcation behavior on Spring's side. It will happily co-exist with independently configured WebSphere transaction strategies in your persistence provider, with no need to specifically connect those setups in any way.
setUowManager(com.ibm.wsspi.uow.UOWManager)
,
setUowManagerName(java.lang.String)
,
UOWManager
,
Serialized FormAbstractPlatformTransactionManager.SuspendedResourcesHolder
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_UOW_MANAGER_NAME
Default JNDI location for the WebSphere UOWManager.
|
DEFAULT_TRANSACTION_SYNCHRONIZATION_REGISTRY_NAME, DEFAULT_USER_TRANSACTION_NAME, FALLBACK_TRANSACTION_MANAGER_NAMES
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
Constructor and Description |
---|
WebSphereUowTransactionManager()
Create a new WebSphereUowTransactionManager.
|
WebSphereUowTransactionManager(com.ibm.wsspi.uow.UOWManager uowManager)
Create a new WebSphereUowTransactionManager for the given UOWManager.
|
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Initialize the UserTransaction as well as the TransactionManager handle.
|
protected void |
doRegisterAfterCompletionWithJtaTransaction(JtaTransactionObject txObject,
java.util.List<TransactionSynchronization> synchronizations)
Registers the synchronizations as interposed JTA Synchronization on the UOWManager.
|
<T> T |
execute(TransactionDefinition definition,
TransactionCallback<T> callback)
Execute the action specified by the given callback object within a transaction.
|
protected com.ibm.wsspi.uow.UOWManager |
lookupDefaultUowManager()
Obtain the WebSphere UOWManager from the default JNDI location
"java:comp/websphere/UOWManager".
|
protected com.ibm.wsspi.uow.UOWManager |
lookupUowManager(java.lang.String uowManagerName)
Look up the WebSphere UOWManager in JNDI via the configured name.
|
void |
setUowManager(com.ibm.wsspi.uow.UOWManager uowManager)
Set the WebSphere UOWManager to use as direct reference.
|
void |
setUowManagerName(java.lang.String uowManagerName)
Set the JNDI name of the WebSphere UOWManager.
|
boolean |
supportsResourceAdapterManagedTransactions()
Returns
true since WebSphere ResourceAdapters (as exposed in JNDI)
implicitly perform transaction enlistment if the MessageEndpointFactory's
isDeliveryTransacted method returns true . |
applyIsolationLevel, applyTimeout, buildUserTransaction, checkUserTransactionAndTransactionManager, createTransaction, doBegin, doCleanupAfterCompletion, doCommit, doGetJtaTransaction, doGetTransaction, doJtaBegin, doJtaResume, doJtaSuspend, doResume, doRollback, doSetRollbackOnly, doSuspend, findTransactionManager, findTransactionSynchronizationRegistry, findUserTransaction, getJndiEnvironment, getJndiTemplate, getTransactionManager, getTransactionSynchronizationRegistry, getUserTransaction, initTransactionSynchronizationRegistry, initUserTransactionAndTransactionManager, isExistingTransaction, lookupTransactionManager, lookupTransactionSynchronizationRegistry, lookupUserTransaction, registerAfterCompletionWithExistingTransaction, retrieveTransactionManager, retrieveTransactionSynchronizationRegistry, retrieveUserTransaction, setAllowCustomIsolationLevels, setAutodetectTransactionManager, setAutodetectTransactionSynchronizationRegistry, setAutodetectUserTransaction, setCacheUserTransaction, setJndiEnvironment, setJndiTemplate, setTransactionManager, setTransactionManagerName, setTransactionSynchronizationRegistry, setTransactionSynchronizationRegistryName, setUserTransaction, setUserTransactionName, shouldCommitOnGlobalRollbackOnly, useSavepointForNestedTransaction
commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareForCommit, prepareSynchronization, prepareTransactionStatus, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, suspend, triggerBeforeCommit, triggerBeforeCompletion
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
commit, getTransaction, rollback
public static final java.lang.String DEFAULT_UOW_MANAGER_NAME
public WebSphereUowTransactionManager()
public WebSphereUowTransactionManager(com.ibm.wsspi.uow.UOWManager uowManager)
uowManager
- the WebSphere UOWManager to use as direct referencepublic void setUowManager(com.ibm.wsspi.uow.UOWManager uowManager)
Typically just used for test setups; in a Java EE environment, the UOWManager will always be fetched from JNDI.
public void setUowManagerName(java.lang.String uowManagerName)
public void afterPropertiesSet() throws TransactionSystemException
JtaTransactionManager
afterPropertiesSet
in interface InitializingBean
afterPropertiesSet
in class JtaTransactionManager
TransactionSystemException
JtaTransactionManager.initUserTransactionAndTransactionManager()
protected com.ibm.wsspi.uow.UOWManager lookupUowManager(java.lang.String uowManagerName) throws TransactionSystemException
uowManagerName
- the JNDI name of the UOWManagerTransactionSystemException
- if the JNDI lookup failedJtaTransactionManager.setJndiTemplate(org.springframework.jndi.JndiTemplate)
,
setUowManagerName(java.lang.String)
protected com.ibm.wsspi.uow.UOWManager lookupDefaultUowManager() throws TransactionSystemException
TransactionSystemException
- if the JNDI lookup failedJtaTransactionManager.setJndiTemplate(org.springframework.jndi.JndiTemplate)
protected void doRegisterAfterCompletionWithJtaTransaction(JtaTransactionObject txObject, java.util.List<TransactionSynchronization> synchronizations)
doRegisterAfterCompletionWithJtaTransaction
in class JtaTransactionManager
txObject
- the current transaction objectsynchronizations
- List of TransactionSynchronization objectsJtaTransactionManager.getTransactionManager()
,
Transaction.registerSynchronization(javax.transaction.Synchronization)
,
TransactionSynchronizationRegistry.registerInterposedSynchronization(javax.transaction.Synchronization)
public boolean supportsResourceAdapterManagedTransactions()
true
since WebSphere ResourceAdapters (as exposed in JNDI)
implicitly perform transaction enlistment if the MessageEndpointFactory's
isDeliveryTransacted
method returns true
.
In that case we'll simply skip the JtaTransactionManager.createTransaction(java.lang.String, int)
call.supportsResourceAdapterManagedTransactions
in interface TransactionFactory
supportsResourceAdapterManagedTransactions
in class JtaTransactionManager
MessageEndpointFactory.isDeliveryTransacted(java.lang.reflect.Method)
,
AbstractMessageEndpointFactory
,
TransactionFactory.createTransaction(java.lang.String, int)
@Nullable public <T> T execute(@Nullable TransactionDefinition definition, TransactionCallback<T> callback) throws TransactionException
CallbackPreferringPlatformTransactionManager
Allows for returning a result object created within the transaction, that is, a domain object or a collection of domain objects. A RuntimeException thrown by the callback is treated as a fatal exception that enforces a rollback. Such an exception gets propagated to the caller of the template.
execute
in interface CallbackPreferringPlatformTransactionManager
definition
- the definition for the transaction to wrap the callback incallback
- the callback object that specifies the transactional actionnull
if noneTransactionException
- in case of initialization, rollback, or system errors