org.springframework.transaction.jta
public class: WebSphereUowTransactionManager [javadoc |
source]
java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.jta.JtaTransactionManager
org.springframework.transaction.jta.WebSphereUowTransactionManager
All Implemented Interfaces:
CallbackPreferringPlatformTransactionManager, Serializable, TransactionFactory, InitializingBean, PlatformTransactionManager
WebSphere-specific PlatformTransactionManager implementation that delegates
to a
com.ibm.wsspi.uow.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 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 method. However,
transaction suspension is not supported in this getTransaction
style (unless you explicitly specify a #setTransactionManager reference,
despite the official WebSphere recommendations). Use the #execute style
for any code that might require transaction suspension.
This transaction manager is compatible with WebSphere 7.0 as well as recent
WebSphere 6.0.x and 6.1.x versions. Check the documentation for your specific
WebSphere version to find out whether UOWManager support is available. If it
is not available, consider using Spring's standard JtaTransactionManager
class, if necessary specifying the WebSphereTransactionManagerFactoryBean
as "transactionManager" through the corresponding bean property. However, note
that transaction suspension is not officially supported in such a scenario
(despite it being known to work properly).
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.
| Field Summary |
|---|
| public static final String | DEFAULT_UOW_MANAGER_NAME | Default JNDI location for the WebSphere UOWManager. |
| Methods from org.springframework.transaction.jta.JtaTransactionManager: |
|---|
|
afterPropertiesSet, applyIsolationLevel, applyTimeout, buildUserTransaction, checkUserTransactionAndTransactionManager, createTransaction, doBegin, doCommit, doGetJtaTransaction, doGetTransaction, doJtaBegin, doJtaResume, doJtaSuspend, doRegisterAfterCompletionWithJtaTransaction, doResume, doRollback, doSetRollbackOnly, doSuspend, findTransactionManager, findTransactionSynchronizationRegistry, findUserTransaction, getJndiEnvironment, getJndiTemplate, getTransactionManager, getUserTransaction, initTransactionSynchronizationRegistry, initUserTransactionAndTransactionManager, isExistingTransaction, lookupTransactionManager, lookupTransactionSynchronizationRegistry, lookupUserTransaction, registerAfterCompletionWithExistingTransaction, retrieveTransactionManager, retrieveTransactionSynchronizationRegistry, retrieveUserTransaction, setAllowCustomIsolationLevels, setAutodetectTransactionManager, setAutodetectUserTransaction, setCacheUserTransaction, setJndiEnvironment, setJndiTemplate, setTransactionManager, setTransactionManagerName, setTransactionSynchronizationRegistryName, setUserTransaction, setUserTransactionName, shouldCommitOnGlobalRollbackOnly, useSavepointForNestedTransaction |
| 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 |
| Method from org.springframework.transaction.jta.WebSphereUowTransactionManager Detail: |
public void afterPropertiesSet() throws TransactionSystemException {
initUserTransactionAndTransactionManager();
// Fetch UOWManager handle from JNDI, if necessary.
if (this.uowManager == null) {
if (this.uowManagerName != null) {
this.uowManager = lookupUowManager(this.uowManagerName);
}
else {
throw new IllegalStateException("'uowManager' or 'uowManagerName' is required");
}
}
}
|
protected void doRegisterAfterCompletionWithJtaTransaction(JtaTransactionObject txObject,
List synchronizations) {
this.uowManager.registerInterposedSynchronization(new JtaAfterCompletionSynchronization(synchronizations));
}
Registers the synchronizations as interposed JTA Synchronization on the UOWManager. |
public Object execute(TransactionDefinition definition,
TransactionCallback callback) throws TransactionException {
if (definition == null) {
// Use defaults if no transaction definition given.
definition = new DefaultTransactionDefinition();
}
if (definition.getTimeout() < TransactionDefinition.TIMEOUT_DEFAULT) {
throw new InvalidTimeoutException("Invalid transaction timeout", definition.getTimeout());
}
int pb = definition.getPropagationBehavior();
boolean existingTx = (this.uowManager.getUOWStatus() != UOWSynchronizationRegistry.UOW_STATUS_NONE &&
this.uowManager.getUOWType() != UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION);
int uowType = UOWSynchronizationRegistry.UOW_TYPE_GLOBAL_TRANSACTION;
boolean joinTx = false;
boolean newSynch = false;
if (existingTx) {
if (pb == TransactionDefinition.PROPAGATION_NEVER) {
throw new IllegalTransactionStateException(
"Transaction propagation 'never' but existing transaction found");
}
if (pb == TransactionDefinition.PROPAGATION_NESTED) {
throw new NestedTransactionNotSupportedException(
"Transaction propagation 'nested' not supported for WebSphere UOW transactions");
}
if (pb == TransactionDefinition.PROPAGATION_SUPPORTS ||
pb == TransactionDefinition.PROPAGATION_REQUIRED || pb == TransactionDefinition.PROPAGATION_MANDATORY) {
joinTx = true;
newSynch = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
}
else if (pb == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
uowType = UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION;
newSynch = (getTransactionSynchronization() == SYNCHRONIZATION_ALWAYS);
}
else {
newSynch = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
}
}
else {
if (pb == TransactionDefinition.PROPAGATION_MANDATORY) {
throw new IllegalTransactionStateException(
"Transaction propagation 'mandatory' but no existing transaction found");
}
if (pb == TransactionDefinition.PROPAGATION_SUPPORTS ||
pb == TransactionDefinition.PROPAGATION_NOT_SUPPORTED || pb == TransactionDefinition.PROPAGATION_NEVER) {
uowType = UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION;
newSynch = (getTransactionSynchronization() == SYNCHRONIZATION_ALWAYS);
}
else {
newSynch = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER);
}
}
boolean debug = logger.isDebugEnabled();
if (debug) {
logger.debug("Creating new transaction with name [" + definition.getName() + "]: " + definition);
}
SuspendedResourcesHolder suspendedResources = (existingTx && !joinTx ? suspend(null) : null);
try {
if (definition.getTimeout() > TransactionDefinition.TIMEOUT_DEFAULT) {
this.uowManager.setUOWTimeout(uowType, definition.getTimeout());
}
if (debug) {
logger.debug("Invoking WebSphere UOW action: type=" + uowType + ", join=" + joinTx);
}
UOWActionAdapter action = new UOWActionAdapter(
definition, callback, (uowType == UOWManager.UOW_TYPE_GLOBAL_TRANSACTION), !joinTx, newSynch, debug);
this.uowManager.runUnderUOW(uowType, joinTx, action);
if (debug) {
logger.debug("Returned from WebSphere UOW action: type=" + uowType + ", join=" + joinTx);
}
return action.getResult();
}
catch (UOWException ex) {
throw new TransactionSystemException("UOWManager transaction processing failed", ex);
}
catch (UOWActionException ex) {
throw new TransactionSystemException("UOWManager threw unexpected UOWActionException", ex);
}
finally {
if (suspendedResources != null) {
resume(null, suspendedResources);
}
}
}
|
protected UOWManager lookupUowManager(String uowManagerName) throws TransactionSystemException {
try {
if (logger.isDebugEnabled()) {
logger.debug("Retrieving WebSphere UOWManager from JNDI location [" + uowManagerName + "]");
}
return (UOWManager) getJndiTemplate().lookup(uowManagerName, UOWManager.class);
}
catch (NamingException ex) {
throw new TransactionSystemException(
"WebSphere UOWManager is not available at JNDI location [" + uowManagerName + "]", ex);
}
}
Look up the WebSphere UOWManager in JNDI via the configured name.
Called by afterPropertiesSet if no direct UOWManager reference was set.
Can be overridden in subclasses to provide a different UOWManager object. |
public void setUowManager(UOWManager uowManager) {
this.uowManager = uowManager;
}
Set the WebSphere UOWManager to use as direct reference.
Typically just used for test setups; in a J2EE environment,
the UOWManager will always be fetched from JNDI. |
public void setUowManagerName(String uowManagerName) {
this.uowManagerName = uowManagerName;
}
Set the JNDI name of the WebSphere UOWManager.
The default "java:comp/websphere/UOWManager" is used if not set. |