public R txExpr()

in jpa-support/src/main/java/org/apache/aries/jpa/support/impl/XAJpaTemplate.java [50:75]


    public <R> R txExpr(TransactionType type, EmFunction<R> code) {
        EntityManager em = null;
        TransactionToken tranToken = null;
        TransactionAttribute ta = TransactionAttribute.fromType(type);
        Coordination coord = null;
        try {
            tranToken = ta.begin(tm);
            coord = coordinator.begin(this.getClass().getName(), 0);
            em = emSupplier.get();
            if (tm.getStatus() != Status.STATUS_NO_TRANSACTION) {
                em.joinTransaction();
            }
            R result = (R)code.apply(em);
            safeFinish(tranToken, ta, coord);
            return result;
        } catch (RollbackException ex) {
            safeRollback(tranToken, ta, coord, ex);
            throw wrapThrowable(ex, "RollbackException is propagating");  
        } catch (Exception ex) {
            safeRollback(tranToken, ta, coord, ex);
            throw wrapThrowable(ex, "Exception occured in transactional code");
        } catch (Error ex) { // NOSONAR
            safeRollback(tranToken, ta, coord, ex);
            throw ex;
        }
    }