javax.transaction.TransactionalException Java Examples
The following examples show how to use
javax.transaction.TransactionalException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SagaStartAnnotationProcessorTest.java From txle with Apache License 2.0 | 6 votes |
@Test public void transformInterceptedException() { MessageSender sender = mock(MessageSender.class); SagaStartAnnotationProcessor sagaStartAnnotationProcessor = new SagaStartAnnotationProcessor(context, sender); doThrow(exception).when(sender).send(any(TxEvent.class)); try { sagaStartAnnotationProcessor.preIntercept(null, null, 0, null, 0); expectFailing(TransactionalException.class); } catch (TransactionalException e) { assertThat(e.getMessage(), is("exception")); assertThat(e.getCause(), instanceOf(RuntimeException.class)); assertThat(e.getCause().getMessage(), is("runtime exception")); } }
Example #2
Source File: TransactionalTest.java From tomee with Apache License 2.0 | 6 votes |
@Test public void neverInTx() throws SystemException { assertNull(OpenEJB.getTransactionManager().getTransaction()); try { bean.createTx(new Runnable() { @Override public void run() { bean.never(); } }); fail(); } catch (final TransactionalException e) { // expected } assertNull(OpenEJB.getTransactionManager().getTransaction()); }
Example #3
Source File: SagaStartAnnotationProcessorTest.java From servicecomb-pack with Apache License 2.0 | 6 votes |
@Test public void transformInterceptedException() { SagaMessageSender sender = mock(SagaMessageSender.class); SagaStartAnnotationProcessor sagaStartAnnotationProcessor = new SagaStartAnnotationProcessor( context, sender); doThrow(exception).when(sender).send(any(TxEvent.class)); try { sagaStartAnnotationProcessor.preIntercept(0); expectFailing(TransactionalException.class); } catch (TransactionalException e) { assertThat(e.getMessage(), is("exception")); assertThat(e.getCause(), instanceOf(RuntimeException.class)); assertThat(e.getCause().getMessage(), is("runtime exception")); } }
Example #4
Source File: RequiredInterceptor.java From openwebbeans-meecrowave with Apache License 2.0 | 6 votes |
@Override protected State start() { try { final Transaction transaction = transactionManager.getTransaction(); final Transaction current; if (transaction == null) { transactionManager.begin(); current = transactionManager.getTransaction(); } else { current = transaction; } return new State(transaction, current); } catch (final SystemException | NotSupportedException se) { throw new TransactionalException(se.getMessage(), se); } }
Example #5
Source File: NeverInterceptor.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected State start() { try { if (transactionManager.getTransaction() != null) { throw new TransactionalException("@Transactional(NEVER) but a transaction is running", new IllegalStateException()); } return STATE; } catch (final SystemException e) { throw new TransactionalException(e.getMessage(), e); } }
Example #6
Source File: NeverInterceptor.java From tomee with Apache License 2.0 | 5 votes |
@AroundInvoke public Object intercept(final InvocationContext ic) throws Exception { try { return super.intercept(ic); } catch (final RemoteException re) { throw new TransactionalException(re.getMessage(), new InvalidTransactionException(re.getMessage())); } }
Example #7
Source File: CdiJpaTest.java From hibernate-demos with Apache License 2.0 | 5 votes |
@Test public void canUseDeclarativeTxControl() throws Exception { try { transactionalTestService.doSomething(); fail("Exception raised due to missing yet required transaction wasn't raised"); } catch(TransactionalException e) { assertThat(e.getMessage().contains("ARJUNA016110")); } ut.begin(); assertThat(transactionalTestService.doSomething()).isEqualTo("Success"); ut.rollback(); }
Example #8
Source File: NotSupportedInterceptor.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected void commit(final State state) { if (state.old != null) { try { transactionManager.resume(state.old); } catch (final InvalidTransactionException | SystemException e) { throw new TransactionalException(e.getMessage(), e); } } }
Example #9
Source File: NotSupportedInterceptor.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected State start() { try { final Transaction tx = transactionManager.getTransaction(); return new State(tx, null); } catch (final SystemException e) { throw new TransactionalException(e.getMessage(), e); } }
Example #10
Source File: TransactionExceptionMapper.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override public Response toResponse(final TransactionalException ejbException) { final Throwable cause = ejbException.getCause(); if (cause != null) { final Class causeClass = cause.getClass(); final ExceptionMapper exceptionMapper = providers.getExceptionMapper(causeClass); if (exceptionMapper == null) { return defaultResponse(cause); } return exceptionMapper.toResponse(cause); } return defaultResponse(ejbException); }
Example #11
Source File: MandatoryInterceptor.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected State start() { try { final Transaction transaction = transactionManager.getTransaction(); return new State(transaction, transaction); } catch (final SystemException e) { throw new TransactionalException(e.getMessage(), e); } }
Example #12
Source File: RequiredInterceptor.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected void commit(final State state) { if (state.old != state.current) { try { state.current.commit(); } catch (final HeuristicMixedException | HeuristicRollbackException | RollbackException | SystemException e) { throw new TransactionalException(e.getMessage(), e); } } }
Example #13
Source File: RequiredNewInterceptor.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected State start() { try { final Transaction transaction = transactionManager.suspend(); transactionManager.begin(); return new State(transaction, transactionManager.getTransaction()); } catch (final SystemException | NotSupportedException se) { throw new TransactionalException(se.getMessage(), se); } }
Example #14
Source File: SupportsInterceptor.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected State start() { final Transaction transaction; try { transaction = transactionManager.getTransaction(); } catch (final SystemException e) { throw new TransactionalException(e.getMessage(), e); } return new State(transaction, transaction); }
Example #15
Source File: SagaStartAnnotationProcessor.java From txle with Apache License 2.0 | 5 votes |
@Override public AlphaResponse preIntercept(String parentTxId, String compensationMethod, int timeout, String retriesMethod, int retries, Object... message) { try { return sender.send(new SagaStartedEvent(omegaContext.globalTxId(), omegaContext.localTxId(), timeout, omegaContext.category())); } catch (OmegaException e) { throw new TransactionalException(e.getMessage(), e.getCause()); } }
Example #16
Source File: CdiTransactionRunner.java From katharsis-framework with Apache License 2.0 | 5 votes |
@Override public <T> T doInTransaction(Callable<T> callable) { try { return impl.doInTransaction(callable); } catch (TransactionalException e) { // unwrap since not usable, cause more interesting // (validationException, etc.) Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } throw e; } }
Example #17
Source File: TccStartAnnotationProcessorTest.java From servicecomb-pack with Apache License 2.0 | 5 votes |
@Test public void testSendTccStartEventFailed() { throwException = true; try { tccStartAnnotationProcessor .preIntercept(null, "TccStartMethod", 0); expectFailing(TransactionalException.class); } catch (TransactionalException e) { Assert.assertThat(e.getMessage(), Is.is("exception")); Assert.assertThat(e.getCause(), instanceOf(RuntimeException.class)); Assert.assertThat(e.getCause().getMessage(), Is.is("runtime exception")); } }
Example #18
Source File: TccStartAnnotationProcessor.java From servicecomb-pack with Apache License 2.0 | 5 votes |
public AlphaResponse preIntercept(String parentTxId, String methodName, int timeout) { try { return tccMessageSender.tccTransactionStart(new TccStartedEvent(omegaContext.globalTxId(), omegaContext.localTxId())); } catch (OmegaException e) { throw new TransactionalException(e.getMessage(), e.getCause()); } }
Example #19
Source File: SagaStartAnnotationProcessor.java From servicecomb-pack with Apache License 2.0 | 5 votes |
public AlphaResponse preIntercept(int timeout) { try { return sender .send(new SagaStartedEvent(omegaContext.globalTxId(), omegaContext.localTxId(), timeout)); } catch (OmegaException e) { throw new TransactionalException(e.getMessage(), e.getCause()); } }
Example #20
Source File: CdiTransactionRunnerTest.java From crnk-framework with Apache License 2.0 | 5 votes |
@Test public void testTransactionalExceptionNotToBeUnwrapped() throws Exception { Callable callable = Mockito.mock(Callable.class); Mockito.when(callable.call()).thenThrow(new TransactionalException("a", new IOException("b"))); try { runner.doInTransaction(callable); Assert.fail(); } catch (TransactionalException e) { Assert.assertEquals("a", e.getMessage()); } Mockito.verify(callable, Mockito.times(1)).call(); }
Example #21
Source File: CdiTransactionRunnerTest.java From crnk-framework with Apache License 2.0 | 5 votes |
@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(); }
Example #22
Source File: CdiTransactionRunner.java From crnk-framework with Apache License 2.0 | 5 votes |
@Override public <T> T doInTransaction(Callable<T> callable) { try { return impl.doInTransaction(callable); } catch (TransactionalException e) { // unwrap since not usable, cause more interesting // (validationException, etc.) Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } throw e; } }
Example #23
Source File: TransactionalInterceptorMandatory.java From quarkus with Apache License 2.0 | 5 votes |
@Override protected Object doIntercept(TransactionManager tm, Transaction tx, InvocationContext ic) throws Exception { if (tx == null) { throw new TransactionalException(jtaLogger.i18NLogger.get_tx_required(), new TransactionRequiredException()); } return invokeInCallerTx(ic, tx); }
Example #24
Source File: TransactionalInterceptorNever.java From quarkus with Apache License 2.0 | 5 votes |
@Override protected Object doIntercept(TransactionManager tm, Transaction tx, InvocationContext ic) throws Exception { if (tx != null) { throw new TransactionalException(jtaLogger.i18NLogger.get_tx_required(), new InvalidTransactionException()); } return invokeInNoTx(ic); }
Example #25
Source File: TransactionalTest.java From tomee with Apache License 2.0 | 4 votes |
@Test(expected = TransactionalException.class) public void mandatoryKO() { for (int i = 0; i < 2; i++) { bean.withoutATxIllThrowAnException(); } }