Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public Object invoke(MethodInvocation methodInvocation) throws Throwable {
try {
result = methodInvocation.proceed();

if (txn.isActive()) {
commitOrRollback(txn);
}
return result;
} catch (Exception e) {
// commit transaction only if rollback didnt occur
if (rollbackIfNecessary(transactional, e, txn)) {
Expand All @@ -74,33 +78,20 @@ public Object invoke(MethodInvocation methodInvocation) throws Throwable {
// propagate whatever exception is thrown anyway
throw e;
} finally {
// Close the em if necessary (guarded so this code doesn't run unless catch fired).
if (null != didWeStartWork.get() && !txn.isActive()) {
didWeStartWork.remove();
unitOfWork.end();
}
}

// everything was normal so commit the txn (do not move into try block above as it
// interferes with the advised method's throwing semantics)
try {
if (txn.isActive()) {
if (txn.getRollbackOnly()) {
txn.rollback();
} else {
txn.commit();
}
}
} finally {
// close the em if necessary
// Close the em if necessary
if (null != didWeStartWork.get()) {
didWeStartWork.remove();
unitOfWork.end();
}
}
}

// or return result
return result;
private void commitOrRollback(EntityTransaction txn) {
if (txn.getRollbackOnly()) {
txn.rollback();
} else {
txn.commit();
}
}

// TODO(user): Cache this method's results.
Expand Down