/**
* 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 = null;
if (!isNew) {
AttributeChangeListener listener = (AttributeChangeListener)((ChangeTracker)clone)._persistence_getPropertyChangeListener();
if (listener != null){
changes = listener.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);
}
changes.getDeferredSet().clear();
}
} 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()) {
FetchGroup fetchGroup = null;
if(descriptor.hasFetchGroupManager()) {
fetchGroup = descriptor.getFetchGroupManager().getObjectFetchGroup(clone);
}
List mappings = descriptor.getMappings();
int size = mappings.size();
for (int index = 0; index < size; index++) {
DatabaseMapping mapping = (DatabaseMapping)mappings.get(index);
if ((fetchGroup == null) || fetchGroup.containsAttributeInternal(mapping.getAttributeName())) {
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.getId() != null)) {
changes.setOptimisticLockingPolicyAndInitialWriteLockValue(descriptor.getOptimisticLockingPolicy(), session);
}
return changes;
}