Entity Locking

1
We have implemented our own Entity locking mechanism where multiple users aren't allowed to edit a certain entity at the same time. This however does not work as users are still able to edit the same entity. It doesn't happen often (maybe once a day), but the fact that it is happening is causing us great frustration. What we have done : We have an entity called Application. Application has a boolean attribute ApplicationLock. All our forms are opened via microflows. In the microflow we do a retrieve on Application where ApplicationLock = false. Immediately after the retrieve we call a microflow LockApplication which sets the ApplicationLock to false and then executes the this.getContext().endTransaction(); function in a java action. The only way I can see two users openeing the same application is when they do an application request at the same time. Applications are unlocked (ApplicationLock = false)when they click the exit microflow button or after 5 minutes via scheduled event (ApplicationLockTime > 5min) Is there a way around this? Roberto Postma has logged a feature request for this functionality. Is this possible? I am going to start implementing the Community Commons acquireLock functionality tomorrow, and would love to hear from anybody that is using this at the moment, how efficient and reliable it is. Any suggestions on our current process would also be greatly appreciated
asked
3 answers
2

I have also implemented my own record locking mechanism, and so far have not had any issues. I create a lock record in a separate entity rather than setting a flag field on the current record itself as you do. If the record is locked, I open a different view of the record that is read-only.

I could not use the Community Commons locking mechanism as we wished to be able to use more that one application node, and the locking in Community Commons is held in memory on the server node so cannot be shared across multiple nodes.

First, I guess in your question you mean you set the LockApplication to true, not false. So how can two users edit the same record...

  • Is 5 minutes long enough to log a record for? Might the first user have the record open longer and allow the second user to open it too?
  • As the LockApplication attribute is contained on the entity record itself, is it possible that the user has the value cached? If they open the record, close it then open it again, does a second retrieve occur or is the data cached? Might a second user have opened the record between these two events?
answered
1

I implemented the locking of community commons, and that works fine (e.g. as designed). However it is quite a drastic way of locking: when user 1 has opened record 1, user 2 is blocked (and informed that Mister x or y has opened the form)

Edit:

As mentioned by me in the topic that you refer to: it is

[1] Quite some work to add this locking functionality (especially when you want to have this implemented application-wide)

[2] It is easy to make errors while modeling (forget to set or release locks somewhere), so I modeled very carefully

Therefore my feature request 7774 that asks for an application-wide setting with the flexibility to override this setting on data/template-grid level...

IMO this feature would be a great enhancement when recordlocking is required.

answered
1

Read the literature about locking. You need a semaphore or lock that is guaranteed to be changed by only one 'client' at a time. Microflows in Mendix run concurrent. So that may be the cause.

Did you switch the microflow property: disallow concurrent execution?

Be sure in that microflow that everything is read from database, so do not use 'retrieve by association'.

answered