Wiki optimistic concurrency example

Hi, I was looking at this wiki example: https://isomorphic.atlassian.net/wiki/pages/viewpage.action?pageId=525055.

If I read this correctly, as it’s not calling setAllowMultiUpdate(true) on the update, the criteria taken from oldValues would be dropped, and a concurrent edit would never be detected.

Is the wiki example still expected to work as written with current builds?

The link you posted is an old revision of that article (Confluence renders historical versions under their own pageId). The current version is here.

The old revision compares dsRequest.oldValues against a fresh fetch in Java and never uses them as criteria, so the operationBinding.allowMultiUpdate question does not arise for it. The current revision does set the request criteria to the old values via DSRequest.setCriteria() and checks DSResponse.getAffectedRows() for zero, which is presumably what you are asking about.

That approach works with current builds, and setAllowMultiUpdate() is not needed. We have confirmed this against a current 14.1 build: a save with stale oldValues comes back with the custom status and the current database row, and a “save anyway” with the server’s row as oldValues succeeds. The reason is that the framework trims update and remove criteria down to primary key fields during the request’s initial processing, before control reaches the DataSource’s own execute() or executeUpdate() method. Criteria you assign inside those methods are not trimmed again and are used as-is in the generated WHERE clause. Setting allowMultiUpdate would actually be counterproductive: it turns off the exact-case primary key matching that single-record updates use, and it causes the request to skip automatic cache synchronization unless an operationBinding.cacheSyncStrategy is set explicitly.

Two things in the article are dated:

  1. It says you must override execute() because overriding the update method does not work. SQLDataSource has since been refactored so that executeUpdate() is the supported override point. Overriding execute() still works, but executeUpdate() is the recommended place for this logic.

  2. Using every field of oldValues as criteria is fragile for real-world schemas. Float and sub-second datetime columns may not compare exactly, and any dataSourceField.includeFrom fields present in oldValues would be emitted into the WHERE clause. We recommend a single version or modifierTimestamp field instead: in executeUpdate(), add just that field from oldValues to the criteria, call the superclass executeUpdate(), and treat zero affected rows as a conflict. Fields of type modifierTimestamp are populated automatically on every add and update.

On the client, nothing has changed: ListGrid and DynamicForm still send oldValues automatically, listGrid.editFailed() fires for any negative status, and the record returned with your custom status is available in the handler. For the dynamicForm.saveData() path you still need rpcRequest.willHandleError on the request, as the article shows. The dynamicForm.suppressValidationErrorCallback setting is unnecessary, since false is the default and it only affects validation errors.

See also the concurrentEdits overview in the reference.