use of javax.transaction.NotSupportedException in project partyline by Commonjava.
the class InfinispanTransactionalGLM method executeInTransaction.
/**
* If transaction not supported, we throw PartylineException to inform the caller to not try again. For other
* transactional exceptions, we return null to let caller retry later.
* @param txManager
* @param operation
* @param <T>
* @return
* @throws PartylineException if transaction not supported
*/
private <T> T executeInTransaction(TransactionManager txManager, TransactionalOperation<T> operation) throws PartylineException {
try {
txManager.begin();
} catch (NotSupportedException e) {
throw new PartylineException("Transaction not supported", e);
} catch (SystemException e) {
logger.error("Failed to begin transaction.", e);
return null;
}
try {
T ret = operation.execute();
txManager.commit();
return ret;
} catch (SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
logger.warn("Failed to commit transaction.", e);
return null;
} catch (Exception e) {
try {
logger.error("Failed to execute. Rolling back.", e);
txManager.rollback();
} catch (SystemException e1) {
logger.error("Exception during rollback", e1);
}
}
return null;
}
use of javax.transaction.NotSupportedException 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 javax.transaction.NotSupportedException in project wildfly by wildfly.
the class MockTransactionManager method begin.
@Override
public void begin() throws NotSupportedException, SystemException {
Transaction tx = currentTx.get();
if (tx != null)
throw new NotSupportedException("Nested tx are not supported");
tx = mock(Transaction.class);
currentTx.set(tx);
}
use of javax.transaction.NotSupportedException in project carbon-business-process by wso2.
the class TransactionManagerProvider method doNonTransactionalWork.
public void doNonTransactionalWork(Runnable runnable) throws NotSupportedException {
TransactionManager tm;
Transaction transaction;
try {
tm = getTransactionManager();
transaction = tm.suspend();
} catch (Exception e) {
NotSupportedException nse = new NotSupportedException(e.getMessage());
nse.initCause(e);
throw nse;
}
runnable.run();
try {
tm.resume(transaction);
} catch (Exception e) {
try {
transaction.setRollbackOnly();
} catch (SystemException se2) {
throw new GeneralException(se2);
}
NotSupportedException nse = new NotSupportedException(e.getMessage());
nse.initCause(e);
throw nse;
}
}
use of javax.transaction.NotSupportedException in project carbon-business-process by wso2.
the class TransactionManagerProvider method doNonTransactionalWork.
public void doNonTransactionalWork(java.lang.Runnable runnable) throws NotSupportedException {
TransactionManager tm;
Transaction transaction;
try {
tm = getTransactionManager();
transaction = tm.suspend();
} catch (Exception e) {
NotSupportedException nse = new NotSupportedException(e.getMessage());
nse.initCause(e);
throw nse;
}
runnable.run();
try {
tm.resume(transaction);
} catch (Exception e) {
try {
transaction.setRollbackOnly();
} catch (SystemException se2) {
throw new GeneralException(se2);
}
NotSupportedException nse = new NotSupportedException(e.getMessage());
nse.initCause(e);
throw nse;
}
}
Aggregations