Locking of database records

4
I have the following question regarding the locking mechanism on the Postgres Database. I have multiple users who can login and access the same customers. How does the platform prevent me from making changes to a customer account when another users is editing a customer account? Han Pieter
asked
3 answers
3

Hi Han

I have seen no evidence of any platform based record locking mechanism to prevent one user overwriting another's changes if they are editing simultaneously - perhaps someone from Mx can confirm?

However, in the past I have added this sort of functionality through workflow. Basically, write to a linked lock record table when a record is opened, and clean up the lock record when closing a form. Then when a user tries to open a form, check for an existing linked lock record, and if it exists open a read-only view of the data with a warning giving the name of the user who is currently editing the record. HTH

answered
3

Maybe it can be solved in the community commons package in a generic way, I posted an proposal here:

https://forum.mendix.com/questions/1511/Community%20Commons%20Module#2748

answered
2

On another platform (BMC Remedy ARS) this is solved in the following way:

  • Each record has a changedDateTime
  • The changedDateTime on retrieve is remembered
  • On save/commit the changedDateTime as remembered is compared to the changedDateTime in the database
  • If database changedDateTime > remembered changedDateTime than a message is given that somebody updated this record and the save/commit is canceled.

Off course this still needs locking during the transaction with some kind of SELECT FOR UPDATE, but it shortens the overlaptime dramatically from users having records open for minutes (or longer) to the sub-second level.

I have an enhancement request issued at Mendix for this function, allthough to be precise, I've asked for a function IsModifiedByOtherUser(), so I can determine myself what should happen.

answered