As I didn't receive any response in regards to creation of a 
setByPeerName function, I've gone and created it anyway.

Here are the results of the diffs required to implement this wonderous 
creation!

The extra code for NumberKey setting allows the user to pass in a 
variety of numeric data types to set NumberKeys.  

We've been using this for 2 weeks now without any noticable problems. 
 The caveat is that we use objects for all data types rather than a 
mixture of objects and primitives.

Feedback is appreciated

Regards,

Ben

cvs diff Object.vm (in directory 
D:\Data\maven\jakarta-turbine-torque\src\templates\om\)
Index: Object.vm
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/templates/om/Object.vm,v
retrieving revision 1.38
diff -r1.38 Object.vm
830a831,872
 >    
 >     /**
 >      * Sets a field on the object by name passed in
 >      * as a String.  The String must be one of the static
 >      * Strings defined in this Class' Peer.
 >      * The object value must be one that will be accepted by the 
appropriate
 >      * set<field> method
 >      */
 >     public void setByPeerName(String name, Object value) throws 
TorqueException
 >     {
 >     #foreach ($col in $table.Columns)
 >       #set ( $cfc = $col.JavaName )
 >       #set ( $cup=$col.Name.toUpperCase() )
 >       #set ( $cjtype = $col.JavaNative )
 >         if (name.equals(${table.JavaName}Peer.$cup ))
 >         {
 >       #if ($cjtype == "int")
 >         set${cfc}(((Number) value).intValue());
 >       #elseif ($cjtype == "long")
 >         set${cfc}(((Number) value).intValue());
 >       #elseif ($cjtype == "float")
 >         set${cfc}(((Float) value).floatValue());
 >       #elseif ($cjtype == "double")
 >         set${cfc}(((Double) value).doubleValue());
 >       #elseif ($cjtype == "boolean")
 >         set${cfc}(((Boolean) value).booleanValue());
 >       #elseif ($cjtype == "short")
 >         set${cfc}(((Short) value).shortValue());
 >       #elseif ($cjtype == "byte")
 >         set${cfc}(((Byte) value).byteValue());
 >       #elseif ($cjtype == "char")
 >         set${cfc}(((Char) value).charValue());
 >       #elseif ($cjtype == "NumberKey")
 >         set${cfc}(convertToNumberKey(value));
 >       #else
 >         set${cfc}(($cjtype)value);
 >       #end
 >     }
 >     #end
 >        
 >     }
 >



cvs diff BaseObject.java (in directory 
D:\Data\maven\jakarta-turbine-torque\src\java\org\apache\torque\om\)
Index: BaseObject.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/om/BaseObject.java,v
retrieving revision 1.13
diff -r1.13 BaseObject.java
59a60,63
 >
 > import org.apache.torque.TorqueException;
 > import org.apache.torque.util.BasePeer;
 >
348a353,362
 >     /**
 >      * Sets a field on the object by name passed in
 >      * as a String.  Must be overridden if called.
 >      * BaseObject's implementation will throw an Error.
 >      */
 >     public void setByPeerName(String name, Object value) throws 
TorqueException
 >     {
 >         throw new Error("BaseObject.setByPeerName: " + NOT_IMPLEMENTED);
 >     }
 >
460a475,495
 >
 >     /**
 >      * Converts a variety of Number types to a NumberKey
 >      * @return an object of type NumberKey
 >      * @throws TorqueException when the input cannot be converted to 
NumberKey
 >      */
 >     public static NumberKey convertToNumberKey(Object value) throws 
TorqueException {
 >         if (value == null) {
 >             return null;
 >         }
 >
 >         if (value instanceof NumberKey)    {
 >             return (NumberKey) value;
 >         }
 >
 >         if (value instanceof Number) {
 >             return new NumberKey(((Number) value).intValue());
 >         }
 >
 >         throw new TorqueException("Cannot convert " + 
value.getClass().getName() + " to a NumberKey");
 >     }



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

Reply via email to