why the method void update(int recNo, String data) does not throw a DuplicateKeyException as int create(String data) does?
I assume, that structurally the argument data represents the same in both methods, namely the record values (name, location, specialties, size, rate, owner), and therefore the method update() has to prevent duplicate keys, too.
[ April 18, 2003: Message edited by: Werner Joerling ]
Actually in update you want a key that matches one that is already used. Because you are updating, not inserting.
You need the key to match one that exists so you know which record to update.
So there is no such thing as a DuplicateKeyException in update.
Mark,I'm a new comer here and I'm confused if we should consider that the new coming record and one of the old record are totlly the same,at that time,we should throw a DuplicateException,am I right?
If I am adding a new record to the database, then the create() which adds the new record needs to check to see if that key already exists, if it does, that means you are trying to add a second record with mathcing keys, or in other words you are adding a duplicate key, hence the reason for throwing a DuplicateKeyException in the create() method.
Now if you are only changing an already existing record, you will call the update() method, and this method needs to be passed a key that already exists, so that it finds that record then updates it with the changed data. So you see in this case the record/key must already exist. So if you threw a DuplicateKeyException here, you would basically always be throwing this exception everytime you call this method, because you have to pass an already existing key to update that record.
The record to update is given by recNo, and data contains the all fields of the record. This generality is suited for fictive (but real world) enhancements that may sound like: "Make it possible to edit and save all fields of a single record." Then the question for the key gets important and IMHO update() has to throw DuplicateKeyException.
[ April 21, 2003: Message edited by: Werner Joerling ]
[ April 21, 2003: Message edited by: Werner Joerling ]
In my Beta exam with the contractor assignment, I wasn't required to have the application make the customer ID or name. It was just a JTextField that the user enters this information.
Hope that helps
In B&S assignment, it is clearly mentioned in the Database schema about this customer ID. It says "Th id value(an 8 digit number) of the customer who has booked this. Note that for this application, you should assume that customer and customer service representatives know their customer ids. The system you are writing does not interact with these numbers, rather it simply records them."
So according to this, user can choose any 8 digit number. I personally feel 00001234 == 1234. It is upto the user, who enters the number.
Further comments are welcome.
Do you have the same requirement as Venkateswara Rao Gunturu? If so, you can ignore Mark's suggestion about using a Social Security Number - just use any 8 digit number since you do not have to do anything with it other than record it.
If your question was "what is a social security number" - it is an Americanism. Every American has a unique social security number which can identify them to govenernment departments and other organisations.
Some other countries have similar unique identifiers for each citizen,but not all. So you could not use the social security number in an application that might be used in any country other than America.
Even in America I suspect that this might cause problems - what happens if another company is doing the booking in the company's name? Do you ask the company secretary to provide her social security number?
[ April 23, 2003: Message edited by: Andrew Monkhouse ]
I got this problem after finished create method, and surprisingly found no way to throw this exception.
In this database, we take recNo as the access key, whether reuse deleted record's space or not, we can avoid put two live record in to the some place, so no DuplicateKeyException .
Appreciate any comment.
Now the find method is implemented by you, so I can't tell you exactly what to do there, but it does throw a RecordNotFoundException, which is the result you want, because that means that this is not a DuplicateKey. Now if it returns some value, in my case it is the record number, I throw the DuplicateKeyException. So I actually have that it != -1, even though -1 is never sent back from the find method.
I got your idea, it's really helpful,but not in the Hotel Booking assignment.
I think two record can be completely the same before they are booked by someone after when they get a unique customer id.
Let's take a look at the columns:
Hotel Name,City,Maximum occupancy of this room,
Is the room smoking or non-smoking,
Price per night,Date available,Customer holding this record;
Before book course, it's usual for the hotel which has two same rooms.
So when find() could get same return values, I think it doesn't mean we couldn't add another same room.
Now my Spider senses tell me that Sun wouldn't do that to you, there must be something different in the data between those two rooms. Maybe room number or something, or maybe they made in the requirements that there can only be one room in a hotel of a type. Something that would make the find method be able to find one of those rooms and not all of the same.
What is the find method signature in the interface that Sun provided?
I can't find any "unique like" ideas according to code above, neither in other part of the instruction doc.
Originally posted by Chan Huan:
I got a same assignment. I think the confusion is what is key. through having analysed the instruction and business model, the key may be consist of name and location field.
that cant be it Chan Huan, because I have several records that would cause problems if that was the case.
and think about it, a hotel has several rooms, which may be up for grabs at the same time, and there are no room numbers, else that and a name/location combo would definately work.
Appreciate your comments.Keep in touch
Originally posted by Larry Lee:
TQ, I'm not quite agree with it.
I think a hotel with two same room is possible.
Yes, a room number is the best identity, but without it, a room can still be booked, when a customer comes, the waiter takes him to one of these rooms randomly. Looks strange, but possible.
I think you misread what I wrote, I tried to get across that a hotel has several rooms, these may be identical, sleeps 5 people, smoking, etc, and without the room number there is no way to uniquely identify the room, not from our database anyway, so thats why we issue record numbers to the rooms, problem solved.
now without a room number AND a record number, how does the person taking reservations know which "random" room the waiter has taken the new guest to ?
and if he doesn't, nor care, then at least he'd have to know how many such rooms he has available, and decrement so as not to reserve a room the waiter you speak of has just taken the guest to.
we dont have that luxury out of the box like the FBN assignment which I believe has a very similar setup from a different angle, and while I have no doubt you can implement it, I dont think its a good approach, but thats just my opinion, its too much work, one too many workarounds, and more code than required to get the job done