aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Overwriting values without knowing it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Overwriting values without knowing it" Watch "Overwriting values without knowing it" New topic
Author

Overwriting values without knowing it

Filip Moens
Greenhorn

Joined: Oct 16, 2003
Posts: 24
(Bodgitt and Scarper, but I guess it pertains to all asignments)
Situation:
User 1 displays all records
User 2 displays all records
User 1 books record 7, filling in a Customer ID.
User 2 does not see that the record is now booked and books it with another Customer id, thus double booking the Subcontractor.
How do you guys solve this problem?
Chris Harris
Ranch Hand

Joined: Sep 21, 2003
Posts: 231
Hi Filip,
In the Situation you have described:
I have coded it so, when user 2 attempts to book a record they are informed that the booking as failed beacuse the record has already being booked.
I have done this by adding a check in my book method of my CSRdbAdapter, which is an Adapter of the Data class.
Chris


SCJP 1.2, SCWCD, SCBCD
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Filip,
Let us follow your example:
1. User 1 displays all records.
2. User 2 displays all records.
3. User 1 books record 7, filling in a Customer ID - He does it using your program which uses the following method sequence:
lock record 7
read record 7 and check if the Customer Id field is still blank? Yes it is! Therefore to ahead and
update record 7 and finally
unlock record 7 so that it can be used by "other" clients.
4. User 2 does not see...? But he will see the updated customer id since he will use the same sequence that you wrote:
lock record 7 (if User 1 still has it locked, wait)
read record 7 - User 1 has updated the Customer Id field while he had the lock on this record. Therefore, now it is visible to User 2. Therefore do not
update record 7 but
unlock it anyway!
Hope this helps.
Bharat


SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Filip Moens
Greenhorn

Joined: Oct 16, 2003
Posts: 24
Hello Chris,
Indeed that 's a possible way to do it.
However, I was planning to allow the user to unbook a record by entering a blank value for the customer id.
Or even to allow the user to enter a new customer id to replace the old one, but not without him seeing that the record was already booked (e.g. by warning him)
I know the assignment states "It must allow the user to book a selected record, updating the database file accordingly.", meaning an unbook or a customer id change is not required.
But hey, we 're all putting in there more than is strictly required.
I wonder if many of us are trying to do it the way I want to.
By the way, do you require the user to enter an 8-digit number or do you allow less than 8?
Filip Moens
Greenhorn

Joined: Oct 16, 2003
Posts: 24
Hi there Bharat,
As I stated in a previous post, I was planning to allow the user to unbook a record by entering a blank value for the customer id.
Or even to allow the user to enter a new customer id to replace the old one, but not without him seeing that the record was already booked (e.g. by warning him).
So things are a bit more complicated then.
I wonder if I should stick to the assignment and drop my current solution which comes back to the client with an indication that the data have changed since his last find was performed.
It seems to be working fine so far, but I may risk losing points.
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Filip,
I am not doing it. I just wrote a simple program that cleans the customer id out for the testing, but I am not planning on including it in my submission. The more bells and whistles that you add, greater is the risk of overlooking some basic requirement and either not doing it well or forgetting to do it completely. I am coding strictly to the specs.
Regards.
Bharat
Filip Moens
Greenhorn

Joined: Oct 16, 2003
Posts: 24
Bharat,
you 're probably right.
I 'll sleep about...
Chris Harris
Ranch Hand

Joined: Sep 21, 2003
Posts: 231
Hi Filip,
By the way, do you require the user to enter an 8-digit number or do you allow less than 8?

I am currently allowing then to add a number less than 8. If they do I pad the field before I put it into the database.
However, I was planning to allow the user to unbook a record by entering a blank value for the customer id.
Or even to allow the user to enter a new customer id to replace the old one, but not without him seeing that the record was already booked (e.g. by warning him)

I have no plan to do this as it is outside the project. So what I am about to suggest my has not been fully tought out
When the user 2 is infromed that booking has fail, they could be provided with a option to override the booking. If they select to do this the code would call a method that allows to book a contractor (but with out checking if the contrator is already booked).
If you do decide to do this I would recommend that you add details within your choices.txt. Don't what the examier to think it is a bug
Chris
Filip Moens
Greenhorn

Joined: Oct 16, 2003
Posts: 24
Thanks for sharing your thoughts, Chris.
I think I'll throw it out. Don 't want to take too many chances.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overwriting values without knowing it