Synchronize on the connection while we're using it to cooperate with

SimpleRepository + StaticConnectionProvider.
This commit is contained in:
Michael Bayne
2007-07-30 20:10:47 +00:00
parent b9d14f57c7
commit 92c54a5325
@@ -471,15 +471,20 @@ public class PersistenceContext
{
boolean isReadOnlyQuery = (query != null);
Connection conn = _conprov.getConnection(_ident, isReadOnlyQuery);
// TEMP: we synchronize on the connection to cooperate with SimpleRepository when used in
// conjunction with a StaticConnectionProvider; at some point we'll switch to standard JDBC
// connection pooling which will block in getConnection() instead of returning a connection
// that someone else may be using
synchronized (conn) {
try {
if (isReadOnlyQuery) {
// if this becomes more complex than this single statement, then this should turn
// into a method call that contains the complexity
// if this becomes more complex than this single statement, then this should
// turn into a method call that contains the complexity
return query.invoke(conn, _liaison);
} else {
// if this becomes more complex than this single statement, then this should turn
// into a method call that contains the complexity
// if this becomes more complex than this single statement, then this should
// turn into a method call that contains the complexity
return modifier.invoke(conn, _liaison);
}
@@ -496,22 +501,22 @@ public class PersistenceContext
conn = null;
if (retryOnTransientFailure && _liaison.isTransientException(sqe)) {
// the MySQL JDBC driver has the annoying habit of including
// the embedded exception stack trace in the message of their
// outer exception; if I want a fucking stack trace, I'll call
// printStackTrace() thanksverymuch
// the MySQL JDBC driver has the annoying habit of including the embedded
// exception stack trace in the message of their outer exception; if I want a
// fucking stack trace, I'll call printStackTrace() thanksverymuch
String msg = StringUtil.split(String.valueOf(sqe), "\n")[0];
log.info("Transient failure executing operation, retrying [error=" + msg + "].");
log.info("Transient failure executing op, retrying [error=" + msg + "].");
} else {
String msg = isReadOnlyQuery ? "Query failure " + query
: "Modifier failure " + modifier;
String msg = isReadOnlyQuery ?
"Query failure " + query : "Modifier failure " + modifier;
throw new PersistenceException(msg, sqe);
}
} finally {
_conprov.releaseConnection(_ident, isReadOnlyQuery, conn);
}
}
// if we got here, we want to retry a transient failure
return invoke(query, modifier, false);