Restructure execute() so that if the obtain-connection phase fails, it too
is retried in the cases where the exception is transient. git-svn-id: https://samskivert.googlecode.com/svn/trunk@534 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SimpleRepository.java,v 1.4 2001/11/10 04:42:24 mdb Exp $
|
// $Id: SimpleRepository.java,v 1.5 2002/01/18 18:35:46 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -81,29 +81,16 @@ public class SimpleRepository extends Repository
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
DatabaseMetaData dmd = null;
|
DatabaseMetaData dmd = null;
|
||||||
DatabaseLiaison liaison = null;
|
DatabaseLiaison liaison = null;
|
||||||
|
Object rv = null;
|
||||||
|
|
||||||
// obtain our database connection and associated goodies
|
|
||||||
try {
|
try {
|
||||||
|
// obtain our database connection and associated goodies
|
||||||
conn = _provider.getConnection(_dbident);
|
conn = _provider.getConnection(_dbident);
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
dmd = conn.getMetaData();
|
dmd = conn.getMetaData();
|
||||||
liaison = LiaisonRegistry.getLiaison(conn);
|
liaison = LiaisonRegistry.getLiaison(conn);
|
||||||
gotConnection(conn);
|
gotConnection(conn);
|
||||||
|
|
||||||
} catch (SQLException sqe) {
|
|
||||||
String err = "Unable to obtain connection.";
|
|
||||||
// if the connection was created, let the provider know that
|
|
||||||
// it choked
|
|
||||||
if (conn != null) {
|
|
||||||
_provider.connectionFailed(_dbident, conn, sqe);
|
|
||||||
}
|
|
||||||
// and then do a little choking ourselves
|
|
||||||
throw new PersistenceException(err, sqe);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object rv = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// invoke the operation
|
// invoke the operation
|
||||||
rv = op.invoke(conn, liaison);
|
rv = op.invoke(conn, liaison);
|
||||||
|
|
||||||
@@ -116,20 +103,23 @@ public class SimpleRepository extends Repository
|
|||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
} catch (SQLException sqe) {
|
} catch (SQLException sqe) {
|
||||||
// back out our changes if something got hosed
|
if (conn != null) {
|
||||||
try {
|
// back out our changes if something got hosed
|
||||||
if (dmd.supportsTransactions()) {
|
try {
|
||||||
conn.rollback();
|
if (dmd.supportsTransactions()) {
|
||||||
|
conn.rollback();
|
||||||
|
}
|
||||||
|
} catch (SQLException rbe) {
|
||||||
|
Log.warning("Unable to roll back operation.");
|
||||||
|
Log.logStackTrace(rbe);
|
||||||
}
|
}
|
||||||
} catch (SQLException rbe) {
|
|
||||||
Log.warning("Unable to roll back operation.");
|
|
||||||
Log.logStackTrace(rbe);
|
|
||||||
}
|
|
||||||
|
|
||||||
// let the connection provider know that the connection failed
|
// let the connection provider know that the connection failed
|
||||||
_provider.connectionFailed(_dbident, conn, sqe);
|
_provider.connectionFailed(_dbident, conn, sqe);
|
||||||
// clear out the reference so that we don't release it later
|
|
||||||
conn = null;
|
// clear out the reference so that we don't release it later
|
||||||
|
conn = null;
|
||||||
|
}
|
||||||
|
|
||||||
// if this is a transient failure and we've been requested to
|
// if this is a transient failure and we've been requested to
|
||||||
// retry such failures, try one more time
|
// retry such failures, try one more time
|
||||||
@@ -140,7 +130,7 @@ public class SimpleRepository extends Repository
|
|||||||
return execute(op, false);
|
return execute(op, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
String err = "Operation invocation failed.";
|
String err = "Operation invocation failed";
|
||||||
throw new PersistenceException(err, sqe);
|
throw new PersistenceException(err, sqe);
|
||||||
|
|
||||||
} catch (PersistenceException pe) {
|
} catch (PersistenceException pe) {
|
||||||
|
|||||||
Reference in New Issue
Block a user