• Post Reply Bookmark Topic Watch Topic
  • New Topic

Better strategy for handling stale data on End User Browser  RSS feed

 
Siva Prasad Reddy Katamreddy
Ranch Hand
Posts: 32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question on what would be the better strategy for handling the following situation.

Lets say a web application is developed which is for doing simple CRUD operations on Employee details of a company.

Suppose Manager1 and Manager2 both are viewing Employee1 details and clicked on Edit button to edit the details.
First Manager2 made the changes and successfully saved the modifications.

Now Manager1 is unaware of this and came back from his Coffee break and changed Employee1 details and when he clicked on Save what should i do??

I have the following options:
a) Save the latest changes done by Manager1
b) Show an Error Message to Manager1 saying the you are working on Stale data

For implementing Option#1 the logic is straight forward.

If i want to go with Option#2, how can i implement the logic??
Should i check whether all the earlier values before editing are equal to the current values in database and if they are same then only i should save otherwise i should show the error message?

Do i need to implement all these logic manually or is there any API/ORM frameworks supporting this?

I hope the Isolation level setting doesn't help in this scenario because its not the problem with concurrent updates.

Thanks,
Siva

 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Siva,

Some ideas:
- If the application is time sensitive (airline ticket booking, movie ticket booking) then a user should not be made to waste effort navigating a bunch of pages only to fail at the end ("ticket's been already booked. please try again" has happened to me in many sites and put me off from using them again) . For such use cases, I feel an immediate notification that state has changed should be pushed back to client, using server push (Comet API).

- In other cases, periodic Ajax polling should be sufficient.

Instead of comparing every field in submitted data, maybe maintain a version number for each record and bump it up on each update. When sending user data to browser, send the version number along. When client polls for updates, it sends only the version number of it's copy. If that version number differs from current version number, there's been a background update. Whether to reload all data and lose the changes depends on how much has changed and how much effort the user has put in. It should not be a frustrating experience.

Not sure if there's one framework for this specifically. Hopefully, somebody can suggest something.

Cheers
Karthik
 
Siva Prasad Reddy Katamreddy
Ranch Hand
Posts: 32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You gave nice ideas.
I remember somewhere i read JPA is providing such a versioning support.

Thanks a lot.

Thanks,
Siva
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome! Do let us know what solution you choose finally and why.
 
Dejan Mratinkovic
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google a bit about "optimistic lock". Ie. http://en.wikipedia.org/wiki/Optimistic_concurrency_control. JPA has built in support with @Version annotation. Check http://www.oracle.com/technology/products/ias/toplink/jpa/tutorials/jsf-jpa-tutorial.html#CHDJEHBA
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!