public Object getOldValue(Object currentCollection, AbstractSession session) { if(currentCollection != null) { if(currentCollection instanceof IndirectCollection) { currentCollection = ((IndirectCollection)currentCollection).getDelegateObject(); } internalRecreateOriginalCollection(currentCollection, session); } return currentCollection; } }
/** * INTERNAL: * Return whether the specified object is instantiated, or if it has changes. */ public boolean objectIsInstantiatedOrChanged(Object object) { return objectIsInstantiated(object) || ((object instanceof IndirectCollection) && ((IndirectCollection)object).hasDeferredChanges()); }
/** * Construct and return an instance of the specified * indirect container class. */ protected IndirectContainer buildIndirectContainer() { IndirectContainer container = null; //3732 if (defaultContainerSize != null) { container = (IndirectContainer)getContainerPolicy().containerInstance(getDefaultContainerSize()); } else { container = (IndirectContainer)getContainerPolicy().containerInstance(); } if (container instanceof IndirectCollection){ if (this.useLazyInstantiation != null){ ((IndirectCollection)container).setUseLazyInstantiation(this.useLazyInstantiation.booleanValue()); } } return container; }
if (cloneAttribute instanceof IndirectCollection) { IndirectCollection collection = (IndirectCollection)cloneAttribute; if (collection.hasDeferredChanges()) { Iterator iterator = collection.getAddedElements().iterator(); boolean cascade = isCascadePersist(); while (iterator.hasNext()) {
/** * Iterate on the indirection object for its mapping. */ public void iterateIndirectContainerForMapping(IndirectContainer container, DatabaseMapping mapping) { setCurrentMapping(mapping); setCurrentDescriptor(null); if (shouldIterateOnIndirectionObjects()) {// false by default internalIterateIndirectContainer(container); } if (shouldIterateOverUninstantiatedIndirectionObjects() || (shouldIterateOverIndirectionObjects() && container.isInstantiated())) { // force instantiation only if specified mapping.iterateOnRealAttributeValue(this, container); } else if (shouldIterateOverIndirectionObjects()) { // PERF: Allow the indirect container to iterate any cached elements. if (container instanceof IndirectCollection) { mapping.iterateOnRealAttributeValue(this, ((IndirectCollection)container).getAddedElements()); } } }
((IndirectCollection)getRealAttributeValueFromObject(clone, uow)).clearDeferredChanges();
@Override public Collection read(Kryo kryo, Input input, Class<Collection> type) { boolean isNotInstantiated = input.readBoolean(); if (!isNotInstantiated) { return super.read(kryo, input, type); } else { IndirectCollection indirectCollection = (IndirectCollection) kryo.newInstance((Class) type); indirectCollection.setValueHolder(new UnfetchedValueHolder()); return (Collection) indirectCollection; } } }
if (cloneAttribute instanceof IndirectCollection) { IndirectCollection collection = (IndirectCollection)cloneAttribute; if (collection.hasDeferredChanges()) { Iterator iterator = collection.getAddedElements().iterator(); boolean cascade = isCascadePersist(); while (iterator.hasNext()) {
/** * Iterate on the indirection object for its mapping. */ public void iterateIndirectContainerForMapping(IndirectContainer container, DatabaseMapping mapping) { setCurrentMapping(mapping); setCurrentDescriptor(null); if (shouldIterateOnIndirectionObjects()) {// false by default internalIterateIndirectContainer(container); } if (shouldIterateOverUninstantiatedIndirectionObjects() || (shouldIterateOverIndirectionObjects() && container.isInstantiated())) { // force instantiation only if specified mapping.iterateOnRealAttributeValue(this, container); } else if (shouldIterateOverIndirectionObjects()) { // PERF: Allow the indirect container to iterate any cached elements. if (container instanceof IndirectCollection) { mapping.iterateOnRealAttributeValue(this, ((IndirectCollection)container).getAddedElements()); } } }
((IndirectCollection)getRealAttributeValueFromObject(clone, uow)).clearDeferredChanges();
public Object getOldValue(Object currentCollection, AbstractSession session) { if(currentCollection != null) { if(currentCollection instanceof IndirectCollection) { currentCollection = ((IndirectCollection)currentCollection).getDelegateObject(); } internalRecreateOriginalCollection(currentCollection, session); } return currentCollection; } }
if (cloneAttribute instanceof IndirectCollection) { IndirectCollection collection = (IndirectCollection)cloneAttribute; if (collection.hasDeferredChanges()) { Iterator iterator = collection.getAddedElements().iterator(); boolean cascade = isCascadePersist(); while (iterator.hasNext()) {
/** * INTERNAL: * Return whether the specified object is instantiated, or if it has changes. */ public boolean objectIsInstantiatedOrChanged(Object object) { return objectIsInstantiated(object) || ((object instanceof IndirectCollection) && ((IndirectCollection)object).hasDeferredChanges()); }
/** * Iterate on the indirection object for its mapping. */ public void iterateIndirectContainerForMapping(IndirectContainer container, DatabaseMapping mapping) { setCurrentMapping(mapping); setCurrentDescriptor(null); if (shouldIterateOnIndirectionObjects()) {// false by default internalIterateIndirectContainer(container); } if (shouldIterateOverUninstantiatedIndirectionObjects() || (shouldIterateOverIndirectionObjects() && container.isInstantiated())) { // force instantiation only if specified mapping.iterateOnRealAttributeValue(this, container); } else if (shouldIterateOverIndirectionObjects()) { // PERF: Allow the indirect container to iterate any cached elements. if (container instanceof IndirectCollection) { mapping.iterateOnRealAttributeValue(this, ((IndirectCollection)container).getAddedElements()); } } }
/** * Construct and return an instance of the specified * indirect container class. */ protected IndirectContainer buildIndirectContainer() { IndirectContainer container = null; //3732 if (defaultContainerSize != null) { container = (IndirectContainer)getContainerPolicy().containerInstance(getDefaultContainerSize()); } else { container = (IndirectContainer)getContainerPolicy().containerInstance(); } if (container instanceof IndirectCollection){ if (this.useLazyInstantiation != null){ ((IndirectCollection)container).setUseLazyInstantiation(this.useLazyInstantiation.booleanValue()); } } return container; }
this.setOriginalCollection(((IndirectCollection)currentCollection).getDelegateObject()); } else { this.setOriginalCollection(currentCollection);
/** * INTERNAL: * Return whether the specified object is instantiated, or if it has changes. */ public boolean objectIsInstantiatedOrChanged(Object object) { return objectIsInstantiated(object) || ((object instanceof IndirectCollection) && ((IndirectCollection)object).hasDeferredChanges()); }
/** * Recreates the original state of the collection. */ public void recreateOriginalCollection(Object currentCollection, AbstractSession session) { if(currentCollection == null) { this.setOriginalCollection(null); return; } if(currentCollection instanceof IndirectCollection) { // to avoid raising event when we add/remove elements from this collection later in this method. setOriginalCollection(((IndirectCollection)currentCollection).getDelegateObject()); } else { setOriginalCollection(currentCollection); } internalRecreateOriginalCollection(this.originalCollection, session); clearChanges(); }
/** * INTERNAL: * Merge changes from the source to the target object. Because this is a * collection mapping, values are added to or removed from the collection * based on the change set. * Synchronize if system property is specified. If not, default to clone the * target collection. No need to synchronize if the collection is new. */ @Override public void mergeChanges(CollectionChangeRecord changeRecord, Object valueOfTarget, boolean shouldMergeCascadeParts, MergeManager mergeManager, AbstractSession targetSession, boolean isSynchronizeOnMerge) { if (isSynchronizeOnMerge && !changeRecord.getOwner().isNew()) { // Ensure the collection is synchronized while changes are being made, // clone also synchronizes on collection (does not have cache key read-lock for indirection). // Must synchronize of the real collection as the clone does so. Object synchronizedValueOfTarget = valueOfTarget; if (valueOfTarget instanceof IndirectCollection) { synchronizedValueOfTarget = ((IndirectCollection)valueOfTarget).getDelegateObject(); } synchronized(synchronizedValueOfTarget) { mergeChanges(changeRecord, valueOfTarget, shouldMergeCascadeParts, mergeManager, targetSession); } } else { mergeChanges(changeRecord, valueOfTarget, shouldMergeCascadeParts, mergeManager, targetSession); } }
/** * INTERNAL: * Merge changes from the source to the target object. Because this is a * collection mapping, values are added to or removed from the collection * based on the change set. * Synchronize if system property is specified. If not, default to clone the * target collection. No need to synchronize if the collection is new. */ public void mergeChanges(CollectionChangeRecord changeRecord, Object valueOfTarget, boolean shouldMergeCascadeParts, MergeManager mergeManager, AbstractSession targetSession, boolean isSynchronizeOnMerge) { if (isSynchronizeOnMerge && !changeRecord.getOwner().isNew()) { // Ensure the collection is synchronized while changes are being made, // clone also synchronizes on collection (does not have cache key read-lock for indirection). // Must synchronize of the real collection as the clone does so. Object synchronizedValueOfTarget = valueOfTarget; if (valueOfTarget instanceof IndirectCollection) { synchronizedValueOfTarget = ((IndirectCollection)valueOfTarget).getDelegateObject(); } synchronized (synchronizedValueOfTarget) { mergeChanges(changeRecord, valueOfTarget, shouldMergeCascadeParts, mergeManager, targetSession); } } else { // Using cloned target object passed instead of synchronization. mergeChanges(changeRecord, valueOfTarget, shouldMergeCascadeParts, mergeManager, targetSession); } }