You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Nick Pomfret <ni...@pixelpark.com> on 2001/11/27 21:04:34 UTC

possible bug in torque generated code

The copy() method in the torque generated in the object model doesn't seem
to work as I would expect.

When using the copy() method on an object it correctly copies that object
but not those objects dependent upon it.  Looking at the automatically
generated code it would appear that copying dependent objects is what is
supposed to happen (see torque-generated code below for the class 'Foo',
which contains other objects 'Bar') - am I correct?

public Foo copy() throws Exception
{
  Foo copyObj = new Foo();
  copyObj.setFooId(foo_id);

  v = copyObj.getBars();
  for (int i=0; i<v.size(); i++)
  {
    ((Persistent)v.get(i)).setNew(true);
  }

  copyObj.setFooId((NumberKey)null);
  return copyObj;
}

The copyObj is created at the start of this method and so never has any
'Bars', why then call 'getBars()' as the result will always be an empty
vector?

Assuming I've not got the wrong end of the stick completely, would the
following be an adequate solution?

public Foo copy() throws Exception
{
  Foo copyObj = new Foo();
  copyObj.setFooId(foo_id);

  v = getBars();
  for (int i=0; i<v.size(); i++)
  {
    Bar obj = (Bar) v.get(i);
    copyObj.addBar(obj.copy());
    ((Persistent)v.get(i)).setNew(true);
  }

  copyObj.setFooId((NumberKey)null);
  return copyObj;
}

If so, Object.vm (in torque) would need to be modified so that the code
which generates the changes described is:

  ${list}v = get${pCollName}();
  for (int i=0; i<v.size(); i++)
  {
    $className obj = ($className) v.get(i);
    copyObj.add$className(obj.copy())
    ((Persistent)v.get(i)).setNew(true);
  }

I'm new to this stuff so forgive me if I've miss understood!


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>