/**
* INTERNAL:
* Create ObjectChangeSet
*/
public ObjectChangeSet createObjectChangeSet(Object clone, Object backUp, org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet changeSet, boolean isNew, AbstractSession session, ClassDescriptor descriptor) {
ObjectChangeSet changes;
if (!isNew) {
changes = ((AttributeChangeListener)((ChangeTracker)clone)._persistence_getPropertyChangeListener()).getObjectChangeSet();
// The changes can be null if forceUpdate is used in CMP, so an empty change must be created.
if (changes != null) {
// PERF: Only merge the change set if merging into a new uow change set.
// merge the changeSet locally (ie the UOW's copy not the tracking policies copy) ; the local changeset will be returned.
if (changes.getUOWChangeSet() != changeSet) {
changes = changeSet.mergeObjectChanges(changes, (org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet)changes.getUOWChangeSet());
}
// check for deferred changes
if (changes.hasDeferredAttributes()){
//need to calculate the changes for these attributes.
for (Iterator iterator = changes.getDeferredSet().iterator(); iterator.hasNext();){
DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName((String)iterator.next());
mapping.calculateDeferredChanges((ChangeRecord)changes.getChangesForAttributeNamed(mapping.getAttributeName()), session);
}
}
if(descriptor.hasMappingsPostCalculateChanges()) {
int size = descriptor.getMappingsPostCalculateChanges().size();
for(int i=0; i < size; i++) {
DatabaseMapping mapping = descriptor.getMappingsPostCalculateChanges().get(i);
org.eclipse.persistence.sessions.changesets.ChangeRecord record = changes.getChangesForAttributeNamed(mapping.getAttributeName());
if(record != null) {
// don't call postCalculateChanges if calculateDeferredChanges has been already called:
// the latter calls the former (required by DeferredChangePolicy).
if(!changes.hasDeferredAttributes() || !changes.getDeferredSet().contains(mapping.getAttributeName())) {
mapping.postCalculateChanges(record, session);
}
}
}
}
} else {
changes = descriptor.getObjectBuilder().createObjectChangeSet(clone, changeSet, isNew, session);
}
} else {
changes = descriptor.getObjectBuilder().createObjectChangeSet(clone, changeSet, isNew, true, session);
// PERF: Do not create change records for new objects.
if (descriptor.shouldUseFullChangeSetsForNewObjects() || descriptor.isAggregateDescriptor()) {
List mappings = descriptor.getMappings();
int size = mappings.size();
for (int index = 0; index < size; index++) {
DatabaseMapping mapping = (DatabaseMapping)mappings.get(index);
changes.addChange(mapping.compareForChange(clone, null, changes, session));
}
}
}
// The following code deals with reads that force changes to the flag associated with optimistic locking.
if ((descriptor.usesOptimisticLocking()) && (changes.getPrimaryKeys() != null)) {
changes.setOptimisticLockingPolicyAndInitialWriteLockValue(descriptor.getOptimisticLockingPolicy(), session);
}
return changes;
}