File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Update Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Update Issue" Watch "Update Issue" New topic
Author

Update Issue

Ulises Pulido
Ranch Hand

Joined: Jul 24, 2008
Posts: 81
Hello:

While I was writing my choices.txt I found out that I did not think about an issue. Is it possible for someone to book a room after it was reserver by someone else? I mean if the room has already been reserved by someone else, is it possible to book it for another client?. At first I thought this was not possible but what happen when two persons have open the GUI in two different machines one performs an update over a row, meantime the other guy in the other GUI tries to update the same row (the GUI will let him try because he is not aware that someone else already booked it) do I let him update it, or should I see first if the row has not been updated already and in case that it is to tell him that another person already booked the room and say him thanks for trying.

This is a common issue with databases that I remember is called shadowing, but the point is, are we able to update twice or more times the owner ID ?.


I hope you can help me on this.


SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCJD, SCEA in progress
www.ulisespulido.com
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1963
    
    7

Hi there, I thought about this issue too especially the network mode. One thing is how you designed your Data class. I did mine as a singleton so only one instance. The way I'm thinking is once one client update a record, the program/thread notifies all other threads/clients and refresh their table views.

This sounds easy but where to trigger the notification (server or Data class?)

Another way is depending on how you implement your book method. I use a JDialog popup. So I can lock the record when the JDialog opens until it disposes itself. But then the locking would be longer than usual and could have problems if program hangs during the update.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
Fola Fadairo
Ranch Hand

Joined: Feb 16, 2004
Posts: 35
Sure, another customer might try to book a reserved record but should not be able to do so. My understanding is that a booked record should have the owner field populated. So it should not be possible for a customer to book a record when the owner field is populated.
Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 230
My instructions said: If record is marked deleted, it(Data-class) should throw RecordNotFoundException. Record is marked deleted, when someone has reverved it. (after that you can show user some dialog etc)


SCJP 5.0, SCJD URLyBird 1.3.3, OCMJEA 5 (SCEA) Factory Homes
Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Posts: 158
It's probably better not to allow re-booking of the same record, especially without the user knowing that he's overwriting his colleague booking. You can either entirely deny re-booking of a booked record, or at least issue a warning "This room is already booked. Are you sure you want to re-book it?". I chose the first approach.

Jari Timonen wrote:My instructions said: If record is marked deleted, it(Data-class) should throw RecordNotFoundException. Record is marked deleted, when someone has reverved it. (after that you can show user some dialog etc)

I don't believe that your instructions say "a booked record should be marked as deleted". This would be quite wrong in my opinion. Since deleted records are available for reuse (or at least that's what the javadoc probably says), anybody could overwrite a booked record (create one on top of it), and nobody will ever know there was a booked room, where, and for which client. Also, deleted record are not showable in the table, so nobody will be able to view booked rooms for (let's say) tomorrow, when the hotel wants to know how many customers to expect.


SCJP 1.4 100%
SCJD 99.5%
Ulises Pulido
Ranch Hand

Joined: Jul 24, 2008
Posts: 81
Thanks for all the people that helped me in this issue,

I am going to follow the approach of checking first if the Field owner id of the row to be updated is not already filled with something after locking that row, I mean lock it first, verify, update in case nothing is in the owner field or throw an exception in case that it contains data already, unlock the row.

Also following Alecsandru advice, send to the user a message in case that he couldn't update the row because it was either deleted or already updated.

Thanks for all your comments they helped me a lot.
Jari Timonen
Ranch Hand

Joined: Jan 16, 2004
Posts: 230
Alecsandru Cocarla wrote:It's probably better not to allow re-booking of the same record, especially without the user knowing that he's overwriting his colleague booking. You can either entirely deny re-booking of a booked record, or at least issue a warning "This room is already booked. Are you sure you want to re-book it?". I chose the first approach.

Jari Timonen wrote:My instructions said: If record is marked deleted, it(Data-class) should throw RecordNotFoundException. Record is marked deleted, when someone has reverved it. (after that you can show user some dialog etc)

I don't believe that your instructions say "a booked record should be marked as deleted". This would be quite wrong in my opinion. Since deleted records are available for reuse (or at least that's what the javadoc probably says), anybody could overwrite a booked record (create one on top of it), and nobody will ever know there was a booked room, where, and for which client. Also, deleted record are not showable in the table, so nobody will be able to view booked rooms for (let's say) tomorrow, when the hotel wants to know how many customers to expect.


That's true. Sorry about the confusion!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Update Issue
 
Similar Threads
URLyBird 1.2.1 - read for update
two questions: properties file and booked room
My overall design choice
URLyBird Basic QA on Locking
URLyBird GUI MVC <-> Business Layer in a Thin Client and HashMap vs. ArrayList