At 05:46 PM 6/24/2002, you wrote:

>That said torque does not require this "best practice" to be followed.
>And a distinction between 0 and more than 1 values would be good.  If
>someone submits a patch that creates a new method and deprecates the old
>I will submit it.

Here's a patch that deprecates the byPK versions and creates a new 
getByPrimaryKey.  I also changed the byPK version to just call the new one 
and throw the exception if it returns null.

James
Index: Peer.vm
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/om/Peer.vm,v
retrieving revision 1.32
diff -r1.32 Peer.vm
838a839
>     #set ($newretrieveMethod = "get${table.JavaName}ByPrimaryKey")
840a842
>     #set ($newretrieveMethod = "getByPrimaryKey")
846a849
>      * @deprecated - use getByPrimaryKey()
872a876
>      * @deprecated - use getByPrimaryKey()
877a882,928
>         $table.JavaName retVal = null;
>         retVal = ${newretrieveMethod}(pk, db);
>         if (retVal == null)
>         {
>             throw new TorqueException("Failed to select one and only one row.");
>         }
>         else
>         {
>             return retVal;
>         }
>     }
> 
>     /**
>      * Retrieve a single object by pk, or null if not found
>      *
>      * @param pk the primary key
>      */
>     public static $table.JavaName ${newretrieveMethod}( ObjectKey pk )
>         throws TorqueException
>     {
>         Connection db = null;
>         $table.JavaName retVal = null;
>         try
>         {
>             db = Torque.getConnection(DATABASE_NAME);
>             retVal = ${newretrieveMethod}(pk, db);
>         }
>         finally
>         {
>             if (db != null)
>             {
>                 closeConnection(db);
>             }
>         }
>         return(retVal);
>     }
> 
>     /**
>      * Retrieve a single object by pk, or null if not found
>      *
>      * @param pk the primary key
>      * @param con the connection to use
>      */
>     public static $table.JavaName ${newretrieveMethod}(ObjectKey pk, Connection con)
>         throws TorqueException
>     {
> 
892a944
>           if (v.size() == 0) return null;

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

Reply via email to