use of com.sun.enterprise.transaction.TransactionManagerHelper in project Payara by payara.
the class TransactionalInterceptorRequired method transactional.
@AroundInvoke
public Object transactional(InvocationContext ctx) throws Exception {
_logger.log(FINE, CDI_JTA_REQUIRED);
if (isLifeCycleMethod(ctx)) {
return proceed(ctx);
}
setTransactionalTransactionOperationsManger(false);
try {
boolean isTransactionStarted = false;
if (getTransactionManager().getTransaction() == null) {
_logger.log(FINE, CDI_JTA_MBREQUIRED);
try {
getTransactionManager().begin();
TransactionManager transactionManager = getTransactionManager();
if (transactionManager instanceof TransactionManagerHelper) {
((TransactionManagerHelper) transactionManager).preInvokeTx(true);
}
} catch (Exception exception) {
_logger.log(FINE, CDI_JTA_MBREQUIREDBT, exception);
throw new TransactionalException("Managed bean with Transactional annotation and TxType of REQUIRED " + "encountered exception during begin " + exception, exception);
}
isTransactionStarted = true;
}
Object proceed = null;
try {
proceed = proceed(ctx);
} finally {
if (isTransactionStarted) {
try {
TransactionManager transactionManager = getTransactionManager();
if (transactionManager instanceof TransactionManagerHelper) {
((TransactionManagerHelper) transactionManager).postInvokeTx(false, true);
}
// Exception handling for proceed method call above can set TM/TRX as setRollbackOnly
if (getTransactionManager().getTransaction().getStatus() == STATUS_MARKED_ROLLBACK) {
getTransactionManager().rollback();
} else {
getTransactionManager().commit();
}
} catch (Exception exception) {
_logger.log(FINE, CDI_JTA_MBREQUIREDCT, exception);
throw new TransactionalException("Managed bean with Transactional annotation and TxType of REQUIRED " + "encountered exception during commit " + exception, exception);
}
}
}
return proceed;
} finally {
resetTransactionOperationsManager();
}
}
use of com.sun.enterprise.transaction.TransactionManagerHelper in project Payara by payara.
the class TransactionalInterceptorRequiresNew method transactional.
@AroundInvoke
public Object transactional(InvocationContext ctx) throws Exception {
_logger.log(FINE, CDI_JTA_REQNEW);
if (isLifeCycleMethod(ctx)) {
return proceed(ctx);
}
setTransactionalTransactionOperationsManger(false);
try {
Transaction suspendedTransaction = null;
if (getTransactionManager().getTransaction() != null) {
_logger.log(FINE, CDI_JTA_MBREQNEW);
suspendedTransaction = getTransactionManager().suspend();
// todo catch, wrap in new transactional exception and throw
}
try {
getTransactionManager().begin();
TransactionManager tm = getTransactionManager();
if (tm instanceof TransactionManagerHelper) {
((TransactionManagerHelper) tm).preInvokeTx(true);
}
} catch (Exception exception) {
_logger.log(FINE, CDI_JTA_MBREQNEWBT, exception);
throw new TransactionalException("Managed bean with Transactional annotation and TxType of REQUIRES_NEW " + "encountered exception during begin " + exception, exception);
}
Object proceed = null;
try {
proceed = proceed(ctx);
} finally {
try {
TransactionManager tm = getTransactionManager();
if (tm instanceof TransactionManagerHelper) {
((TransactionManagerHelper) tm).postInvokeTx(false, true);
}
// Exception handling for proceed method call above can set TM/TRX as setRollbackOnly
if (getTransactionManager().getTransaction().getStatus() == STATUS_MARKED_ROLLBACK) {
getTransactionManager().rollback();
} else {
getTransactionManager().commit();
}
} catch (Exception exception) {
_logger.log(FINE, CDI_JTA_MBREQNEWCT, exception);
throw new TransactionalException("Managed bean with Transactional annotation and TxType of REQUIRES_NEW " + "encountered exception during commit " + exception, exception);
}
if (suspendedTransaction != null) {
try {
getTransactionManager().resume(suspendedTransaction);
} catch (Exception exception) {
throw new TransactionalException("Managed bean with Transactional annotation and TxType of REQUIRED " + "encountered exception during resume " + exception, exception);
}
}
}
return proceed;
} finally {
resetTransactionOperationsManager();
}
}
Aggregations