I was the one who commited the recursive save code that was later 
commented out.  John M. found that it caused infinite looping when a 
Torque OM object's get method was called from within another's OM save 
method, specifically on Scarab.

Our company uses Torque with the FIXME lines commented out and we find 
that the recursive saves through the get and set methods very 
convenient.  However, we don't overide the save(Connection) methods 
which is were the looping problems begin.

There is even a minor looping potential currently with the recursive 
nature of the OM add methods if you manipulate an OM object from within 
the save(Connection) method.

I think an approach like what you have below would work, but the list of 
saved objects would not hash according to the this.hashCode() method, 
but on a hash that uniquely identifies the OM object. For example:

public void save(Connection conn, Savehash savehash)
{
   if (!isNew() && !alreadyInSave && !savehash.contains(this))
   {
     ....

the savehahs.contains method might look something like this:  A derived 
class of Hashtable.

public boolean contains(Persistent pom)
{
    String hash = String.valueOf(pom.getPrimaryKey()) +
                  pom.getClass().getHashCode();
    if (get(hash) != null)
    {
       put(hash, pom);
       return false;
    }

    return true;
}

The above does not fix the case in which new objects to be saved 
recursively construct each other.  However, such a case may be 
considered a coding error.

I can submit a patch if the approach seems plausible.

Byron

Stephen Haberman wrote:
> We've hit a point where it'd be really nice to have the recursive save
> stuff that was commented out with:
> 
> #* FIXME! the following code can cause an infinite loop, needs more
> thought
> shows the infinite loop: System.out.println("Entering save for " +
> this);
>     #if ($pVars.size() != 0)
> 
> Could I re-add this with cycle checking? E.g. something like:
> 
> private save(Connection conn, HashSet alreadySaved)
> {
>   if (!alreadySaved.contains(this))
>   {
>     ...
>    }
> }
> 
> Thanks,
> Stephen



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to