On 2000.12.06 17:16:13 +0000 "Diethelm Guallar, Gonzalo" wrote:
> > > You voted +1, Sean voted +0, I'm (of course) +1. This means
> > > we need one extra +1, right? Anybody? Should I write a more
> > > formal proposal for how this would be implemented?

I'll go +1 too :-) I reckon it should be possible to switch off via a
torque.props property, like addSaveMethod, but with the default being on.

> Sean, do you wish to coordinate with me to help you in any way
> I can, or would you rather go solo with it until you have something
> showable?

Well, I didn't really meant to usurp you - just suddenly realised both how
it would be useful to me in my current project and how I would do it... so
I went ahead. Great idea - thanks.

There's a patch below that I believe should do it, if everyone's happy with
it I'll check it in. (I decided on getByName not getFieldByName because I
think 'getXXX' already implies field retrieval). I've also gone for the
same property naming convention as velocity (i.e. init caps).

Note I've also handled every primitive type even though at present
TorqueStringUtils.getJavaName will only return 'int'. The range of types
supported should be bigger though IMO, and this code should never break
whatever types Torque comes to handle.


Index: Object.vm
===================================================================
RCS file: /products/cvs/turbine/turbine/conf/torque/templates/om/Object.vm,v
retrieving revision 1.3
diff -r1.3 Object.vm
141c141,180
< 
---
> ##
> ## getByName code
> ##
> #if ($addGetByNameMethod)
>     /**
>      * Retrieves a field from the object by name passed in
>      * as a String.
>      */
>     public Object getByName(String name)
>     {
>     #foreach ($col in $table.Columns)
>       #set $cfc = $col.JavaName
>       #set $cjtype = $tstrings.getJavaType( $col.Type )
>         if (name.equals("${col.JavaName}"))
>       {
>         #if ($cjtype == "int")
>           return new Integer(get${cfc}());
>         #elseif ($cjtype == "long")
>           return new Long(get${cfc}());
>         #elseif ($cjtype == "float")
>           return new Float(get${cfc}());
>         #elseif ($cjtype == "double")
>           return new Double(get${cfc}());
>         #elseif ($cjtype == "boolean")
>           return new Boolean(get${cfc}());
>         #elseif ($cjtype == "short")
>           return new Short(get${cfc}());
>         #elseif ($cjtype == "byte")
>           return new Byte(get${cfc}());
>         #elseif ($cjtype == "char")
>           return new Character(get${cfc}());
>         #else
>           return get${cfc}();
>         #end
>       }
>     #end
>         return null; 
>     }
> #end
>       


-- 
Sean Legassick
[EMAIL PROTECTED]
      Hombre soy, nada humano me puede ser ajeno  
      
      



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to