You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Byron Foster <bf...@base2.cc> on 2001/12/04 09:52:41 UTC

[PATCH] Torque save on set

Here is a patch that addresses a few issues, but they are all related. 
This fixes the FIXME problem in the Object.vm file that caused scarab to
recursively loop.  The problem was fixed by adding boolean flags to
objects that are associated by a foreign key.  With this patch, only
setting the object will flag it to be saved, and not getting it.
Example:
class 'A' contains a foreign key reference to class 'B' such that A
contains the methods setB and getB.  Calling setB with an object of type
B will flag Torque to save the object the next time A is saved, but this
will not be true for an Object of type B aquired from A.getB. 

The error occurred before because getB would also save the object
aquirred when A was saved.  When this operation was performed within a
save, infinite looping followed.

I think this makes intuitive since based on the fact that when calling a
set method a user is indicating a change in the object and a
relationship between the objects.  Certainly in practice we have found
this functionality very useful. 
  
In this patch the alreadyInSave flag has been replaced with a
transaction key.  A transaction key uniquely identifies a transaction. 
The use of the transaction key serves the purpose of alreadyInSave, but
it will also keep the save method from being called more than once
during a given transaction. This becomes an issue with the new set
method feature.

Also in this patch is the initSave method which serves the purpose of
the preSave.  It has some nice properties over overidding the save
method. First, it is guaranteed to be called once per object per save
transaction. Also, it is safe to call other save(DBConnection)  methods
without the risk of infinite looping. 

This patch contain the new class org.apache.torque.pool.TransactionKey

This patch has been tested with scarab.

Log Message:

Fixed infinite looping problem caused by saving associated om objects
linked by foreign key to an om object that is being saved.  Now, only
associated objects linked by passing them to the set method of the root
object are saved.  TransactionKey added to prevent the save operation
from occurring more than one time on an OM object for a given
transaction. 

Thanks Much,
Byron