Hi all,

Here is a little patch for a bug found in Object.vm, the generated 
method setPrimaryKey( String key ) has a bug if your Table has a 
multiple PK, it won't parse a string representation of a ComboKey even 
one acquired by om.getPrimaryKey().toString(), the code always throws an 
ArrayIndexOfBoundException..
The generated code could only work if your string representation of a 
ComboKey ends with a ':', the reason for this is because the code breaks 
the String between ':' and doesn't consider the end-of-line as a 
delimiter.. (btw, why not using a StringTokenizer here ?)

I guess I'm the first person who ever consider using this method.. so I 
may be in the wrong direction :
I'm developing a webapp using Torque (and Struts), everywhere in the 
code I need to pass PKs in URLs, so I need something to translate 
ObjectKey instances to String and vice versa, the first one is easy, the 
toString() method works well (I just doubt that the ComboKey.toString() 
consider escaping the ':' character but.. well..), but I didn't found 
anything for the String -> ComboKey transformation.

I first tried the constructor from ComboKey, but  new ComboKey( String ) 
has a killer-bug (at least in the torque-3.0-b1 I'm using) : it falls 
into infinite loop !, and I realized this wasn't the solution as I need 
to get a ComboKey for a particular table : for example a String 
representation of <myTable> :  'A320:10:15' coud be a ComboKey composed 
of {StringKey, NumberKey, NumberKey} but it could also be a {StringKey, 
StringKey, StringKey} the only classes to be aware of this are <myTable> 
or <myTable>Peer,
So I decided to use  Persistent.setPrimaryKey( String ) and 
Persistent.getPrimaryKey() -> ObjectKey for the translation, and hit 
another bug..
Do you guys have another solution ?
Or am I the only one dealing with multiple PK (my database-designer 
loves them ;) )

regards,
Alexis.
Index: Object.vm
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/om/Object.vm,v
retrieving revision 1.45
diff -u -r1.45 Object.vm
--- Object.vm   1 Aug 2002 16:51:38 -0000       1.45
+++ Object.vm   2 Aug 2002 06:14:43 -0000
@@ -1164,11 +1164,17 @@
         int prevPos = 0;
 
      #set ($int = "int ")
+     #set ($i = 1)
      #foreach ($col in $table.PrimaryKeys)
-        ${int}colonPos = key.indexOf(':', prevPos);
-        set${col.JavaName}(new ${col.JavaNative}(key.substring(prevPos, colonPos)));
-        prevPos = colonPos + 1;
+        #if ( $i < $table.PrimaryKeys.size() )
+          ${int}colonPos = key.indexOf(':', prevPos);
+          set${col.JavaName}( new ${col.JavaNative}(key.substring(prevPos, colonPos)) 
+);
+          prevPos = colonPos + 1;
+        #else
+          set${col.JavaName}( new ${col.JavaNative}(key.substring(prevPos)) );
+        #end
         #set ($int = "")
+        #set ($i = $i +1)
      #end
     }
 


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

Reply via email to