当前位置: 首页>>代码示例>>Java>>正文


Java TransactionalException类代码示例

本文整理汇总了Java中javax.transaction.TransactionalException的典型用法代码示例。如果您正苦于以下问题:Java TransactionalException类的具体用法?Java TransactionalException怎么用?Java TransactionalException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TransactionalException类属于javax.transaction包,在下文中一共展示了TransactionalException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transformInterceptedException

import javax.transaction.TransactionalException; //导入依赖的package包/类
@Test
public void transformInterceptedException() {
  MessageSender sender = mock(MessageSender.class);
  SagaStartAnnotationProcessor sagaStartAnnotationProcessor = new SagaStartAnnotationProcessor(context, sender);

  doThrow(exception).when(sender).send(any());

  try {
    sagaStartAnnotationProcessor.preIntercept(null, null);
    expectFailing(TransactionalException.class);
  } catch (TransactionalException e) {
    assertThat(e.getMessage(), is("exception"));
    assertThat(e.getCause(), instanceOf(RuntimeException.class));
    assertThat(e.getCause().getMessage(), is("runtime exception"));
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:17,代码来源:SagaStartAnnotationProcessorTest.java

示例2: neverInTx

import javax.transaction.TransactionalException; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:tomee,代码行数:17,代码来源:TransactionalTest.java

示例3: preIntercept

import javax.transaction.TransactionalException; //导入依赖的package包/类
@Override
public AlphaResponse preIntercept(String parentTxId, String compensationMethod, Object... message) {
  try {
    return sender.send(new SagaStartedEvent(omegaContext.globalTxId(), omegaContext.localTxId()));
  } catch (OmegaException e) {
    throw new TransactionalException(e.getMessage(), e.getCause());
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:9,代码来源:SagaStartAnnotationProcessor.java

示例4: doInTransaction

import javax.transaction.TransactionalException; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:15,代码来源:CdiTransactionRunner.java

示例5: testTransactionalRuntimeExceptionToBeUnwrapped

import javax.transaction.TransactionalException; //导入依赖的package包/类
@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();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:13,代码来源:CdiTransactionRunnerTest.java

示例6: testTransactionalExceptionNotToBeUnwrapped

import javax.transaction.TransactionalException; //导入依赖的package包/类
@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();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:13,代码来源:CdiTransactionRunnerTest.java

示例7: doInTransaction

import javax.transaction.TransactionalException; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:16,代码来源:CdiTransactionRunner.java

示例8: if

import javax.transaction.TransactionalException; //导入依赖的package包/类
public <T> T $$(Function<EntityManager, T> block) {
    if (beanManager.isEntityManagerExistsOpen()) {
        beanManager.getCurrentEntityManager().close();
    }
    final EntityManager em = beanManager.getCurrentEntityManager();
    final EntityTransaction transaction = em.getTransaction();
    if (transaction.isActive()) {
        throw new TransactionalException("Transactional block must not be called within current transaction.",
                new InvalidTransactionException("transaction in " + Thread.currentThread()));
    }

    Optional<Throwable> t = empty();

    try {
        transaction.begin();
        return block.apply(em);
    } catch (Throwable e) {
        t = of(e);
        e.printStackTrace();
    } finally {
        try {
            if (t.isPresent()) {
                t = performAndAddSuppressedException(transaction::rollback, t);
            } else {
                t = perform(transaction::commit);
                t.ifPresent(Throwable::printStackTrace);
            }
        } finally {
            boolean noExceptionBefore = !t.isPresent();
            t = performAndAddSuppressedException(em::close, t);
            t.filter(x -> noExceptionBefore).ifPresent(Throwable::printStackTrace);
        }

        t.ifPresent(x -> { throw new TransactionalException(x.getLocalizedMessage(), x); });
    }

    throw new AssertionError("unreachable statement");
}
 
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:39,代码来源:JPARule.java

示例9: shouldFailOnNeverTransaction

import javax.transaction.TransactionalException; //导入依赖的package包/类
@Test
@Transactional
public void shouldFailOnNeverTransaction() {
    exceptionHandler.expect(TransactionalException.class);
    exceptionHandler.expectMessage("Transaction not applicable to " +
            "@Transactional(value = Transactional.TxType.NEVER) " +
            "in bean method call " +
            "public void javaee.samples.frameworks.injection.transactional.injection.field.NeverOuterService.saveOuter(java.lang.String)");

        outerService.saveOuter("transaction");
        jpa.getCurrentEntityManager()
                .createQuery("select count(e) from MyEntity e", Long.class)
                .getSingleResult();
}
 
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:15,代码来源:TransactionalInterceptorWithFieldInjectionTest.java

示例10: shouldFailOnNonExistingMandatoryTransaction

import javax.transaction.TransactionalException; //导入依赖的package包/类
@Test
public void shouldFailOnNonExistingMandatoryTransaction() {
    exceptionHandler.expect(TransactionalException.class);
    exceptionHandler.expectMessage("Transaction not applicable to " +
            "@Transactional(value = Transactional.TxType.MANDATORY) " +
            "in bean method call " +
            "public void javaee.samples.frameworks.injection.transactional.injection.field.MandatoryOuterService.saveOuter(java.lang.String)");

    outerService.saveOuter("transaction");
    jpa.getCurrentEntityManager()
            .createQuery("select count(e) from MyEntity e", Long.class)
            .getSingleResult();
}
 
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:14,代码来源:TransactionalInterceptorWithFieldInjectionTest.java

示例11: shouldFailOnNeverTransaction

import javax.transaction.TransactionalException; //导入依赖的package包/类
@Test
@Transactional
public void shouldFailOnNeverTransaction() {
    exceptionHandler.expect(TransactionalException.class);
    exceptionHandler.expectMessage("Transaction not applicable to " +
            "@Transactional(value = Transactional.TxType.NEVER) " +
            "in bean method call " +
            "public void javaee.samples.frameworks.injection.transactional.injection.constructor.NeverOuterService.saveOuter(java.lang.String)");

        outerService.saveOuter("transaction");
        jpa.getCurrentEntityManager()
                .createQuery("select count(e) from MyEntity e", Long.class)
                .getSingleResult();
}
 
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:15,代码来源:TransactionalInterceptorWithConstructorInjectionTest.java

示例12: shouldFailOnNonExistingMandatoryTransaction

import javax.transaction.TransactionalException; //导入依赖的package包/类
@Test
public void shouldFailOnNonExistingMandatoryTransaction() {
    exceptionHandler.expect(TransactionalException.class);
    exceptionHandler.expectMessage("Transaction not applicable to " +
            "@Transactional(value = Transactional.TxType.MANDATORY) " +
            "in bean method call " +
            "public void javaee.samples.frameworks.injection.transactional.injection.constructor.MandatoryOuterService.saveOuter(java.lang.String)");

    outerService.saveOuter("transaction");
    jpa.getCurrentEntityManager()
            .createQuery("select count(e) from MyEntity e", Long.class)
            .getSingleResult();
}
 
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:14,代码来源:TransactionalInterceptorWithConstructorInjectionTest.java

示例13: intercept

import javax.transaction.TransactionalException; //导入依赖的package包/类
@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()));
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:9,代码来源:NeverInterceptor.java

示例14: throwTransactionalException

import javax.transaction.TransactionalException; //导入依赖的package包/类
private static void throwTransactionalException(TxType txType, Method m, Throwable cause) {
    throw new TransactionalException("Transaction not applicable to "
            + "@Transactional(value = Transactional.TxType." + txType + ") "
            + "in bean method call "
            + m.toGenericString(), cause);
}
 
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:7,代码来源:BeanManager.java

示例15: should_mandatory_throw_exception

import javax.transaction.TransactionalException; //导入依赖的package包/类
@Test(expected = TransactionalException.class)
public void should_mandatory_throw_exception() {
    bean.mandatory();
}
 
开发者ID:ftomassetti,项目名称:JavaIncrementalParser,代码行数:5,代码来源:MyTransactionalTxTypeBeanTest.java


注:本文中的javax.transaction.TransactionalException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。