Synchronize on the connection while we're using it to cooperate with
SimpleRepository + StaticConnectionProvider.
This commit is contained in:
@@ -471,15 +471,20 @@ public class PersistenceContext
|
|||||||
{
|
{
|
||||||
boolean isReadOnlyQuery = (query != null);
|
boolean isReadOnlyQuery = (query != null);
|
||||||
Connection conn = _conprov.getConnection(_ident, isReadOnlyQuery);
|
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 {
|
try {
|
||||||
if (isReadOnlyQuery) {
|
if (isReadOnlyQuery) {
|
||||||
// if this becomes more complex than this single statement, then this should turn
|
// if this becomes more complex than this single statement, then this should
|
||||||
// into a method call that contains the complexity
|
// turn into a method call that contains the complexity
|
||||||
return query.invoke(conn, _liaison);
|
return query.invoke(conn, _liaison);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// if this becomes more complex than this single statement, then this should turn
|
// if this becomes more complex than this single statement, then this should
|
||||||
// into a method call that contains the complexity
|
// turn into a method call that contains the complexity
|
||||||
return modifier.invoke(conn, _liaison);
|
return modifier.invoke(conn, _liaison);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,22 +501,22 @@ public class PersistenceContext
|
|||||||
conn = null;
|
conn = null;
|
||||||
|
|
||||||
if (retryOnTransientFailure && _liaison.isTransientException(sqe)) {
|
if (retryOnTransientFailure && _liaison.isTransientException(sqe)) {
|
||||||
// the MySQL JDBC driver has the annoying habit of including
|
// the MySQL JDBC driver has the annoying habit of including the embedded
|
||||||
// the embedded exception stack trace in the message of their
|
// exception stack trace in the message of their outer exception; if I want a
|
||||||
// outer exception; if I want a fucking stack trace, I'll call
|
// fucking stack trace, I'll call printStackTrace() thanksverymuch
|
||||||
// printStackTrace() thanksverymuch
|
|
||||||
String msg = StringUtil.split(String.valueOf(sqe), "\n")[0];
|
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 {
|
} else {
|
||||||
String msg = isReadOnlyQuery ? "Query failure " + query
|
String msg = isReadOnlyQuery ?
|
||||||
: "Modifier failure " + modifier;
|
"Query failure " + query : "Modifier failure " + modifier;
|
||||||
throw new PersistenceException(msg, sqe);
|
throw new PersistenceException(msg, sqe);
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
_conprov.releaseConnection(_ident, isReadOnlyQuery, conn);
|
_conprov.releaseConnection(_ident, isReadOnlyQuery, conn);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if we got here, we want to retry a transient failure
|
// if we got here, we want to retry a transient failure
|
||||||
return invoke(query, modifier, false);
|
return invoke(query, modifier, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user