private void cascadeInsertCollectionReferences(ObjectEnvelope source, List descriptor, List alreadyPrepared)
{
// PersistenceBroker pb = getTransaction().getBroker();
for(int i = 0; i < descriptor.size(); i++)
{
CollectionDescriptor col = (CollectionDescriptor) descriptor.get(i);
Object collOrArray = col.getPersistentField().get(source.getObject());
CollectionProxy proxy = ProxyHelper.getCollectionProxy(collOrArray);
/*
on insert we perform only materialized collection objects. This should be
sufficient, because in method #cascadingDependents() we make sure that on
move of unmaterialized collection objects the proxy was materialized if needed.
*/
if(proxy == null && collOrArray != null)
{
Iterator it = BrokerHelper.getCollectionIterator(collOrArray);
while(it.hasNext())
{
Object colObj = it.next();
if(colObj != null)
{
RuntimeObject rt = new RuntimeObject(colObj, getTransaction());
Identity oid = rt.getIdentity();
/*
arminw:
only when the main object need insert we start with FK assignment
of the 1:n and m:n relations. If the main objects need update (was already persisted)
it should be handled by the object state detection in ObjectEnvelope
*/
if(source.needsInsert())
{
/*
arminw:
TODO: what is the valid way to go, when the collection object itself is
a unmaterialized proxy object? Think in this case we should materialize the
object when the main object needs insert, because we have to assign the FK values
to the main object
*/
colObj = ProxyHelper.getRealObject(colObj);
ObjectEnvelope oe = getByIdentity(oid);
if(oe == null)
{
getTransaction().lockAndRegister(rt, Transaction.WRITE, false, getTransaction().getRegistrationList());
oe = getByIdentity(oid);
}
if(col.isMtoNRelation())
{
// the main objects needs insert, thus add new m:n link
addM2NLinkEntry(col, source.getObject(), colObj);
}
else