How to control simultaneous work on one db record.

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

xren
Ebase User
Posts: 272
Joined: Fri Dec 14, 2012 2:55 pm
Location: Ottawa

How to control simultaneous work on one db record.

#1

Postby xren » Wed Sep 25, 2013 2:07 pm

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
0 x

Steve
Moderator
Moderator
Posts: 421
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#2

Postby Steve » Wed Sep 25, 2013 3:05 pm

Hi xren,

Ebase does support locking

More information:

http://dev-docs.verj.io/ufs/doc/transac ... c106428118

Kind regards

Steve
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#3

Postby Jon » Wed Sep 25, 2013 3:45 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.

Code: Select all

try
{
  resources.MYDB.update();
}
catch (e)
{
  // handle update failure - send error message to user?
}
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
0 x

xren
Ebase User
Posts: 272
Joined: Fri Dec 14, 2012 2:55 pm
Location: Ottawa

Pessimistic locking not working.

#4

Postby xren » Fri Sep 27, 2013 2:51 pm

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!
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#5

Postby Jon » Fri Sep 27, 2013 4:08 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
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#6

Postby Jon » Mon Sep 30, 2013 9:24 am

Xiaoli,

The bug with pessimistic locking applies only to the Javascript interface. If you use FPL, it should be fine. The Javascript bug will be fixed in V4.5.1.

Regards
Jon
0 x

xren
Ebase User
Posts: 272
Joined: Fri Dec 14, 2012 2:55 pm
Location: Ottawa

#7

Postby xren » Mon Sep 30, 2013 3:41 pm

Hi Jon,

When should I expect the new update is coming?

Thanks,
Xiaoli
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#8

Postby Jon » Mon Sep 30, 2013 3:48 pm

Probably about 1 month from now. It's not likely to be much earlier.
0 x

xren
Ebase User
Posts: 272
Joined: Fri Dec 14, 2012 2:55 pm
Location: Ottawa

lock scope.

#9

Postby xren » Mon Sep 30, 2013 7:51 pm

Hi Jon,

What is the scope of the lock?

Can I check the lock from the global script?

Thanks,
Xiaoli
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#10

Postby Jon » Tue Oct 01, 2013 7:39 am

Locks are system-wide in scope. You can check then from any script. However, the locks are held in memory and are lost when the system shuts down.
0 x


Who is online

Users browsing this forum: No registered users and 14 guests