if (!getModifyRow().isEmpty() || shouldModifyVersionField != null || changeSet.hasCmpPolicyForcedUpdate()) {
// If user defined the entire row is required. Must not be built until change is known.
if (writeQuery.isUserDefined() || writeQuery.isCallQuery()) {
writeQuery.setModifyRow(descriptor.getObjectBuilder().buildRow(object, session, WriteType.UNDEFINED));
}
OptimisticLockingPolicy lockingPolicy = descriptor.getOptimisticLockingPolicy();
// Update the write lock field if required.
if (lockingPolicy != null) {
lockingPolicy.addLockValuesToTranslationRow(writeQuery);
// Do not lock an object that has previously been optimistically locked within the RWUoW
boolean existingOptimisticLock = false;
if (session instanceof RepeatableWriteUnitOfWork) {
RepeatableWriteUnitOfWork uow = (RepeatableWriteUnitOfWork)session;
if (uow.getOptimisticReadLockObjects().get(object) != null && uow.getCumulativeUOWChangeSet() != null
&& uow.getCumulativeUOWChangeSet().getObjectChangeSetForClone(object) != null) {
existingOptimisticLock = true;
}
}
if (!existingOptimisticLock) {
// update the row and object if shouldModifyVersionField is non null and has a value of true (a forced update),
// or if there is no forced update and modifyRow has modifications
if ((shouldModifyVersionField != null && shouldModifyVersionField) || !getModifyRow().isEmpty()) {
// Update the row with newer lock value.
lockingPolicy.updateRowAndObjectForUpdate(writeQuery, object);
} else if (!shouldModifyVersionField && (lockingPolicy instanceof VersionLockingPolicy)) {
// Add the existing write lock value to the for a "read" lock (requires something to update).
((VersionLockingPolicy)lockingPolicy).writeLockValueIntoRow(writeQuery, object);
}
}
}
if (descriptor.hasSerializedObjectPolicy()) {
descriptor.getSerializedObjectPolicy().putObjectIntoRow(getModifyRow(), object, session);
}
// PERF: Avoid events if no listeners.
if (eventManager.hasAnyEventListeners()) {
DescriptorEvent event = new DescriptorEvent(DescriptorEventManager.AboutToUpdateEvent, writeQuery);
event.setRecord(getModifyRow());
eventManager.executeEvent(event);
}
if (QueryMonitor.shouldMonitor()) {
QueryMonitor.incrementUpdate(getWriteObjectQuery());
}
int rowCount = updateObject().intValue();
if (rowCount < 1) {
if (session.hasEventManager()) {
session.getEventManager().noRowsModified(writeQuery, object);
}
}
if (lockingPolicy != null) {
lockingPolicy.validateUpdate(rowCount, object, writeQuery);
}
}
commitManager.markPostModifyCommitInProgress(object);