Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes Question transaction in several request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Question transaction in several request" Watch "Question transaction in several request" New topic
Author

Question transaction in several request

Evaristo Ballorca
Greenhorn

Joined: Feb 13, 2002
Posts: 17
Hello every body, i've a problem and i've been studying it from monday. Th e application is a web application( for a intranet ). My problem is that i want a database transaction in several request. It's posible??? I've been studying JTA, but it's for distribute transaction, one transaction with several connection that access distinct data resources.
A example is that in a request i load the client data to be updated, and i want that nobody could change this record. I've thing to implement this operative with flags. Could i do it in other away??
Thanks you very much??
Regards
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
"eballosa",
May I ask you to edit your display name so that it conforms to our naming policy.
Thanks.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Evaristo Ballorca
Greenhorn

Joined: Feb 13, 2002
Posts: 17
I've just changed it.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by eballosa:
My problem is that i want a database transaction in several request. It's posible??? I've been studying JTA, but it's for distribute transaction, one transaction with several connection that access distinct data resources.
A example is that in a request i load the client data to be updated, and i want that nobody could change this record. I've thing to implement this operative with flags. Could i do it in other away??

In general you want your transactions to be very short. Doing a lot of processing during the transaction is one thing. Leaving a transaction active while the user modifies fields in the HTML form, goes to get some coffee, decides to play a little ping pong, and then goes to lunch, is not a good idea.
One solution is to tag each object/row with a version number (usually stored in the database). When you load the record for the user, send the current version number. Once the user has made their changes and submitted it, check the version number they gave you (read earlier) against the current value. If they are the same, save the user's new values and *increment* the version number. If the version numbers differ, it means that another user modified the record while the first user was working on it.
At this point you can either deny the first user's edits with an error message, refresh the data (merge with their changes to be super-cool) from the database and let them try again, or provide an option to "force" the edit, overwriting what the changes made by the second user.
Basically, the goal is to allow the system to remain usable at all times. In the rare cases where a user's edits are blocked, they'll learn to save their changes before going to lunch.
Evaristo Ballorca
Greenhorn

Joined: Feb 13, 2002
Posts: 17
David, thank you very much. It's a very good solution. I never thought in this way.
Thanks.
Evaristo Ballorca
Greenhorn

Joined: Feb 13, 2002
Posts: 17
Hello David, i'm looking for same information about this mechanism in internet. I thing that exist diferent strategies to do this in web application. Do you know any web site wher i could read something about that??
thanks again
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
What David is referring to is know as offline locking. Probably the best resource I have seen on this is Martin Fowler's most recent book: Patterns of Enterprise Application Architecture. I highly suggest you pick up a copy of it... and not just because of this problem. It is an incredible book!
Back to your question... there are basically two types of locking: Optimistic and Pessimistic. Take a look at these links for a description of each as they apply to offling locking:
Optimistic Offline Lock
Pessimistic Offline Lock
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question transaction in several request
 
Similar Threads
JSF and Character Sets (UTF-8 mainly)
Login/Auth strategy for J2EE Application
What is wrong with my JTA?
Terminating the server
Deployment on wlserver5.1