gonzalo     01/08/16 15:56:05

  Modified:    src/java/org/apache/torque/util BasePeer.java
  Log:
  Added a couple of finally blocks protecting calls to releaseConnection(),
  to ensure those calls are ALWAYS issued.
  Also fixed some code blocks without {}.
  
  Revision  Changes    Path
  1.5       +30 -16    
jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java
  
  Index: BasePeer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BasePeer.java     2001/08/10 20:49:34     1.4
  +++ BasePeer.java     2001/08/16 22:56:04     1.5
  @@ -110,7 +110,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Frank Y. Kim</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>John D. McNally</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Brett McLaughlin</a>
  - * @version $Id: BasePeer.java,v 1.4 2001/08/10 20:49:34 dlr Exp $
  + * @version $Id: BasePeer.java,v 1.5 2001/08/16 22:56:04 gonzalo Exp $
    */
   public abstract class BasePeer
   {
  @@ -350,14 +350,19 @@
       public static void commitTransaction(DBConnection dbCon)
           throws Exception
       {
  -        if ( dbCon.getConnection().getMetaData().supportsTransactions() )
  +        try
           {
  -            dbCon.commit();
  -            dbCon.setAutoCommit(true);
  +            if ( dbCon.getConnection().getMetaData().supportsTransactions() )
  +            {
  +                dbCon.commit();
  +                dbCon.setAutoCommit(true);
  +            }
           }
  -
  -        // Release the connection to the pool.
  -        Torque.releaseConnection( dbCon );
  +        finally
  +        {
  +            // Release the connection to the pool.
  +            Torque.releaseConnection( dbCon );
  +        }
       }
   
       /**
  @@ -372,19 +377,24 @@
       public static void rollBackTransaction(DBConnection dbCon)
           throws Exception
       {
  -        if ( dbCon.getConnection().getMetaData().supportsTransactions() )
  +        try
           {
  -            dbCon.rollback();
  -            dbCon.setAutoCommit(true);
  +            if ( dbCon.getConnection().getMetaData().supportsTransactions() )
  +            {
  +                dbCon.rollback();
  +                dbCon.setAutoCommit(true);
  +            }
  +            else
  +            {
  +                category.error("An attempt was made to rollback a transaction but 
the"
  +                               + " database did not allow the operation to be 
rolled back.");
  +            }
           }
  -        else
  +        finally
           {
  -            category.error("An attempt was made to rollback a transaction but the"
  -                + " database did not allow the operation to be rolled back.");
  +            // Release the connection to the pool.
  +            Torque.releaseConnection( dbCon );
           }
  -
  -        // Release the connection to the pool.
  -        Torque.releaseConnection( dbCon );
       }
   
   
  @@ -1639,9 +1649,13 @@
           finally
           {
               if (doTransaction)
  +            {
                   commitTransaction(db);
  +            }
               else
  +            {
                   Torque.releaseConnection(db);
  +            }
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to