private void storeAndLinkOneToMany(boolean linkOnly, Object obj, CollectionDescriptor cod,
                                       Object referencedObjects, boolean insert)
    {
        if(referencedObjects == null)
        {
            return;
        }
        /*
        Only make sense to perform (link or/and store) real referenced objects
        or materialized collection proxy objects, because on unmaterialized collection
        nothing has changed.

        - if the collection is a collectionproxy and it's not already loaded
        no need to perform an update on the referenced objects
        - on insert we link and insert the referenced objects, because the proxy
        collection maybe "inherited" from the object before the PK was replaced
        */
        if(insert || !(referencedObjects instanceof CollectionProxyDefaultImpl
                        && !((CollectionProxyDefaultImpl) referencedObjects).isLoaded()))
        {
            Iterator it = BrokerHelper.getCollectionIterator(referencedObjects);
            Object refObj;
            while(it.hasNext())
            {
                refObj = it.next();
                /*
                TODO: Check this!
                arminw:
                When it's necessary to 'link' (set the FK) the 1:n reference objects?
                1. set FK in refObj if it is materialized
                2. if the referenced object is a proxy AND the main object needs insert
                we have to materialize the real object, because the user may move a collection
                of proxy objects from object A to new object B. In this case we have to replace the
                FK in the proxy object with new key of object B.
                */
                if(insert || getProxyFactory().isMaterialized(refObj))
                {
                    ClassDescriptor refCld = getClassDescriptor(getProxyFactory().getRealClass(refObj));
                    // get the real object before linking
                    refObj = getProxyFactory().getRealObject(refObj);
                    link(refObj, refCld, cod, obj, insert);
                    // if enabled cascade store and not only link, store the refObj
                    if(!linkOnly && cod.getCascadingStore() == ObjectReferenceDescriptor.CASCADE_OBJECT)
                    {
                        store(refObj);
                    }
                }
            }
        }
    }
private void storeAndLinkOneToMany ( boolean linkOnly , Object obj , CollectionDescriptor cod , Object referencedObjects , boolean insert ) { if ( referencedObjects == null ) { return ; } if ( insert || ! ( referencedObjects instanceof CollectionProxyDefaultImpl && ! ( ( CollectionProxyDefaultImpl ) referencedObjects ) . isLoaded ( ) ) ) { Iterator it = BrokerHelper . getCollectionIterator ( referencedObjects ) ; Object refObj ; while ( it . hasNext ( ) ) { refObj = it . next ( ) ; if ( insert || getProxyFactory ( ) . isMaterialized ( refObj ) ) { ClassDescriptor refCld = getClassDescriptor ( getProxyFactory ( ) . getRealClass ( refObj ) ) ; refObj = getProxyFactory ( ) . getRealObject ( refObj ) ; link ( refObj , refCld , cod , obj , insert ) ; if ( ! linkOnly && cod . getCascadingStore ( ) == ObjectReferenceDescriptor . CASCADE_OBJECT ) { store ( refObj ) ; } } } } }
Store/Link 1:n collection references.

@param obj real object the reference starts
@param linkOnly if true the referenced objects will only be linked (FK set, no reference store).
Reference store setting in descriptor will be ignored in this case
@param cod {@link CollectionDescriptor} of the real object
@param referencedObjects the referenced objects ({@link ManageableCollection} or Collection or Array) or null
@param insert flag for insert operation