You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by "Janssen, Roger" <Ro...@ibanx.nl> on 2003/05/15 16:41:18 UTC

RE: [BUG 1.0.rc3 / PB API] storing object removes all related ite ms i n indirection table

A possible patch is given below.
I'm not completely sure whether the later call to overloaded method
deleteMtoNImplementor
in this same method should also be patched?

replace the method ;
    private void storeCollections(Object obj, Vector vecCds) throws
PersistenceBrokerException

by code below (the altered code is marked by 'iBanx patch');

    private void storeCollections(Object obj, Vector vecCds) throws
PersistenceBrokerException
    {
        // get all members of obj that are collections and store all their
elements
        Iterator i = vecCds.iterator();
        while (i.hasNext())
        {
            CollectionDescriptor cds = (CollectionDescriptor) i.next();
            Object col = cds.getPersistentField().get(obj);
            Collection currentMtoNKeys = null;

            if (col == null)
            {
                if (cds.isMtoNRelation())
                {
                	// iBanx patch
                	if (cds.getCascadeStore())
                	{
                    	// delete all rows from m:n table belonging to obj
                    	deleteMtoNImplementor(cds, obj);
                    }
                    //// delete all rows from m:n table belonging to obj
					//deleteMtoNImplementor(cds, obj);
					// end iBanx patch
                }
            }
            else
            {
                // MBAIRD
                // if the collection is a collectionproxy and it's not
already loaded
                // no need to store it.
                if (col instanceof CollectionProxy && !((CollectionProxy)
col).isLoaded())
                {
                    continue;
                }
                if (cds.isMtoNRelation())
                {
                    currentMtoNKeys = getMtoNImplementor(cds, obj);
                    // delete unused m:n implementors
                    deleteMtoNImplementor(cds, obj, (Collection)col,
currentMtoNKeys);
                }
                Iterator colIterator;
                if (col instanceof ManageableCollection)
                {
                    colIterator = ((ManageableCollection)
col).ojbIterator();
                }
                else if (col instanceof Collection)
                {
                    colIterator = ((Collection) col).iterator();
                }
                else if (col.getClass().isArray())
                {
                    colIterator = new ArrayIterator(col);
                }
                else
                {
                    throw new OJBRuntimeException(
                            col.getClass()
                            + " can not be managed by OJB, use Array,
Collection or ManageableCollection instead !");
                }
                while (colIterator.hasNext())
                {
                    Object otherObj = colIterator.next();
                    // for m:n mapped collections store association
implementing entries
                    if (cds.isMtoNRelation())
                    {
                        // 1. Store depended upon object first to avoid FK
violation
                        storeCollectionObject(cds, otherObj);
                        // 2. Store indirection record
                        storeMtoNImplementor(cds, obj, otherObj,
currentMtoNKeys);
                    }
                    // for 1:n mapped collection assert proper fk assignment
                    else
                    {
                        assertFkAssignment(otherObj, obj, cds);
                        storeCollectionObject(cds, otherObj);
                    }
                }
                // invoke callback on collection
                if (col instanceof ManageableCollection)
                {
                    ((ManageableCollection) col).afterStore(this);
                }
            }
        }
    }

Roger Janssen
iBanx


*************************************************************************
The information contained in this communication is confidential and is
intended solely for the use of the individual or entity to  whom it is
addressed.You should not copy, disclose or distribute this communication 
without the authority of iBanx bv. iBanx bv is neither liable for 
the proper and complete transmission of the information has been maintained
nor that the communication is free of viruses, interceptions or interference.

If you are not the intended recipient of this communication please return
the communication to the sender and delete and destroy all copies.