Example usage for javax.ejb TransactionRolledbackLocalException TransactionRolledbackLocalException

List of usage examples for javax.ejb TransactionRolledbackLocalException TransactionRolledbackLocalException

Introduction

In this page you can find the example usage for javax.ejb TransactionRolledbackLocalException TransactionRolledbackLocalException.

Prototype

public TransactionRolledbackLocalException() 

Source Link

Document

Constructs a TransactionRolledbackLocalException with no detail message.

Usage

From source file:org.openejb.transaction.TxRequired.java

public InvocationResult invoke(Interceptor interceptor, EjbInvocation ejbInvocation,
        TransactionManager transactionManager) throws Throwable {
    Transaction transaction = transactionManager.getTransaction();
    if (transaction != null) {
        try {/*from  w  w  w .  j  a v a  2 s  .co  m*/
            return interceptor.invoke(ejbInvocation);
        } catch (Throwable t) {
            transactionManager.setRollbackOnly();
            if (ejbInvocation.getType().isLocal()) {
                throw new TransactionRolledbackLocalException().initCause(t);
            } else {
                // can't set an initCause on a TransactionRolledbackException
                throw new TransactionRolledbackException(t.getMessage());
            }
        }
    }

    transactionManager.begin();
    try {
        InvocationResult result = interceptor.invoke(ejbInvocation);
        return result;
    } catch (RollbackException re) {
        throw re;
    } catch (Throwable t) {
        try {
            transactionManager.setRollbackOnly();
        } catch (Exception e) {
            log.warn("Unable to roll back", e);
        }
        throw t;
    } finally {
        if (transactionManager.getStatus() == Status.STATUS_ACTIVE) {
            transactionManager.commit();
        } else {
            transactionManager.rollback();
        }
    }
}