org.springframework.transaction.jta
public class: WebLogicJtaTransactionManager [javadoc |
source]
java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.transaction.jta.JtaTransactionManager
org.springframework.transaction.jta.WebLogicJtaTransactionManager
All Implemented Interfaces:
Serializable, TransactionFactory, InitializingBean, PlatformTransactionManager
Special
JtaTransactionManager variant for BEA WebLogic (7.0, 8.1 and higher).
Supports the full power of Spring's transaction definitions on WebLogic's
transaction coordinator,
beyond standard JTA: transaction names,
per-transaction isolation levels, and proper resuming of transactions in all cases.
Uses WebLogic's special begin(name) method to start a JTA transaction,
in order to make Spring-driven transactions visible in WebLogic's transaction
monitor. In case of Spring's declarative transactions, the exposed name will
(by default) be the fully-qualified class name + "." + method name.
Supports a per-transaction isolation level through WebLogic's corresponding
JTA transaction property "ISOLATION LEVEL". This will apply the specified isolation
level (e.g. ISOLATION_SERIALIZABLE) to all JDBC Connections that participate in the
given transaction.
Invokes WebLogic's special forceResume method if standard JTA resume
failed, to also resume if the target transaction was marked rollback-only.
If you're not relying on this feature of transaction suspension in the first
place, Spring's standard JtaTransactionManager will behave properly too.
Automatically detects WebLogic Server 7.0 or 8.1+ and adapts accordingly.
Usage on a WebLogic client is also supported, although with restricted
functionality: transaction names cannot be applied there.
By default, the JTA UserTransaction and TransactionManager handles are
fetched directly from WebLogic's TransactionHelper (on 8.1+)
or TxHelper (on 7.0). This can be overridden by specifying
"userTransaction"/"userTransactionName" and "transactionManager"/"transactionManagerName",
passing in existing handles or specifying corresponding JNDI locations to look up.
Also see:
- org.springframework.transaction.TransactionDefinition#getName
- org.springframework.transaction.TransactionDefinition#getIsolationLevel
- weblogic.transaction.UserTransaction#begin(String)
- weblogic.transaction.Transaction#setProperty
- weblogic.transaction.TransactionManager#forceResume
- weblogic.transaction.TransactionHelper
- weblogic.transaction.TxHelper
- author:
Juergen - Hoeller
- since:
1.1 -
| 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.WebLogicJtaTransactionManager Detail: |
public void afterPropertiesSet() throws TransactionSystemException {
super.afterPropertiesSet();
loadWebLogicTransactionClasses();
}
|
public Transaction createTransaction(String name,
int timeout) throws SystemException, NotSupportedException {
if (this.weblogicUserTransactionAvailable && name != null) {
try {
if (timeout >= 0) {
this.beginWithNameAndTimeoutMethod.invoke(getUserTransaction(), new Object[] {name, new Integer(timeout)});
}
else {
this.beginWithNameMethod.invoke(getUserTransaction(), new Object[] {name});
}
}
catch (InvocationTargetException ex) {
if (ex.getTargetException() instanceof NotSupportedException) {
throw (NotSupportedException) ex.getTargetException();
}
else if (ex.getTargetException() instanceof SystemException) {
throw (SystemException) ex.getTargetException();
}
else if (ex.getTargetException() instanceof RuntimeException) {
throw (RuntimeException) ex.getTargetException();
}
else {
throw new SystemException(
"WebLogic's begin() method failed with an unexpected error: " + ex.getTargetException());
}
}
catch (Exception ex) {
throw new SystemException("Could not invoke WebLogic's UserTransaction.begin() method: " + ex);
}
return getTransactionManager().getTransaction();
}
else {
// No name specified - standard JTA is sufficient.
return super.createTransaction(name, timeout);
}
}
|
protected void doJtaBegin(JtaTransactionObject txObject,
TransactionDefinition definition) throws SystemException, NotSupportedException {
int timeout = determineTimeout(definition);
// Apply transaction name (if any) to WebLogic transaction.
if (this.weblogicUserTransactionAvailable && definition.getName() != null) {
try {
if (timeout > TransactionDefinition.TIMEOUT_DEFAULT) {
/*
weblogic.transaction.UserTransaction wut = (weblogic.transaction.UserTransaction) ut;
wut.begin(definition.getName(), timeout);
*/
this.beginWithNameAndTimeoutMethod.invoke(txObject.getUserTransaction(),
new Object[] {definition.getName(), new Integer(timeout)});
}
else {
/*
weblogic.transaction.UserTransaction wut = (weblogic.transaction.UserTransaction) ut;
wut.begin(definition.getName());
*/
this.beginWithNameMethod.invoke(txObject.getUserTransaction(),
new Object[] {definition.getName()});
}
}
catch (InvocationTargetException ex) {
throw new TransactionSystemException(
"WebLogic's UserTransaction.begin() method failed", ex.getTargetException());
}
catch (Exception ex) {
throw new TransactionSystemException(
"Could not invoke WebLogic's UserTransaction.begin() method", ex);
}
}
else {
// No WebLogic UserTransaction available or no transaction name specified
// - > standard JTA begin call.
applyTimeout(txObject, timeout);
txObject.getUserTransaction().begin();
}
// Specify isolation level, if any, through corresponding WebLogic transaction property.
if (this.weblogicTransactionManagerAvailable) {
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
try {
Transaction tx = getTransactionManager().getTransaction();
Integer isolationLevel = new Integer(definition.getIsolationLevel());
/*
weblogic.transaction.Transaction wtx = (weblogic.transaction.Transaction) tx;
wtx.setProperty(ISOLATION_LEVEL_KEY, isolationLevel);
*/
this.setPropertyMethod.invoke(tx, new Object[] {ISOLATION_LEVEL_KEY, isolationLevel});
}
catch (InvocationTargetException ex) {
throw new TransactionSystemException(
"WebLogic's Transaction.setProperty(String, Serializable) method failed", ex.getTargetException());
}
catch (Exception ex) {
throw new TransactionSystemException(
"Could not invoke WebLogic's Transaction.setProperty(String, Serializable) method", ex);
}
}
}
else {
applyIsolationLevel(txObject, definition.getIsolationLevel());
}
}
|
protected void doJtaResume(JtaTransactionObject txObject,
Object suspendedTransaction) throws SystemException, InvalidTransactionException {
try {
getTransactionManager().resume((Transaction) suspendedTransaction);
}
catch (InvalidTransactionException ex) {
if (!this.weblogicTransactionManagerAvailable) {
throw ex;
}
if (logger.isDebugEnabled()) {
logger.debug("Standard JTA resume threw InvalidTransactionException: " + ex.getMessage() +
" - trying WebLogic JTA forceResume");
}
/*
weblogic.transaction.TransactionManager wtm =
(weblogic.transaction.TransactionManager) getTransactionManager();
wtm.forceResume(suspendedTransaction);
*/
try {
this.forceResumeMethod.invoke(getTransactionManager(), new Object[] {suspendedTransaction});
}
catch (InvocationTargetException ex2) {
throw new TransactionSystemException(
"WebLogic's TransactionManager.forceResume(Transaction) method failed", ex2.getTargetException());
}
catch (Exception ex2) {
throw new TransactionSystemException(
"Could not access WebLogic's TransactionManager.forceResume(Transaction) method", ex2);
}
}
}
|
protected TransactionManager retrieveTransactionManager() throws TransactionSystemException {
loadWebLogicTransactionHelperClass();
try {
logger.debug("Retrieving JTA TransactionManager from WebLogic TransactionHelper/TxHelper");
Method getTransactionManagerMethod =
this.transactionHelperClass.getMethod("getTransactionManager", new Class[0]);
return (TransactionManager) getTransactionManagerMethod.invoke(this.transactionHelper, new Object[0]);
}
catch (InvocationTargetException ex) {
throw new TransactionSystemException(
"WebLogic's TransactionHelper/TxHelper.getTransactionManager() method failed", ex.getTargetException());
}
catch (Exception ex) {
throw new TransactionSystemException(
"Could not invoke WebLogic's TransactionHelper/TxHelper.getTransactionManager() method", ex);
}
}
|
protected UserTransaction retrieveUserTransaction() throws TransactionSystemException {
loadWebLogicTransactionHelperClass();
try {
logger.debug("Retrieving JTA UserTransaction from WebLogic TransactionHelper/TxHelper");
Method getUserTransactionMethod =
this.transactionHelperClass.getMethod("getUserTransaction", new Class[0]);
return (UserTransaction) getUserTransactionMethod.invoke(this.transactionHelper, new Object[0]);
}
catch (InvocationTargetException ex) {
throw new TransactionSystemException(
"WebLogic's TransactionHelper/TxHelper.getUserTransaction() method failed", ex.getTargetException());
}
catch (Exception ex) {
throw new TransactionSystemException(
"Could not invoke WebLogic's TransactionHelper/TxHelper.getUserTransaction() method", ex);
}
}
|