db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John McNally <jmcna...@collab.net>
Subject Modify Transaction.rollback to ignore a null connection [was Re: cvs commit: db-torque/src/java/org/apache/torque/util BasePeer.java]
Date Thu, 31 Jul 2003 17:50:44 GMT
Sorry, you are going to need to point me to the documentation that shows
why null checks are a bad idea or a hack.  Without them the code was
hiding root cause of many errors.

You think modifying Transaction.rollback to ignore a null connection is
a good one.  I don't see how that could be a good thing, at least now an
exception is thrown which will hopefully be at a minimum logged. 
Creating a contract that says rollback(Connection con) will do nothing
and return if con == null, is okay.  but then the calling code is either
going to have to be very sure that con is not null or that the
application does not care if what it was trying to accomplish with
rollback actually happens.

john mcnally  


On Sat, 2003-07-19 at 16:58, Henning P. Schmiedehausen wrote:
> jmcnally@apache.org writes:
> 
> >jmcnally    2003/07/19 11:49:40
> 
> This is a gross hack.
> 
> Make Transaction.rollback(Connection con) accept "null" as connection
> and just return. 
> 
> Not start hacking in lots of tests where you're bound to miss one or
> two and then developers looking at the Torque code start to scratch
> their head and ask themselves "why did he do this on five occasions
> and missed two others"?
> 
> I'm strictly -1 on this change because I've removed lots of such bogus
> code from Turbine.
> 
> 	Regards
> 		Henning
> 
> 
> 
> >  Modified:    src/java/org/apache/torque/util BasePeer.java
> >  Log:
> >  replaced
> >  
> >  catch (TorqueException e)
> >  {
> >      Transaction.rollback(con);
> >      throw e;
> >  }
> >  
> >  with
> >  
> >  catch (TorqueException e)
> >  {
> >      if (con != null)  Transaction.rollback(con);
> >      throw e;
> >  }
> >  
> >  so that an exception which prevents getting a connection does not get
> >  obscured by the attempt to use the connection in rollback.
> >  
> >  Revision  Changes    Path
> >  1.72      +26 -12    db-torque/src/java/org/apache/torque/util/BasePeer.java
> >  
> >  Index: BasePeer.java
> >  ===================================================================
> >  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/BasePeer.java,v
> >  retrieving revision 1.71
> >  retrieving revision 1.72
> >  diff -u -r1.71 -r1.72
> >  --- BasePeer.java	25 Jun 2003 19:31:16 -0000	1.71
> >  +++ BasePeer.java	19 Jul 2003 18:49:40 -0000	1.72
> >  @@ -435,7 +435,10 @@
> >           }
> >           catch (TorqueException e)
> >           {
> >  -            Transaction.rollback(con);
> >  +            if (con != null) 
> >  +            {
> >  +                Transaction.rollback(con);   
> >  +            }
> >               throw new TorqueException(e);
> >           }
> >       }
> >  @@ -625,7 +628,10 @@
> >           }
> >           catch (TorqueException e)
> >           {
> >  -            Transaction.rollback(con);
> >  +            if (con != null) 
> >  +            {
> >  +                Transaction.rollback(con);   
> >  +            }
> >               throw e;
> >           }
> >   
> >  @@ -1352,7 +1358,10 @@
> >           }
> >           catch (Exception e)
> >           {
> >  -            Transaction.rollback(con);
> >  +            if (con != null) 
> >  +            {
> >  +                Transaction.rollback(con);   
> >  +            }
> >               throw new TorqueException(e);
> >           }
> >           return results;
> >  @@ -1743,7 +1752,10 @@
> >           }
> >           catch (TorqueException e)
> >           {
> >  -            Transaction.rollback(con);
> >  +            if (con != null) 
> >  +            {
> >  +                Transaction.rollback(con);   
> >  +            }
> >               throw e;
> >           }
> >       }
> >  @@ -1806,18 +1818,20 @@
> >       public static void doUpdate(Criteria selectCriteria, Criteria updateValues)
> >           throws TorqueException
> >       {
> >  -        Connection db = null;
> >  +        Connection con = null;
> >           try
> >           {
> >  -            db = Transaction.beginOptional(
> >  -                    selectCriteria.getDbName(),
> >  -                    updateValues.isUseTransaction());
> >  -            doUpdate(selectCriteria, updateValues, db);
> >  -            Transaction.commit(db);
> >  +            con = Transaction.beginOptional(selectCriteria.getDbName(),
> >  +                                            updateValues.isUseTransaction());
> >  +            doUpdate(selectCriteria, updateValues, con);
> >  +            Transaction.commit(con);
> >           }
> >           catch (TorqueException e)
> >           {
> >  -            Transaction.rollback(db);
> >  +            if (con != null) 
> >  +            {
> >  +                Transaction.rollback(con);   
> >  +            }
> >               throw e;
> >           }
> >       }
> >  
> >  
> >  
> 
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> >For additional commands, e-mail: torque-dev-help@db.apache.org
> 
> -- 
> Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
> hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/
> 
> Java, perl, Solaris, Linux, xSP Consulting, Web Services 
> freelance consultant -- Jakarta Turbine Development  -- hero for hire
> 
> --- Quote of the week: "It is pointless to tell people anything when
> you know that they won't process the message." --- Jonathan Revusky
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message