You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Thoralf Rickert <th...@cadooz.de> on 2006/05/24 15:12:34 UTC
Copying Torque Object
Hi!
I've a small problem with the copy() and copyInto() methods in the
generated Torque objects. I've tables with dependencies from other
tables (for example a table "login" which has a foreign key to a table
"address"). I want to use the BaseAddress.copy() method to copy the
address object and save it. If I use this method, it also loads and
copies internally all logins which are linked to the source address to
the new address. So, it makes a deep copy. Is it possible, to override
this behaviour outside the Base* class without creating a totally new
copy() method? I don't think so...
I've noticed this some time a go and wrote my own copy() method in the
extended Address class like this:
public Address copy(boolean deepcopy) throws Exception {
if (deepcopy)
return super.copy();
else {
Address newAddress = new Address();
newAddress.setFirstname(firstname);
....
return newAddress;
}
}
But after a little while I've added a new column to the address table
and forgot to update the new copy() method too. So I didn't copy all
data, if I use copy(false) - which takes some time to find and fix. I
can't make a deep copy because there could be many thousands of referer
rows to an address. I just want to copy the address data.
So, the best way would be, that this copy(boolean) method should be
added during BaseAddress generation in that class. I think, it's not
very complicated to add this "feature". Here is my proposal:
1. add in Object.vm a new boolean parameter to copy() like this
public $table.JavaName copy(boolean deepcopy) throws TorqueException
{
return copyInto(new ${table.JavaName}(),deepcopy);
}
2. create two new downwards compatible methods copy() and copyInto()
public $table.JavaName copy() throws TorqueException
{
return copy(true);
}
protected $table.JavaName copyInto($table.JavaName copyObj) throws
TorqueException
{
return copyInto(copyObject, true);
}
3. add a new parameter deepcopy to the old copyInto() method and check
that variable before making the
deepcopy. I think, it's not necessary to submit that value recursivly
to the referers.
protected $table.JavaName copyInto($table.JavaName copyObj, boolean)
throws TorqueException
{
....
#if ($complexObjectModel)
if (deepcopy) {
#foreach ($fk in $table.Referrers)
...
#end
}
#end
}
Is that possible or did I forgot something important?
bye
Thoralf
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org