--- ../om-orig/Peer.vm       Tue Jul 30 07:31:55 2002
+++ Peer.vm     Mon Jul 29 18:53:53 2002
@@ -328,6 +328,38 @@
     }

     /**
+     * Create a new object of type cls from a resultset row starting
+     * from a specified offset.  This is done so that you can select
+     * other rows than just those needed for this object.  You may
+     * for example want to create two objects from the same row.
+     */
+    public static $table.JavaName row2Object (Value[] values,
+                                              int offset,
+                                              Class cls )
+        throws TorqueException
+    {
+        try
+        {
+            $table.JavaName obj = ($table.JavaName)cls.newInstance();
+            populateObject(values, offset, obj);
+            #if ($addSaveMethod)
+                obj.setModified(false);
+            #end
+            obj.setNew(false);
+
+            return obj;
+        }
+        catch (InstantiationException e)
+        {
+            throw new TorqueException(e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new TorqueException(e);
+        }
+    }
+
+    /**
      * Populates an object from a resultset row starting
      * from a specified offset.  This is done so that you can select
      * other rows than just those needed for this object.  You may
@@ -391,6 +423,70 @@
         }
     }

+    /**
+     * Populates an object from a resultset row starting
+     * from a specified offset.  This is done so that you can select
+     * other rows than just those needed for this object.  You may
+     * for example want to create two objects from the same row.
+     */
+    public static void populateObject(Value[] values,
+                                      int offset,
+                                      $table.JavaName obj)
+        throws TorqueException
+    {
+        try
+        {
+        #set ( $n=0 )
+        #set ( $boolean = "boolean" )
+        #foreach ($col in $table.Columns)
+            #if ($col.isBooleanChar())
+            $boolean b = "Y".equals(values[offset + $n].$col.VillageMethod);
+            #set ( $boolean = "" )
+                #if ($col.isUsePrimitive())
+            obj.set${col.JavaName}(b);
+                #else
+            obj.set${col.JavaName}(b ? Boolean.TRUE : Boolean.FALSE);
+                #end
+            #elseif ($col.isBooleanInt())
+            $boolean b = (values[offset + $n].$col.VillageMethod == 1);
+                #set ( $boolean = "" )
+                #if ($col.isUsePrimitive())
+            obj.set${col.JavaName}(b);
+                #else
+            obj.set${col.JavaName}(b ? Boolean.TRUE : Boolean.FALSE);
+                #end
+            #else
+                #if ($col.isPrimaryKey() || $col.isForeignKey() )
+            ## The field should always be an Object type but make sure so we
+            ## are sure we can set it to null.
+            if (values[offset + $n].$col.VillageMethod instanceof Object)
+            {
+               ## If the database value is a null value then set the Key
+               ## value to null so comparisons with ObjectUtils.equals really work.
+               if (null == values[offset + $n].$col.VillageMethod)
+               {
+                  obj.set${col.JavaName}((${col.JavaNative}) null);
+               }
+               else
+               ## Do what we normally do
+               {
+                  obj.set${col.JavaName}(
+                      new ${col.JavaNative}(values[offset + $n].$col.VillageMethod));
+               }
+            }
+                #else
+            obj.set${col.JavaName}(values[offset + $n].$col.VillageMethod);
+                #end
+            #end
+                #set ( $n = $n + 1 )
+        #end
+        }
+        catch (DataSetException e)
+        {
+            throw new TorqueException(e);
+        }
+    }
+
     /** Method to do selects */
     public static List doSelect(Criteria criteria) throws TorqueException
     {