Hi,
Could somenone please test and commit this patch, it's a bug-fix : given
one table with a complex PK, <om>.setPrimaryKey( String ) is broken.
Thanks
Alexis.
I wrote on 2002/08/02 :
> 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 ?)
[../..]
>
> 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]>
>
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]>