It turned out to be much easier to patch Torque.  I have been using a
patched version of Torque for about a week with no problems.  I can't
get the current CVS of Torque to build, hopefully someone else can run
it through Torque's tests.

This patch adds a new property to build.properties:
retrieveByPKReturnsNull.  Setting it to true modifies the behavior of
the retrieveByPK method so that they return null for a key that does
not exist, instead of throwing an exception.

-james



On Mon, 2002-05-20 at 14:34, James A. Hillyerd wrote:
> I originally posted this to the user list (by accident), so I am
> reposting here:
> 
> I'm finally getting to the point in my project where I am using Torque. 
> Pretty cool since my code base has been essentially broken for months.
> My employer really loves me. =)
> 
> One assumption I had (mistakenly) made was that calling retrieveByPK
> with a key that doesn't exist would return null, not throw an exception:
> "Failed to select one and only one row."
> 
> I have a few options:
> 
> 1. Code custom retrieveByXXX methods for each of my Objects, that either
> duplicate the code in the PK method, or call it and catch the exception.
> (I don't like either, duplicating code is bad, and so is unnecessary
> exceptions)
> 
> 2. Modify places where I use the PK method to catch the exception. (More
> unnecessary exceptions)
> 
> 3. Modify Torque to return null (or so that it is an option in
> build.properties).
> 
> 
> I think that each of the above options would take a similar amount of
> effort to implement.  Can anyone give me reasons for or against
> modifying Torque?  The only thing I could think of is if Torque uses the
> retrieveByPK methods internally and depends on them never returning
> null.
> 
> Someone on the user list mentioned using Managers instead.  Is there
> somewhere I can read up on Managers?  I thought they were still
> experimental.
> 
> Thanks.
> 
> -james
> 
> -- 
> []  James A. Hillyerd <[EMAIL PROTECTED]> - Java Software Engineer
> []  PGP 1024D/D31BC40D F87B 7906 C0DA 32E8 B8F6 DE23 FBF6 4712 D31B C40D
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 
> 
-- 
[]  James A. Hillyerd <[EMAIL PROTECTED]> - Java Software Engineer
[]  PGP 1024D/D31BC40D F87B 7906 C0DA 32E8 B8F6 DE23 FBF6 4712 D31B C40D
Index: src/conf/build.properties
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/conf/build.properties,v
retrieving revision 1.14
diff -u -r1.14 build.properties
--- src/conf/build.properties	10 May 2002 00:42:52 -0000	1.14
+++ src/conf/build.properties	31 May 2002 19:13:53 -0000
@@ -71,6 +71,10 @@
 # overloadKeySetters=false prevents overloading of the setter method for
 # primary/foreign keys.  This is useful when working with broken
 # JavaBean implementations.
+#
+# retrieveByPKReturnsNull=true modifies the behavior of the
+# retrieveByPK method so that they return null for a key that does
+# not exist, instead of throwing an exception.
 # -------------------------------------------------------------------
 
 targetPackage=org.apache.torque
@@ -82,6 +86,7 @@
 addIntakeRetrievable=false
 useManagers=false
 overloadKeySetters=true
+retrieveByPKReturnsNull=false
 
 # -------------------------------------------------------------------
 #
Index: src/templates/om/Peer.vm
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/om/Peer.vm,v
retrieving revision 1.30
diff -u -r1.30 Peer.vm
--- src/templates/om/Peer.vm	28 May 2002 01:00:16 -0000	1.30
+++ src/templates/om/Peer.vm	31 May 2002 19:14:03 -0000
@@ -864,6 +864,12 @@
     #end
   #end
         List v = doSelect(criteria, con);
+  #if ($retrieveByPKReturnsNull)
+        if (v.size() == 0)
+        {
+            return null;
+        }
+  #end
         if (v.size() != 1)
         {
             throw new TorqueException("Failed to select one and only one row.");

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

Reply via email to