getSession().getCommitManager().markPreModifyCommitInProgress(writeQuery.getObjectChangeSet());
if (writeQuery.getObjectChangeSet().hasChanges()) {
// PERF: Avoid events if no listeners.
if (getDescriptor().getEventManager().hasAnyEventListeners()) {
DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.PreUpdateWithChangesEvent, writeQuery);
getDescriptor().getEventManager().executeEvent(event);
// PreUpdateWithChangesEvent listeners may have altered the object - should recalculate the change set.
UnitOfWorkChangeSet uowChangeSet = (oracle.toplink.essentials.internal.sessions.UnitOfWorkChangeSet)((UnitOfWorkImpl)writeQuery.getSession()).getUnitOfWorkChangeSet();
// writeQuery.getObjectChangeSet() is mapped to object in uowChangeSet.
// It is first cleared then re-populated by calculateChanges method.
writeQuery.getObjectChangeSet().clear();
if(writeQuery.getDescriptor().getObjectChangePolicy().calculateChanges(object, ((UnitOfWorkImpl)event.getSession()).getBackupClone(object), uowChangeSet, writeQuery.getSession(), writeQuery.getDescriptor(), false) == null) {
// calculateChanges returns null in case the changeSet doesn't have changes.
// It should be removed from the list of ObjectChangeSets that have changes in uowChangeSet.
uowChangeSet.getAllChangeSets().remove(writeQuery.getObjectChangeSet());
}
}
}
// Verify if deep shallow modify is turned on
if (writeQuery.shouldCascadeParts()) {
queryManager.preUpdate(writeQuery);
}
// The row must not be built until after preUpdate in case the object reference has changed.
// For a user defined update in the uow to row must be built twice to check if any update is required.
writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRowForUpdateWithChangeSet(writeQuery));
Boolean shouldModifyVersionField = writeQuery.getObjectChangeSet().shouldModifyVersionField();
if (!getModifyRow().isEmpty() || (shouldModifyVersionField != null) || writeQuery.getObjectChangeSet().hasCmpPolicyForcedUpdate()) {
// If user defined the entire row is required. Must not be built until change is known.
if (writeQuery.isUserDefined() || writeQuery.isCallQuery()) {
writeQuery.setModifyRow(getDescriptor().getObjectBuilder().buildRow(object, getSession()));
}
// Update the write lock field if required
if (getDescriptor().usesOptimisticLocking()) {
OptimisticLockingPolicy policy = getDescriptor().getOptimisticLockingPolicy();
policy.addLockValuesToTranslationRow(writeQuery);
if (!getModifyRow().isEmpty() || (shouldModifyVersionField.booleanValue() && policy instanceof VersionLockingPolicy)) {
// update the row with newer lock value
policy.updateRowAndObjectForUpdate(writeQuery, object);
} else if (!shouldModifyVersionField.booleanValue() && policy instanceof VersionLockingPolicy) {
((VersionLockingPolicy)policy).writeLockValueIntoRow(writeQuery, object);
}
}
// PERF: Avoid events if no listeners.
if (getDescriptor().getEventManager().hasAnyEventListeners()) {
DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToUpdateEvent, writeQuery);
event.setRecord(getModifyRow());
getDescriptor().getEventManager().executeEvent(event);
}
int rowCount = updateObject().intValue();
if (rowCount < 1) {
getSession().getEventManager().noRowsModified(writeQuery, object);
}
if (getDescriptor().usesOptimisticLocking()) {
getDescriptor().getOptimisticLockingPolicy().validateUpdate(rowCount, object, writeQuery);
}
}
getSession().getCommitManager().markPostModifyCommitInProgress(object);
getSession().getCommitManager().markPostModifyCommitInProgress(writeQuery.getObjectChangeSet());
// Verify if deep shallow modify is turned on
if (writeQuery.shouldCascadeParts()) {
queryManager.postUpdate(writeQuery);
}
// PERF: Avoid events if no listeners.
if (getDescriptor().getEventManager().hasAnyEventListeners()) {
getDescriptor().getEventManager().executeEvent(new DescriptorEvent(DescriptorEventManager.PostUpdateEvent, writeQuery));
}
}