From daf7fa3c1149eb81148f4b953b0081b2311a42b9 Mon Sep 17 00:00:00 2001 From: mdb Date: Fri, 18 Jan 2002 18:35:46 +0000 Subject: [PATCH] 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 --- .../com/samskivert/jdbc/SimpleRepository.java | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java b/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java index b94078d3..c9c5033b 100644 --- a/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java +++ b/projects/samskivert/src/java/com/samskivert/jdbc/SimpleRepository.java @@ -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 // Copyright (C) 2001 Michael Bayne @@ -81,29 +81,16 @@ public class SimpleRepository extends Repository Connection conn = null; DatabaseMetaData dmd = null; DatabaseLiaison liaison = null; + Object rv = null; - // obtain our database connection and associated goodies try { + // obtain our database connection and associated goodies conn = _provider.getConnection(_dbident); conn.setAutoCommit(false); dmd = conn.getMetaData(); liaison = LiaisonRegistry.getLiaison(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 rv = op.invoke(conn, liaison); @@ -116,20 +103,23 @@ public class SimpleRepository extends Repository return rv; } catch (SQLException sqe) { - // back out our changes if something got hosed - try { - if (dmd.supportsTransactions()) { - conn.rollback(); + if (conn != null) { + // back out our changes if something got hosed + try { + 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 - _provider.connectionFailed(_dbident, conn, sqe); - // clear out the reference so that we don't release it later - conn = null; + // let the connection provider know that the connection failed + _provider.connectionFailed(_dbident, conn, sqe); + + // 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 // retry such failures, try one more time @@ -140,7 +130,7 @@ public class SimpleRepository extends Repository return execute(op, false); } - String err = "Operation invocation failed."; + String err = "Operation invocation failed"; throw new PersistenceException(err, sqe); } catch (PersistenceException pe) {