Skip to content

Instantly share code, notes, and snippets.

/gist:2499458
Created Apr 26, 2012

Embed
What would you like to do?
Resume/suspend
/**
* Transaction Manager implementation
*/
private TransactionManager tm;
@Override
public V call() throws Exception {
// Start a transaction that locks. We then suspend the transaction to
// allow for the main transaction to complete.
Transaction tx = null;
try {
tm.begin();
this.lock(this.key);
tx = tm.suspend();
return doTx();
}
finally {
if (tx != null) {
tm.resume(tx);
int status = -1;
try {
status = tm.getStatus();
} catch (Exception e) {
}
if (status == Status.STATUS_ACTIVE) {
tm.commit();
} else {
tm.rollback();
}
}
}
}
/**
* Wraps the work implementation around a transaction.
*
* @return
* @throws Exception
*/
protected V doTx() throws Exception {
try {
tm.begin();
return performWork();
} catch (Exception e) {
tm.setRollbackOnly();
throw e;
}
finally {
int status = -1;
try {
status = tm.getStatus();
} catch (Exception e) {
}
if (status == Status.STATUS_ACTIVE) {
tm.commit();
} else {
tm.rollback();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.