javax.ejb.EJBTransactionRequiredException Java Examples

The following examples show how to use javax.ejb.EJBTransactionRequiredException. 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: ServiceProvisioningPartnerServiceLocalBeanContainerIT.java    From development with Apache License 2.0 5 votes vote down vote up
@Test(expected = EJBTransactionRequiredException.class)
public void getTemplateProducts_NoTransaction() {
    // given
    // when
    localService.getTemplateProducts();
    // then EJBTransactionRequiredException happens
}
 
Example #2
Source File: ServiceProvisioningPartnerServiceLocalBeanContainerIT.java    From development with Apache License 2.0 5 votes vote down vote up
@Test(expected = EJBTransactionRequiredException.class)
public void getProductsForVendor_NoTransaction() {
    // given
    // when
    localService.getProductsForVendor();
    // then EJBTransactionRequiredException happens
}
 
Example #3
Source File: TransactionAttributesTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void assertAttribute(final String attribute, final Method method) throws Exception {
    final MethodTransactionInfo info = (MethodTransactionInfo) attributes.get(method);
    assertEquals(method.toString(), attribute, info.transAttribute);

    try {
        final Object[] args = new Object[method.getParameterTypes().length];
        final Object result = method.invoke(bean, args);
        assertEquals(attribute, result);
    } catch (final InvocationTargetException e) {
        assertEquals(attribute, "Mandatory");
        assertTrue(e.getTargetException() instanceof EJBTransactionRequiredException);
    }
}
 
Example #4
Source File: TransactionInvocationHandlersTest.java    From development with Apache License 2.0 4 votes vote down vote up
@Test(expected = EJBTransactionRequiredException.class)
public void testMANDATORY_NoTx() throws Exception {
    TransactionInvocationHandlers.TX_MANDATORY.call(
            callableReturns(new Object()), ctxStub);
}
 
Example #5
Source File: TransactionInvocationHandlers.java    From development with Apache License 2.0 4 votes vote down vote up
public Object call(Callable<Object> callable, IInvocationCtx ctx)
        throws Exception {
    throw new EJBTransactionRequiredException(
            "Transaction required (MANDATORY).");
}
 
Example #6
Source File: MarketplaceServiceLocalBeanQueryIT.java    From development with Apache License 2.0 4 votes vote down vote up
@Test(expected = EJBTransactionRequiredException.class)
public void getAllMarketplace_TransactionMandatory() {
    marketplaceLocalService.getAllMarketplaces();
}
 
Example #7
Source File: TransactionInvocationHandlersTest.java    From development with Apache License 2.0 4 votes vote down vote up
@Test(expected = EJBTransactionRequiredException.class)
public void testMANDATORY_NoTx() throws Exception {
    TransactionInvocationHandlers.TX_MANDATORY.call(
            callableReturns(new Object()), ctxStub);
}
 
Example #8
Source File: TransactionExerciseTest.java    From training with MIT License 4 votes vote down vote up
@Test(expected = EJBTransactionRequiredException.class)
public void testPersistWithNoTx() {
	employeeDAO.persist(new Employee());
}
 
Example #9
Source File: BaseEjbProxyHandler.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * Renamed method so it shows up with a much more understandable purpose as it
 * will be the top element in the stacktrace
 *
 * @param e        Throwable
 * @param method   Method
 * @param interfce Class
 */
protected Throwable convertException(Throwable e, final Method method, final Class interfce) {
    final boolean rmiRemote = Remote.class.isAssignableFrom(interfce);
    if (e instanceof TransactionRequiredException) {
        if (!rmiRemote && interfaceType.isBusiness()) {
            return new EJBTransactionRequiredException(e.getMessage()).initCause(getCause(e));
        } else if (interfaceType.isLocal()) {
            return new TransactionRequiredLocalException(e.getMessage()).initCause(getCause(e));
        } else {
            return e;
        }
    }
    if (e instanceof TransactionRolledbackException) {
        if (!rmiRemote && interfaceType.isBusiness()) {
            return new EJBTransactionRolledbackException(e.getMessage()).initCause(getCause(e));
        } else if (interfaceType.isLocal()) {
            return new TransactionRolledbackLocalException(e.getMessage()).initCause(getCause(e));
        } else {
            return e;
        }
    }
    if (e instanceof NoSuchObjectException) {
        if (!rmiRemote && interfaceType.isBusiness()) {
            return new NoSuchEJBException(e.getMessage()).initCause(getCause(e));
        } else if (interfaceType.isLocal()) {
            return new NoSuchObjectLocalException(e.getMessage()).initCause(getCause(e));
        } else {
            return e;
        }
    }
    if (e instanceof AccessException) {
        if (!rmiRemote && interfaceType.isBusiness()) {
            return new AccessLocalException(e.getMessage()).initCause(getCause(e));
        } else if (interfaceType.isLocal()) {
            return new AccessLocalException(e.getMessage()).initCause(getCause(e));
        } else {
            return e;
        }
    }
    if (e instanceof RemoteException) {
        if (!rmiRemote && interfaceType.isBusiness()) {
            return new EJBException(e.getMessage()).initCause(getCause(e));
        } else if (interfaceType.isLocal()) {
            return new EJBException(e.getMessage()).initCause(getCause(e));
        } else {
            return e;
        }
    }

    for (final Class<?> type : method.getExceptionTypes()) {
        if (type.isAssignableFrom(e.getClass())) {
            return e;
        }
    }

    // Exception is undeclared
    // Try and find a runtime exception in there
    while (e.getCause() != null && !(e instanceof RuntimeException)) {
        e = e.getCause();
    }
    return e;
}