in jpa-support/src/main/java/org/apache/aries/jpa/support/impl/ResourceLocalJpaTemplate.java [42:68]
public <R> R txExpr(TransactionType type, EmFunction<R> code) {
EntityManager em = null;
boolean weControlTx = false;
if (type != TransactionType.Required) {
throw new IllegalStateException("Only transation propagation type REQUIRED is supported");
}
Coordination coord = coordinator.begin(this.getClass().getName(), 0);
try {
em = emSupplier.get();
weControlTx = !em.getTransaction().isActive();
if (weControlTx) {
em.getTransaction().begin();
}
R result = (R)code.apply(em);
if (weControlTx) {
em.getTransaction().commit();
}
return result;
} catch (Exception e) {
if (weControlTx) {
safeRollback(em);
}
throw wrapThrowable(e, "Exception occured in transactional code");
} finally {
coord.end();
}
}