Hi,
I have a form mapping to a db record. two user may work on the same record at the same time.
Is there a existing way in ebase on controlling this? e.g. lock the record when one person editing it and release it after she/he is done?
Thanks,
Xiaoli
How to control simultaneous work on one db record.
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 272
- Joined: Fri Dec 14, 2012 2:55 pm
- Location: Ottawa
-
- Moderator
- Posts: 421
- Joined: Fri Sep 07, 2007 3:44 pm
- Location: Sandy, UK
- Contact:
Hi xren,
Ebase does support locking
More information:
http://dev-docs.verj.io/ufs/doc/transac ... c106428118
Kind regards
Steve
Ebase does support locking
More information:
http://dev-docs.verj.io/ufs/doc/transac ... c106428118
Kind regards
Steve
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Xiaoli,
Please see documentation page transactional_concepts.htm which contains a discussion on locking - there doesn't seem to be simple way to navigate to this page so you will probably need to find it in the file system.
You've got a choice between "pessimistic" and "optimistic" locking. The choice depends on how likely a collision is. I think most people prefer to use optimistic locking nowadays.
With pessimistic locking, you take out a lock up front and release it when you've finished. To do this in Ebase you use system.lockManager.lock() and system.lockManager.unlock() methods. You can only use this if all your users editing the record are using your Ebase Xi form. The trouble with this approach, is that user 1 might not complete the edit in which case they will hold on to the lock until their session times out.
Optimistic locking is activated in the form properties dialog and is based on the idea that user 2 will only get a message when they try and perform an update. This is only available when using resources.XXX.fetch() and resources.XXX.update() to read and write your database record. At update time, the system re-reads the record and checks if another user has changed it - if so, the update fails e.g.
The trouble with the optimistic locking approach is that user 2 might spend 15 minutes typing in her updates only to find they are rejected.
Regards
Jon
Please see documentation page transactional_concepts.htm which contains a discussion on locking - there doesn't seem to be simple way to navigate to this page so you will probably need to find it in the file system.
You've got a choice between "pessimistic" and "optimistic" locking. The choice depends on how likely a collision is. I think most people prefer to use optimistic locking nowadays.
With pessimistic locking, you take out a lock up front and release it when you've finished. To do this in Ebase you use system.lockManager.lock() and system.lockManager.unlock() methods. You can only use this if all your users editing the record are using your Ebase Xi form. The trouble with this approach, is that user 1 might not complete the edit in which case they will hold on to the lock until their session times out.
Optimistic locking is activated in the form properties dialog and is based on the idea that user 2 will only get a message when they try and perform an update. This is only available when using resources.XXX.fetch() and resources.XXX.update() to read and write your database record. At update time, the system re-reads the record and checks if another user has changed it - if so, the update fails e.g.
Code: Select all
try
{
resources.MYDB.update();
}
catch (e)
{
// handle update failure - send error message to user?
}
Regards
Jon
0 x
-
- Ebase User
- Posts: 272
- Joined: Fri Dec 14, 2012 2:55 pm
- Location: Ottawa
Pessimistic locking not working.
The optimistic lock works fine.
However, the pessimistic lock does not work for me.
I tried the following code in the form before page script to lock one of the db record which are mapped to some of the fields on the form.
However, with one session opened the form and locked the resource, the other session still can open the form and does not go to the other form.
if(system.lockManager.isLockHeld("REHAB_INTAKE_THREE", fields.INTAKE_ID))
{
log("The intake form is locked by some user." );
form.gotoForm("REHAB_PT_CHART");
}else
{
var locked = system.lockManager.lock("REHAB_INTAKE_THREE", fields.INTAKE_ID);
log("I locked the intake form. - " + locked );
}
Is there anything wrong?
Thank you in advance!
However, the pessimistic lock does not work for me.
I tried the following code in the form before page script to lock one of the db record which are mapped to some of the fields on the form.
However, with one session opened the form and locked the resource, the other session still can open the form and does not go to the other form.
if(system.lockManager.isLockHeld("REHAB_INTAKE_THREE", fields.INTAKE_ID))
{
log("The intake form is locked by some user." );
form.gotoForm("REHAB_PT_CHART");
}else
{
var locked = system.lockManager.lock("REHAB_INTAKE_THREE", fields.INTAKE_ID);
log("I locked the intake form. - " + locked );
}
Is there anything wrong?
Thank you in advance!
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Yes, there's a bug. It'll be fixed in the next service pack. But it means you can't use the pessimistic locking technique until then. Hope the optimistic locking is OK for you. Incidentally, it should be fields.INTAKE_ID.value not fields.INTAKE_ID, but it still doesn't work properly because of the bug.
Regards
Jon
Regards
Jon
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
-
- Ebase User
- Posts: 272
- Joined: Fri Dec 14, 2012 2:55 pm
- Location: Ottawa
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
-
- Ebase User
- Posts: 272
- Joined: Fri Dec 14, 2012 2:55 pm
- Location: Ottawa
lock scope.
Hi Jon,
What is the scope of the lock?
Can I check the lock from the global script?
Thanks,
Xiaoli
What is the scope of the lock?
Can I check the lock from the global script?
Thanks,
Xiaoli
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Who is online
Users browsing this forum: No registered users and 6 guests