use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.
the class CciLocalTransactionManager method doBegin.
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
Connection con = null;
try {
con = getConnectionFactory().getConnection();
if (logger.isDebugEnabled()) {
logger.debug("Acquired Connection [" + con + "] for local CCI transaction");
}
txObject.setConnectionHolder(new ConnectionHolder(con));
txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
con.getLocalTransaction().begin();
int timeout = determineTimeout(definition);
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
txObject.getConnectionHolder().setTimeoutInSeconds(timeout);
}
TransactionSynchronizationManager.bindResource(getConnectionFactory(), txObject.getConnectionHolder());
} catch (NotSupportedException ex) {
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
throw new CannotCreateTransactionException("CCI Connection does not support local transactions", ex);
} catch (LocalTransactionException ex) {
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
throw new CannotCreateTransactionException("Could not begin local CCI transaction", ex);
} catch (Throwable ex) {
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
throw new TransactionSystemException("Unexpected failure on begin of CCI local transaction", ex);
}
}
use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.
the class WebLogicJtaTransactionManager method doJtaBegin.
@Override
protected void doJtaBegin(JtaTransactionObject txObject, TransactionDefinition definition) throws NotSupportedException, SystemException {
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(), definition.getName(), timeout);
} else {
/*
weblogic.transaction.UserTransaction wut = (weblogic.transaction.UserTransaction) ut;
wut.begin(definition.getName());
*/
this.beginWithNameMethod.invoke(txObject.getUserTransaction(), 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 = definition.getIsolationLevel();
/*
weblogic.transaction.Transaction wtx = (weblogic.transaction.Transaction) tx;
wtx.setProperty(ISOLATION_LEVEL_KEY, isolationLevel);
*/
this.setPropertyMethod.invoke(tx, 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());
}
}
use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.
the class JtaTransactionManager method registerAfterCompletionWithExistingTransaction.
@Override
protected void registerAfterCompletionWithExistingTransaction(Object transaction, List<TransactionSynchronization> synchronizations) {
JtaTransactionObject txObject = (JtaTransactionObject) transaction;
logger.debug("Registering after-completion synchronization with existing JTA transaction");
try {
doRegisterAfterCompletionWithJtaTransaction(txObject, synchronizations);
} catch (SystemException ex) {
throw new TransactionSystemException("JTA failure on registerSynchronization", ex);
} catch (Exception ex) {
// Note: JBoss throws plain RuntimeException with RollbackException as cause.
if (ex instanceof RollbackException || ex.getCause() instanceof RollbackException) {
logger.debug("Participating in existing JTA transaction that has been marked for rollback: " + "cannot register Spring after-completion callbacks with outer JTA transaction - " + "immediately performing Spring after-completion callbacks with outcome status 'rollback'. " + "Original exception: " + ex);
invokeAfterCompletion(synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
} else {
logger.debug("Participating in existing JTA transaction, but unexpected internal transaction " + "state encountered: cannot register Spring after-completion callbacks with outer JTA " + "transaction - processing Spring after-completion callbacks with outcome status 'unknown'" + "Original exception: " + ex);
invokeAfterCompletion(synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
}
}
}
use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.
the class WebLogicJtaTransactionManager method loadWebLogicTransactionClasses.
private void loadWebLogicTransactionClasses() throws TransactionSystemException {
try {
Class<?> userTransactionClass = getClass().getClassLoader().loadClass(USER_TRANSACTION_CLASS_NAME);
this.weblogicUserTransactionAvailable = userTransactionClass.isInstance(getUserTransaction());
if (this.weblogicUserTransactionAvailable) {
this.beginWithNameMethod = userTransactionClass.getMethod("begin", String.class);
this.beginWithNameAndTimeoutMethod = userTransactionClass.getMethod("begin", String.class, int.class);
logger.info("Support for WebLogic transaction names available");
} else {
logger.info("Support for WebLogic transaction names not available");
}
// Obtain WebLogic ClientTransactionManager interface.
Class<?> transactionManagerClass = getClass().getClassLoader().loadClass(CLIENT_TRANSACTION_MANAGER_CLASS_NAME);
logger.debug("WebLogic ClientTransactionManager found");
this.weblogicTransactionManagerAvailable = transactionManagerClass.isInstance(getTransactionManager());
if (this.weblogicTransactionManagerAvailable) {
Class<?> transactionClass = getClass().getClassLoader().loadClass(TRANSACTION_CLASS_NAME);
this.forceResumeMethod = transactionManagerClass.getMethod("forceResume", Transaction.class);
this.setPropertyMethod = transactionClass.getMethod("setProperty", String.class, Serializable.class);
logger.debug("Support for WebLogic forceResume available");
} else {
logger.warn("Support for WebLogic forceResume not available");
}
} catch (Exception ex) {
throw new TransactionSystemException("Could not initialize WebLogicJtaTransactionManager because WebLogic API classes are not available", ex);
}
}
use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.
the class WebLogicJtaTransactionManager method retrieveTransactionManager.
@Override
protected TransactionManager retrieveTransactionManager() throws TransactionSystemException {
loadWebLogicTransactionHelper();
try {
logger.debug("Retrieving JTA TransactionManager from WebLogic TransactionHelper");
Method getTransactionManagerMethod = this.transactionHelper.getClass().getMethod("getTransactionManager");
return (TransactionManager) getTransactionManagerMethod.invoke(this.transactionHelper);
} catch (InvocationTargetException ex) {
throw new TransactionSystemException("WebLogic's TransactionHelper.getTransactionManager() method failed", ex.getTargetException());
} catch (Exception ex) {
throw new TransactionSystemException("Could not invoke WebLogic's TransactionHelper.getTransactionManager() method", ex);
}
}
Aggregations