Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB locking  RSS feed

 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think EJB "ISOLATION" provides locking within a method (pls correct me if iam wrong). Now i have entity bean which reads the data from database (using ejbLoad()), once i present that data for the user to update, i want to lock that record till the user completes updation (ofcourse assuming that it will be done by ejbStore()). Will the ISOLATION provide this kind of locking, that is between ejbLoad() and ejbStore(). If not how do i achieve this in my application ?
Any help is appreciated
Thanks in advance
Hari
 
trupti nigam
Ranch Hand
Posts: 640
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The isolation levels are provided to help avoid the problems like dirty read, phantom read, repeatable read..
When two clients want to access the same entity bean ,for some data base operation the isolation level helps to achieve the lock on the particular row (represented by the entity bean) so that the same data is not available to the second client unless the first one finishes the operation.
Having isolation level also affects the performance. The more rigid the isolation level the more performance hit you have to pay.
As per your requirements you don't have control on the isolation level that it should work only between these particular period..in your case between ejbLoad() & ejbStore().
Once the isolation level is specified in the deployment descriptor the container decides when to put lock (generally when the other client wants to access the same entity bean ..depending upon the type of isolation..).
So it's not possible to achieve the lock between these two method calls..if some other client is not accessing the same bean.
At this moment I don't have solution to u r problem but i can think about it & then get back to you.
Thnaks,
Trupti
 
trupti nigam
Ranch Hand
Posts: 640
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
One correction to my answer..
You said that you want to lock the data between the ejbStore() & ejbLoad().
Basically what you want is when the user is updating the data the original data should remian intact.
This is possible with the isolation level. As long as some other client is not trying to access the same record(the bean) when the user is updating it.
Once some other client tries to access it the the container will put the lock on it.
Your question is little confusing as it says the lock between the ejbStore() & ejbLoad() operation but actually the lcking mechanism comes into picture when two different clients tries to access the same entity bean...
I hope this answers your question..
thanks,
trupti
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a couple of other ways of implementing this without actually "locking" the data, but essentially it's the age old problem of getting data and hoping that when it's saved, you're not overwriting somebody elses updates.
Basically, most of the strategies revolve around carrying around versioning information (e.g. a version number, timestamp, etc) with the data. If you are using value objects to ship data between your business and web tiers, then this is a good place in which to store this information.
Here's a couple of links for further information:
http://www.theserverside.com/patterns/index.jsp
http://www.theserverside.com/patterns/thread.jsp?thread_id=1695
Hope that helps
Simon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!