/** * Ensure that the backup value holder is populated. */ public void setValue(Object theValue) { // Must force instantiation to be able to compare with the old value. if (!isInstantiated()) { instantiate(); } Object oldValue = getValue(); super.setValue(theValue); updateForeignReferenceSet(theValue, oldValue); }
/** * INTERNAL: * Builder the unit of work value holder. * Ignore the original object. * @param buildDirectlyFromRow indicates that we are building the clone directly * from a row as opposed to building the original from the row, putting it in * the shared cache, and then cloning the original. */ public UnitOfWorkValueHolder createUnitOfWorkValueHolder(ValueHolderInterface attributeValue, Object original, Object clone, AbstractRecord row, UnitOfWorkImpl unitOfWork, boolean buildDirectlyFromRow) { return new UnitOfWorkQueryValueHolder(attributeValue, clone, this, row, unitOfWork); }
/** * Backup the clone attribute value. */ protected Object buildBackupCloneFor(Object cloneAttributeValue) { return getMapping().buildBackupCloneForPartObject(cloneAttributeValue, null, null, getUnitOfWork()); }
/** * Ensure that the backup value holder is populated. */ public void setValue(Object theValue) { // Must force instantiation to be able to compare with the old value. if (!this.isInstantiated) { instantiate(); } Object oldValue = getValue(); super.setValue(theValue); updateForeignReferenceSet(theValue, oldValue); }
if (getMapping() == null) { ForeignReferenceMapping partner = this.getRelationshipPartnerFor(value); if (partner != null) { if (value != null) { Object unwrappedValue = partner.getDescriptor().getObjectBuilder().unwrapObject(value, getSession()); Object oldParent = partner.getRealAttributeValueFromObject(unwrappedValue, getSession()); Object sourceObject = getRelationshipSourceObject(); Object wrappedSource = getMapping().getDescriptor().getObjectBuilder().wrapObject(sourceObject, getSession()); if (partner.getContainerPolicy().contains(sourceObject, oldParent, getSession())) { if (getMapping().isObjectReferenceMapping()) { if (!partner.isCollectionMapping()) { ((ObjectReferenceMapping)getMapping()).setRealAttributeValueInObject(oldParent, null); } else if (getMapping().isCollectionMapping() && (!partner.isManyToManyMapping())) { getMapping().getContainerPolicy().removeFrom(unwrappedValue, getMapping().getRealAttributeValueFromObject(oldParent, getSession()), getSession()); Object unwrappedOldValue = partner.getDescriptor().getObjectBuilder().unwrapObject(oldValue, getSession()); partner.setRealAttributeValueInObject(unwrappedOldValue, null); } else if (partner.isCollectionMapping()) { partner.getContainerPolicy().removeFrom(sourceObject, partner.getRealAttributeValueFromObject(unwrappedOldValue, getSession()), getSession()); partner.setRealAttributeValueInObject(unwrappedValue, wrappedSource); } else if (partner.isCollectionMapping()) { partner.getContainerPolicy().addInto(wrappedSource, oldParent, getSession());
/** * Helper method to retrieve the relationship partner mapping. This will take inheritance * into account and return the mapping associated with correct subclass if necessary. This * is needed for EJB 2.0 inheritance */ private ForeignReferenceMapping getRelationshipPartnerFor(Object partnerObject) { ForeignReferenceMapping partner = (ForeignReferenceMapping)getMapping().getRelationshipPartner(); if ((partner == null) || (partnerObject == null)) { // no partner, nothing to do return partner; } // if the target object is not an instance of the class type associated with the partner // mapping, try and look up the same partner mapping but as part of the partnerObject's // descriptor. Only check if inheritance is involved... if (partner.getDescriptor().hasInheritance()) { ClassDescriptor partnerObjectDescriptor = this.getSession().getDescriptor(partnerObject); if (!(partner.getDescriptor().getJavaClass().isAssignableFrom(partnerObjectDescriptor.getJavaClass()))) { return (ForeignReferenceMapping)partnerObjectDescriptor.getObjectBuilder().getMappingForAttributeName(partner.getAttributeName()); } } return partner; } }
protected void raiseAddChangeEvent(Object element, Integer index, boolean isSet) { if (hasTrackedPropertyChangeListener()) { _persistence_getPropertyChangeListener().propertyChange(new CollectionChangeEvent(this, getTrackedAttributeName(), this, element, CollectionChangeEvent.ADD, index, isSet, true)); } if (isRelationshipMaintenanceRequired()) { ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceSet(element, null); } }
protected void raiseRemoveChangeEvent(Object element, Integer index, boolean isSet) { if (hasTrackedPropertyChangeListener()) { _persistence_getPropertyChangeListener().propertyChange(new CollectionChangeEvent(this, getTrackedAttributeName(), this, element, CollectionChangeEvent.REMOVE, index, isSet, true)); } if (isRelationshipMaintenanceRequired()) { ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceRemove(element); } }
/** * Clone the original attribute value. */ public Object buildCloneFor(Object originalAttributeValue) { Integer refreshCascade = null; if (wrappedValueHolder instanceof QueryBasedValueHolder){ refreshCascade = ((QueryBasedValueHolder)getWrappedValueHolder()).getRefreshCascadePolicy(); } Object clone = this.mapping.buildCloneForPartObject(originalAttributeValue, null, null, this.relationshipSourceObject, getUnitOfWork(), refreshCascade, true, true); // Bug 414801 if (wrappedValueHolder.isInstantiated() && refreshCascade != null) { ((QueryBasedValueHolder)getWrappedValueHolder()).setRefreshCascadePolicy(null); } return clone; }
protected boolean isRelationshipMaintenanceRequired() { if (this.valueHolder instanceof UnitOfWorkQueryValueHolder) { DatabaseMapping mapping = ((UnitOfWorkQueryValueHolder)this.valueHolder).getMapping(); return (mapping != null) && (mapping.getRelationshipPartner() != null); } return false; }
/** * INTERNAL: * Builder the unit of work value holder. * @param buildDirectlyFromRow indicates that we are building the clone directly * from a row as opposed to building the original from the row, putting it in * the shared cache, and then cloning the original. */ public UnitOfWorkValueHolder createUnitOfWorkValueHolder(ValueHolderInterface attributeValue, Object original, Object clone, AbstractRecord row, UnitOfWorkImpl unitOfWork, boolean buildDirectlyFromRow) { UnitOfWorkQueryValueHolder valueHolder = null; if ((row == null) && (isPrimaryKeyMapping())) { // The row must be built if a primary key mapping for remote case. AbstractRecord rowFromTargetObject = extractPrimaryKeyRowForSourceObject(original, unitOfWork); valueHolder = new UnitOfWorkQueryValueHolder(attributeValue, clone, this, rowFromTargetObject, unitOfWork); } else { valueHolder = new UnitOfWorkQueryValueHolder(attributeValue, clone, this, row, unitOfWork); } // In case of joined attributes it so happens that the attributeValue // contains a registered clone, as valueFromRow was called with a // UnitOfWork. So switch the values. // Note that this UOW valueholder starts off as instantiated but that // is fine, for the reality is that it is. if (buildDirectlyFromRow && attributeValue.isInstantiated()) { Object cloneAttributeValue = attributeValue.getValue(); valueHolder.privilegedSetValue(cloneAttributeValue); valueHolder.setInstantiated(); // PERF: Do not modify the original value-holder, it is never used. } return valueHolder; }
} else if (attribute.isAssociation()) { UnitOfWorkQueryValueHolder holder = UnitOfWorkQueryValueHolder.class.cast(value); AbstractRecord record = holder.getRow(); if (record != null) { value = record.get(field); if (otoMapping.getSourceToTargetKeyFields() != null) { DatabaseField fField = otoMapping.getSourceToTargetKeyFields().get(field); Object targetEntity = holder.getValue(); EntityDesc fDesc = EntityDescFactory.getEntityDesc(targetEntity.getClass()); AttributeDesc faDesc = fDesc.getAttributeDesc(fField.getName());
/** * Backup the clone attribute value. */ protected Object buildBackupCloneFor(Object cloneAttributeValue) { return this.mapping.buildBackupCloneForPartObject(cloneAttributeValue, null, null, getUnitOfWork()); }
if (getMapping() == null) { ForeignReferenceMapping partner = this.getRelationshipPartnerFor(value); if (partner != null) { if (value != null) { Object unwrappedValue = partner.getDescriptor().getObjectBuilder().unwrapObject(value, getSession()); Object oldParent = partner.getRealAttributeValueFromObject(unwrappedValue, getSession()); Object sourceObject = getRelationshipSourceObject(); Object wrappedSource = getMapping().getDescriptor().getObjectBuilder().wrapObject(sourceObject, getSession()); if (partner.getContainerPolicy().contains(sourceObject, oldParent, getSession())) { if (getMapping().isObjectReferenceMapping()) { if (!partner.isCollectionMapping()) { ((ObjectReferenceMapping)getMapping()).setRealAttributeValueInObject(oldParent, null); } else if (getMapping().isCollectionMapping() && (!partner.isManyToManyMapping())) { getMapping().getContainerPolicy().removeFrom(unwrappedValue, getMapping().getRealAttributeValueFromObject(oldParent, getSession()), getSession()); Object unwrappedOldValue = partner.getDescriptor().getObjectBuilder().unwrapObject(oldValue, getSession()); partner.setRealAttributeValueInObject(unwrappedOldValue, null); } else if (partner.isCollectionMapping()) { partner.getContainerPolicy().removeFrom(sourceObject, partner.getRealAttributeValueFromObject(unwrappedOldValue, getSession()), getSession()); partner.setRealAttributeValueInObject(unwrappedValue, wrappedSource); } else if (partner.isCollectionMapping()) { partner.getContainerPolicy().addInto(wrappedSource, oldParent, getSession());
/** * Ensure that the backup value holder is populated. */ public void setValue(Object theValue) { // Must force instantiation to be able to compare with the old value. if (!this.isInstantiated) { instantiate(); } Object oldValue = getValue(); super.setValue(theValue); updateForeignReferenceSet(theValue, oldValue); }
/** * Helper method to retrieve the relationship partner mapping. This will take inheritance * into account and return the mapping associated with correct subclass if necessary. This * is needed for EJB 2.0 inheritance */ private ForeignReferenceMapping getRelationshipPartnerFor(Object partnerObject) { ForeignReferenceMapping partner = (ForeignReferenceMapping)getMapping().getRelationshipPartner(); if ((partner == null) || (partnerObject == null)) { // no partner, nothing to do return partner; } // if the target object is not an instance of the class type associated with the partner // mapping, try and look up the same partner mapping but as part of the partnerObject's // descriptor. Only check if inheritance is involved... if (partner.getDescriptor().hasInheritance()) { ClassDescriptor partnerObjectDescriptor = this.getSession().getDescriptor(partnerObject); if (!(partner.getDescriptor().getJavaClass().isAssignableFrom(partnerObjectDescriptor.getJavaClass()))) { return (ForeignReferenceMapping)partnerObjectDescriptor.getObjectBuilder().getMappingForAttributeName(partner.getAttributeName()); } } return partner; } }
/** * Raise the add change event and relationship maintainence. */ protected void raiseAddChangeEvent(Object element) { if (hasTrackedPropertyChangeListener()) { _persistence_getPropertyChangeListener().propertyChange(new CollectionChangeEvent(this, getTrackedAttributeName(), this, element, CollectionChangeEvent.ADD)); } if (hasBeenRegistered()) { ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceSet(element, null); } }
protected void raiseRemoveChangeEvent(Object element, Integer index, boolean isSet) { if (hasTrackedPropertyChangeListener()) { _persistence_getPropertyChangeListener().propertyChange(new CollectionChangeEvent(this, getTrackedAttributeName(), this, element, CollectionChangeEvent.REMOVE, index, isSet)); } if (hasBeenRegistered()) { ((UnitOfWorkQueryValueHolder)getValueHolder()).updateForeignReferenceRemove(element); } }
/** * Clone the original attribute value. */ public Object buildCloneFor(Object originalAttributeValue) { Integer refreshCascade = null; if (wrappedValueHolder instanceof QueryBasedValueHolder){ refreshCascade = ((QueryBasedValueHolder)getWrappedValueHolder()).getRefreshCascadePolicy(); } Object clone = this.mapping.buildCloneForPartObject(originalAttributeValue, null, null, this.relationshipSourceObject, getUnitOfWork(), refreshCascade, true, true); // Bug 414801 if (wrappedValueHolder.isInstantiated() && refreshCascade != null) { ((QueryBasedValueHolder)getWrappedValueHolder()).setRefreshCascadePolicy(null); } return clone; }
protected boolean isRelationshipMaintenanceRequired() { if (this.valueHolder instanceof UnitOfWorkQueryValueHolder) { DatabaseMapping mapping = ((UnitOfWorkQueryValueHolder)this.valueHolder).getMapping(); return (mapping != null) && (mapping.getRelationshipPartner() != null); } return false; }