Here is a patch that fixes bug #3496:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3496
In general ObjectKeys are no longer stored within a Torque OM object
with a value property of null, but are rather converted to null so that
the associated get call always return null for when an object is not
associated or defined. I think this is intuitive behavior as described
in the bug. This is consistent with what the current get property
method expects for how ObjectKey fields will be handled.
I removed code that previously did just the inverse so that when a null
value was passed to the set method a new ObjectKey was created and set
given a value of null. I did not find where this is necessary or
desirable, certainly since it breaks the associated get method.
This will change behavior slightly but I dont think it will affect
current code that calls Torque OM objects. Before the new changes if a
foreign key field is not required, then selecting an object out of the
database that does not have an associated object for the given foreign
key would create an ObjectKey with a null value property. With this
patch this same case simply returns null. But like the bug states
people should be testing this case currently with:
if (getXXX() != null || getXXX().getValue() != null)
Thanks,
Byron
Index: src/templates/om/Object.vm
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/templates/om/Object.vm,v
retrieving revision 1.6
diff -u -U10 -r1.6 Object.vm
--- src/templates/om/Object.vm 2001/09/10 21:14:02 1.6
+++ src/templates/om/Object.vm 2001/10/22 08:10:16
@@ -95,20 +95,36 @@
#set ( $throwsClause = "throws Exception" )
#end
#end
#end
/**
* Set the value of $cfc
*/
public void set${cfc}($cjtype v ) $throwsClause
{
+ #if ( ($cjtype == "NumberKey")
+ || ($cjtype == "StringKey")
+ || ($cjtype == "DateKey") )
+
+ if (v != null && v.getValue() == null)
+ {
+ // If this is an Objectkey than this set method is
+ // probably storing the id of this object or some
+ // associated object. If the objectKey value is null
+ // then we convert the parameter to null so that this
+ // property is consistently null to indicate that no
+ // object is associated or defined.
+ v = null;
+ }
+ #end
+
#if ($complexObjectModel)
#if ($col.isForeignKey())
#set ( $tmp = $col.RelatedTableName )
#set ( $tblFK = $table.Database.getTable($tmp) )
#set ( $colFK = $tblFK.getColumn($col.RelatedColumnName) )
#if ($col.isMultipleFK())
#set ( $varName = $strings.concat(["a", $tblFK.JavaName, "RelatedBy",
$col.JavaName]) )
#elseif ($tmp.equals($table.Name))
#set ( $varName = $strings.concat(["a", $tblFK.JavaName, "RelatedBy",
$col.JavaName]) )
#else
@@ -145,34 +161,21 @@
#if ( ($cjtype == "int") || ($cjtype == "long") || ($cjtype == "boolean")
|| ($cjtype == "short") || ($cjtype == "float") || ($cjtype == "double")
|| ($cjtype == "char") || ($cjtype == "byte") )
if (this.$clo != v)
{
#else
if ( !ObjectUtils.equals(this.$clo, v) )
{
#end
- #if ( ($cjtype == "NumberKey")
- || ($cjtype == "StringKey")
- || ($cjtype == "DateKey") )
- if (this.$clo == null)
- {
- this.$clo = new $cjtype(v);
- }
- else
- {
- this.${clo}.setValue(v);
- }
- #else
this.$clo = v;
- #end
setModified(true);
}
#else
this.$clo = v;
#end
}
##if ($complexObjectModel)
#if ($col.isPrimaryKey() || $col.isForeignKey())
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]