use of javax.transaction.TransactionalException in project Payara by payara.
the class TransactionalInterceptorMandatory method transactional.
@AroundInvoke
public Object transactional(InvocationContext ctx) throws Exception {
_logger.log(FINE, CDI_JTA_MANDATORY);
if (isLifeCycleMethod(ctx)) {
return proceed(ctx);
}
setTransactionalTransactionOperationsManger(false);
try {
if (getTransactionManager().getTransaction() == null) {
throw new TransactionalException("TransactionRequiredException thrown from TxType.MANDATORY transactional interceptor.", new TransactionRequiredException("Managed bean with Transactional annotation and TxType of " + "MANDATORY called outside of a transaction context"));
}
return proceed(ctx);
} finally {
resetTransactionOperationsManager();
}
}
use of javax.transaction.TransactionalException in project Payara by payara.
the class TransactionalInterceptorNotSupported method transactional.
@AroundInvoke
public Object transactional(InvocationContext ctx) throws Exception {
_logger.log(FINE, CDI_JTA_NOTSUPPORTED);
if (isLifeCycleMethod(ctx)) {
return proceed(ctx);
}
setTransactionalTransactionOperationsManger(true);
try {
Transaction transaction = null;
if (getTransactionManager().getTransaction() != null) {
_logger.log(FINE, CDI_JTA_MBNOTSUPPORTED);
try {
transaction = getTransactionManager().suspend();
} catch (Exception exception) {
_logger.log(FINE, CDI_JTA_MBNOTSUPPORTEDTX, exception);
throw new TransactionalException("Managed bean with Transactional annotation and TxType of NOT_SUPPORTED " + "called inside a transaction context. Suspending transaction failed due to " + exception, exception);
}
}
Object proceed = null;
try {
proceed = proceed(ctx);
} finally {
if (transaction != null) {
try {
getTransactionManager().resume(transaction);
} catch (Exception exception) {
throw new TransactionalException("Managed bean with Transactional annotation and TxType of NOT_SUPPORTED " + "encountered exception during resume " + exception, exception);
}
}
}
return proceed;
} finally {
resetTransactionOperationsManager();
}
}
use of javax.transaction.TransactionalException 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 javax.transaction.TransactionalException in project crnk-framework by crnk-project.
the class CdiTransactionRunnerTest method testTransactionalRuntimeExceptionToBeUnwrapped.
@Test
public void testTransactionalRuntimeExceptionToBeUnwrapped() throws Exception {
Callable callable = Mockito.mock(Callable.class);
Mockito.when(callable.call()).thenThrow(new TransactionalException("a", new IllegalStateException("b")));
try {
runner.doInTransaction(callable);
Assert.fail();
} catch (IllegalStateException e) {
Assert.assertEquals("b", e.getMessage());
}
Mockito.verify(callable, Mockito.times(1)).call();
}
use of javax.transaction.TransactionalException in project narayana by jbosstm.
the class TransactionalImplTest method testClassLevelDefaultNeverExistingTX.
@Test
public void testClassLevelDefaultNeverExistingTX() throws Exception {
TransactionManager tm = Utills.getTransactionManager();
Utills.assertTransactionActive(false);
tm.begin();
Utills.assertTransactionActive(true);
try {
testTransactionalBean.invokeWithCLassLevelDefault();
Assert.fail("Expected Exception to be thrown, but it was not");
} catch (TransactionalException e) {
// expected
}
Utills.assertTransactionActive(true);
tm.commit();
Utills.assertTransactionActive(false);
}
Aggregations