use of com.jfinal.plugin.activerecord.NestedTransactionHelpException in project jfinal by jfinal.
the class Tx method intercept.
public void intercept(Invocation inv) {
Config config = getConfigWithTxConfig(inv);
if (config == null)
config = DbKit.getConfig();
Connection conn = config.getThreadLocalConnection();
if (conn != null) {
// Nested transaction support
try {
if (conn.getTransactionIsolation() < getTransactionLevel(config))
conn.setTransactionIsolation(getTransactionLevel(config));
inv.invoke();
return;
} catch (SQLException e) {
throw new ActiveRecordException(e);
}
}
Boolean autoCommit = null;
try {
conn = config.getConnection();
autoCommit = conn.getAutoCommit();
config.setThreadLocalConnection(conn);
// conn.setTransactionIsolation(transactionLevel);
conn.setTransactionIsolation(getTransactionLevel(config));
conn.setAutoCommit(false);
inv.invoke();
conn.commit();
} catch (NestedTransactionHelpException e) {
if (conn != null)
try {
conn.rollback();
} catch (Exception e1) {
LogKit.error(e1.getMessage(), e1);
}
LogKit.logNothing(e);
} catch (Throwable t) {
if (conn != null)
try {
conn.rollback();
} catch (Exception e1) {
LogKit.error(e1.getMessage(), e1);
}
throw t instanceof RuntimeException ? (RuntimeException) t : new ActiveRecordException(t);
} finally {
try {
if (conn != null) {
if (autoCommit != null)
conn.setAutoCommit(autoCommit);
conn.close();
}
} catch (Throwable t) {
// can not throw exception here, otherwise the more important exception in previous catch block can not be thrown
LogKit.error(t.getMessage(), t);
} finally {
// prevent memory leak
config.removeThreadLocalConnection();
}
}
}
Aggregations