Edit locking mechanism

Currently I have to deal with the concept of edit locking in a Flow application. This means that as soon as a user started editing a record, another user cannot open it for editing again, either by deactivating the edit button (if the list was not rendered already) or by displaying a message on trying to edit such a record.

I’ve implemented a very simple version of such a process before by adding an editLockUser (reference to Account) and editLockDateTime (for cleaning up “ghost” sessions) property to the respective model and doing the necessary checks. This works, but using it for more than one domain model would blow up the database and feels dirty.

I came up with another concept and would be glad for some feedback - maybe one of you has better ideas or worked with this requirement before:

  • Adding a domain model “editlock” with properties objectType (the class name of the object), objectIdentifier (the uuid of the object), user (reference to User which has a relation to Account), lockDateTime (DateTime).
  • Write an entry when calling editAction, remove it after calling updateAction (maybe by AOP?).
  • Respect the lock state when generating lists (editable = false) and calling editAction (if edit session was started after rendering the list).
  • Have edit lock sessions expire after a certain time (similar to session timeouts in e-banking applications).
  • Have command to clean up expired sessions.

Thanks for sharing your thoughts on this approach!