hi edson,

please have a look at the test case MtoNTest#testDeletionFromBothTables (auto-delete ON)
and MtoNTest#testDeletionFromIntermediaryTable (auto-delete OFF).


the first one fails because ojb only deletes from intermediary table. collection is not removal aware.


jakob


Edson Carlos Ericksson Richter wrote:

(this is a real long mail, but I've made a long research. The first part is
the reason I started to research, the second is explain why this occur. The
third is a suggestion of how can we correct).

FIRST PART:
Ok. To avoid the problem related to OJB always using RemovalAwareCollection,
I put my beans to work as

public class A {
 private ArrayList myColl = new ArrayList();

 public void setMyCollection( List collection ) { this.myColl.clear;
this.myColl.addAll( collection ); }
 public List getMyCollection( ) {return this.myColl;}
}

Doing this, I'm converting from RemovalAwareCollection to ArrayList. Fine.

Now suppose that I want auto-delete="true". Then I

getMyCollection().remove(0);

and then persist the object. Theorically, OJB should delete the object from
indirection table AND the referenced table (the N side, ok?). This not
occur. OJB deletes only from indirection table (the auto-delete option makes
no difference).

If I change the code to

public class A {
 private List myColl;

 public void setMyCollection( List collection ) { this.myColl=collection; }
 public List getMyCollection( ) {return this.myColl;}
}

then it works (because the collection passed to setter is
RemovalAwareCollection). BUT, if I put auto-delete="false", then OJB still
delete the indirection table AND the referenced table (again, the
auto-delete option makes no difference).

SECOND PART:
To the facts: since OJB is using RemovalAwareCollection, after the correct
treatment for M:N non-decomposable queries (that my debugging show that it
is working like a charm), the following code is being executed:

               // invoke callback on collection
               if (col instanceof ManageableCollection)
               {
                   ((ManageableCollection) col).afterStore(this);
               }

That is deleting the real objects, even if auto-delete="false".

THIRD PART:
The method deleteMtoNImplementor(...) should reset the
"allObjectsToBeRemoved" in RemovalAwareCollection if the auto-delete option
is set to false. What do you think? Something like create a RemovalAware
interface. Make all classes (RemovalAwareCollection, and RemovalAwareList in
my case) implement it. Then do

public interface RemovalAware {

 public void resetDeleted();
}

The resetDelete method implementation is just

public void resetDeleted( ) {
 allObjectsToBeRemoved.clear();
}


and then change PersistentBrokerImpl to


                   currentMtoNKeys = getMtoNImplementor(cds, obj);
                   // delete unused m:n implementors
                   deleteMtoNImplementor(cds, obj, (Collection)col,
currentMtoNKeys);

                   if( col instanceof ManageableCollection &&
!cds.getCascadeDelete() ) {
                     Collection testCol;
                     if( col instanceof CollectionProxy ) {
                       testCol = ( ( CollectionProxy )col ).getData();
                     } else {
                       testCol = ( Collection )col;
                     }

                     if( testCol instanceof RemovalAware ) {
                       ( ( RemovalAware )testCol ).resetDeleted();
                     }
                   }

This make M:N suff work working. I'm using CVS HEAD.

Thanks for your patience.

Edson Richter




--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.493 / Virus Database: 292 - Release Date: 25/6/2003


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






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



Reply via email to