Pessimistic lock questions

I am trying to use record locking feature in CUBA and have some questions with regards to pessimistic locking after I have activated pessimistic locking from Administration > Lock > Setup.

I understand when a record is opened in the Editor, CUBA system automatically locks the record and prohibits from being edited by any other user and the same time.

  1. How the second user is notified, at the moment when he clicks on the edit button from the browser screen or before saving? Is there any default setting that can be used or suggestion how we can achieve this?
  2. As setting timer is mandatory, what will happen when the first user is still in edit mode and he is already time-out, is there any way we can read the first user’s activity and extend the locking time beyond the default setting? This may happen in many different situations in real-life use of the software. Any option to set unlimited time say 0 for unlimited?
  3. When I have setup the locking in development environment, is it going to be part of deployment by default or I have to do the same in every production instances?
  4. Which mode is used and how can we change if needed i.e. PESSIMISTIC_READ, PESSIMISTIC_WRITE, PESSIMISTIC_FORCE_INCREMENT?

Hi Mortoza,

  1. The user is notified at the moment when he tries to open the editor screen. The logic is in EditorWindowDelegate.setItem() method: when the entity is already locked by someone, the editor shows a notification and disables actions that save the editor.

  2. Extending the timeout is not implemented. The lock just disappears and any user will be able to edit the entity. And yes, if you set 0 as timeout for the lock descriptor, such locks will never expire.

  3. Locking setup is stored in the database, so you have to replicate it on each production database. You can add SQL INSERTs to you 30.create-db.sql script: open Entity Inspector*, select *Lock Descriptor entity and open System Information from the table context menu. Then click Script for insert and copy the script to the 30.create-db.sql file of your project.

  4. Pessimistic locking in CUBA is implemented in memory and has nothing to do with the database or JPA features.

Awesome