Thomas Fischer wrote:

Hi,

Does anyone object to push out RC2 in the next few days ? The other option is doing it in three weeks as afterwards, I am on vacation for two weeks.

I just noticed that I forgot to attach my patches regarding the silent db hit issue in ObjectWithManager.vm. Here they are. I leave it to you to decide if you want them in RC2 or not.

Bye, Thomas.

Index: db/torque/templates/trunk/src/templates/om/BaseManager.vm
===================================================================
--- db/torque/templates/trunk/src/templates/om/BaseManager.vm   (revision 
279555)
+++ db/torque/templates/trunk/src/templates/om/BaseManager.vm   (working copy)
@@ -13,6 +13,7 @@
 ## limitations under the License.
 #*
  * author <a href="mailto:[EMAIL PROTECTED]">John McNally</a>
+ * author <a href="mailto:[EMAIL PROTECTED]">Thomas Vandahl</a>
  * version $Id$
  *#
 #set ($interfaceName = $table.JavaName)
@@ -63,10 +64,10 @@
     extends AbstractBaseManager
 {
     /** The name of the manager */
-    protected static String MANAGED_CLASS = "${package}.${interfaceName}";
+    protected final static String MANAGED_CLASS = 
"${package}.${interfaceName}";
 
     /** The name of our class to pass to Torque as the default manager. */
-    protected static String DEFAULT_MANAGER_CLASS
+    protected final static String DEFAULT_MANAGER_CLASS
         = "${package}.${interfaceName}Manager";
 
     /**
@@ -108,6 +109,21 @@
     }
 
     /**
+     * Static accessor for the @see #getCachedInstanceImpl(ObjectKey).
+     * Loads <code>${interfaceName}</code> from cache, returns 
+     * <code>null</code>, if instance is not in cache
+     *
+     * @param id an <code>ObjectKey</code> value
+     * @return a <code>${interfaceName}</code> value
+     * @exception TorqueException if an error occurs
+     */
+    public static ${interfaceName} getCachedInstance(ObjectKey id)
+        throws TorqueException
+    {
+        return getManager().getCachedInstanceImpl(id);
+    }
+
+    /**
      * Static accessor for the @see #getInstanceImpl(ObjectKey, boolean).
      *
      * @param id an <code>ObjectKey</code> value
@@ -239,7 +255,6 @@
         return obj;
     }
 
-
     /**
      * Get a ${interfaceName} with the given id.
      *
@@ -252,6 +267,18 @@
     }
 
     /**
+     * Get a ${interfaceName} with the given id from the cache. Returns 
+     * <code>null</code> if instance is not in cache
+     *
+     * @param id <code>ObjectKey</code> value
+     */
+    protected ${interfaceName} getCachedInstanceImpl(ObjectKey id)
+        throws TorqueException
+    {
+        return (${interfaceName}) cacheGet(id);
+    }
+
+    /**
      * Get a ${interfaceName} with the given id.
      *
      * @param id <code>ObjectKey</code> value
Index: db/torque/templates/trunk/src/templates/om/Peer.vm
===================================================================
--- db/torque/templates/trunk/src/templates/om/Peer.vm  (revision 279555)
+++ db/torque/templates/trunk/src/templates/om/Peer.vm  (working copy)
@@ -594,7 +594,7 @@
         throws TorqueException
     {
         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
-               correctBooleans(criteria);
+        correctBooleans(criteria);
 
   #foreach ($col in $table.Columns)
     #set ( $cup=$col.Name.toUpperCase() )
@@ -832,10 +832,14 @@
     #set ( $cjtype = $col.JavaNative )
     #if ($col.isPrimaryKey() && !$table.IdMethod.equals("none"))
         if (!obj.isNew())
+        {
     #end
     #if ( $cjtype != "byte[]" )
             criteria.add($cup, obj.${col.GetterName}());
     #end
+    #if ($col.isPrimaryKey() && !$table.IdMethod.equals("none"))
+        }
+    #end
   #end
         return criteria;
     }
@@ -906,7 +910,7 @@
         {
             Torque.closeConnection(db);
         }
-        return(retVal);
+        return retVal;
     }
 
     /**
@@ -959,7 +963,7 @@
         {
             Torque.closeConnection(db);
         }
-        return(retVal);
+        return retVal;
     }
 
     /**
@@ -1048,7 +1052,7 @@
         {
             Torque.closeConnection(db);
         }
-        return(retVal);
+        return retVal;
     }
 
   #set ( $comma = false )
@@ -1079,13 +1083,13 @@
         criteria.add($cup, $clo);
   #end
         List v = doSelect(criteria, con);
-        if (v.size() != 1)
+        if (v.size() == 1)
         {
-            throw new TorqueException("Failed to select one and only one 
row.");
+            return ($table.JavaName) v.get(0);
         }
         else
         {
-            return ($table.JavaName) v.get(0);
+            throw new TorqueException("Failed to select one and only one 
row.");
         }
     }
 #end
@@ -1151,8 +1155,8 @@
     protected static List doSelectJoin${joinColumnId}(Criteria criteria)
         throws TorqueException
     {
-               return doSelectJoin${joinColumnId}(criteria, null);
-       }
+        return doSelectJoin${joinColumnId}(criteria, null);
+    }
 
     /**
      * selects a collection of $className objects pre-filled with their
@@ -1185,11 +1189,15 @@
 
         correctBooleans(criteria);
 
-               List rows;
-               if( conn == null )
-               rows = BasePeer.doSelect(criteria);
-           else
-               rows = BasePeer.doSelect(criteria,conn);
+        List rows;
+        if (conn == null)
+        {
+            rows = BasePeer.doSelect(criteria);
+        }
+        else
+        {
+            rows = BasePeer.doSelect(criteria,conn);
+        }
 
         List results = new ArrayList();
 
@@ -1295,7 +1303,7 @@
     protected static List doSelectJoinAllExcept${excludeString}(Criteria 
criteria)
         throws TorqueException
     {
-       return doSelectJoinAllExcept${excludeString}(criteria, null);
+        return doSelectJoinAllExcept${excludeString}(criteria, null);
     }
 
     /**
@@ -1335,10 +1343,14 @@
         correctBooleans(criteria);
 
         List rows;
-        if( conn == null )
-               rows = BasePeer.doSelect(criteria);
-           else
-               rows = BasePeer.doSelect(criteria,conn);
+        if (conn == null)
+        {
+            rows = BasePeer.doSelect(criteria);
+        }
+        else
+        {
+            rows = BasePeer.doSelect(criteria,conn);
+        }
 
         List results = new ArrayList();
 
Index: db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm
===================================================================
--- db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm     
(revision 279555)
+++ db/torque/templates/trunk/src/templates/om/ObjectWithManager.vm     
(working copy)
@@ -364,9 +364,9 @@
         {
         #if ($argsize > 1)
             SimpleKey[] keys = { $arglist };
-            return ${interfaceName}Manager.getInstance(new ComboKey(keys));
+            $varName = ${interfaceName}Manager.getInstance(new ComboKey(keys));
         #else
-            return ${interfaceName}Manager.getInstance($arglist);
+            $varName = ${interfaceName}Manager.getInstance($arglist);
         #end
         }
       #end
@@ -374,6 +374,51 @@
     }
 
     /**
+     * Return the associated $interfaceName object
+     * If it was not retrieved before, the object is retrieved from
+     * the database using the passed connection
+     *
+     * @param connection the connection used to retrieve the associated object
+     *        from the database, if it was not retrieved before
+     * @return the associated $interfaceName object
+     * @throws TorqueException
+     */
+    public $interfaceName get${pVarName}(Connection connection)
+        throws TorqueException
+    {
+        if ($varName == null && ($conditional))
+        {
+        #if ($argsize > 1)
+            SimpleKey[] keys = { $arglist };
+            ComboKey comboid = new ComboKey(keys);
+
+            $varName = ${interfaceName}Manager.getCachedInstance(comboid);
+            if ($varName == null)
+            {
+          #if ($tblFK.isAlias())
+                $varName = ${className}Peer.retrieve${className}ByPK(comboid, 
connection);
+          #else
+                $varName = ${className}Peer.retrieveByPK(comboid, connection);
+          #end
+                ${interfaceName}Manager.putInstance($varName);
+            }
+        #else
+            $varName = ${interfaceName}Manager.getCachedInstance($arglist);
+            if ($varName == null)
+            {
+          #if ($tblFK.isAlias())
+                $varName = ${className}Peer.retrieve${className}ByPK($arglist, 
connection);
+          #else
+                $varName = ${className}Peer.retrieveByPK($arglist, connection);
+          #end
+                ${interfaceName}Manager.putInstance($varName);
+            }
+        #end
+        }
+        return $varName;
+    }
+    
+    /**
      * Provides convenient way to set a relationship based on a
      * ObjectKey, for example
      * <code>bar.setFooKey(foo.getPrimaryKey())</code>

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

Reply via email to