* involved. EclipseLink will update the field, in the row, to have the new value for the field
* that this mapping maps to. If the attribute being updated is within an aggregate then pass the updated aggregate
* and the attribute of the aggregate mapping into this method.
*/
public void updateAttributeAddObjectToCollection(String attributeName, Object mapKey, Object value) {
DatabaseMapping mapping = this.query.getDescriptor().getObjectBuilder().getMappingForAttributeName(attributeName);
if (mapping == null) {
throw DescriptorException.mappingForAttributeIsMissing(attributeName, getDescriptor());
}
Object clone = this.getObject();
Object cloneValue = value;
Object original = null;
//only set the original object if we need to update it, ie before the merge takes place
if ((this.eventCode == DescriptorEventManager.PostCloneEvent) || (this.eventCode == DescriptorEventManager.PostMergeEvent)) {
original = this.getOriginalObject();
}
Object originalValue = value;
ObjectChangeSet eventChangeSet = this.getChangeSet();
Object valueForChangeSet = value;
if ((this.query != null) && this.query.isObjectLevelModifyQuery()) {
clone = ((ObjectLevelModifyQuery)this.query).getObject();
eventChangeSet = ((ObjectLevelModifyQuery)this.query).getObjectChangeSet();
}
ClassDescriptor descriptor = getSession().getDescriptor(value.getClass());
if (descriptor != null) {
//There is a descriptor for the value being passed in so we must be carefull
// to convert the value before assigning it.
if (eventChangeSet != null) {
valueForChangeSet = descriptor.getObjectBuilder().createObjectChangeSet(value, (UnitOfWorkChangeSet)eventChangeSet.getUOWChangeSet(), getSession());
}
if (original != null) {
// must be a unitOfWork because only the postMerge, and postClone events set this attribute
originalValue = ((UnitOfWorkImpl)getSession()).getOriginalVersionOfObject(value);
}
}
if (clone != null) {
Object collection = mapping.getRealCollectionAttributeValueFromObject(clone, getSession());
mapping.getContainerPolicy().addInto(mapKey, cloneValue, collection, getSession());
}
if (original != null) {
Object collection = mapping.getRealCollectionAttributeValueFromObject(original, getSession());
mapping.getContainerPolicy().addInto(mapKey, originalValue, collection, getSession());
}
if (getRecord() != null) {
AbstractRecord tempRow = getDescriptor().getObjectBuilder().createRecord(getSession());
// pass in temp Row because most mappings use row.add() not row.put() for
// perf reasons. We are using writeFromObjectIntoRow in order to support
// a large number of types.
mapping.writeFromObjectIntoRow(clone, tempRow, getSession());
((AbstractRecord)getRecord()).mergeFrom(tempRow);
}
if (eventChangeSet != null) {
mapping.simpleAddToCollectionChangeRecord(mapKey, valueForChangeSet, eventChangeSet, getSession());
}
}