• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Home contractor assignment, update()/create(), DuplicateKeyException

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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.
Werner
[ April 18, 2003: Message edited by: Werner Joerling ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Nick, you are a little confused.
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.
Mark
 
Werner Joerling
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because this application deals with booking records and not editing records, it only has to change the owner field from an empty to a non-empty value. In this special situation we really need not care about duplicate keys, and furthermore, need not answer the question which fields the key consists of.
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 ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"IMHO update() has to throw DuplicateKeyException."
Never, you will never have to change the Key, and therefore never throw a DuplicateKeyException.
Mark
 
Nick Lee
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Mark
Now,I ve understood what u mean,and thanks for ur instruction.
I ve another question on my system:
how can I produce a customer ID(8 digit number) in my gui? what is it format?
00001234 or 12345678?
Is it a random one or not?
thanks very much
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well a customer ID. Hmm, there could be many solutions. You could use the customers Social Security number. You could try using a random number, but that can't guarantee that two clients might get the same number. Same with Thread ID, there isn't a guarantee there either.
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
Mark
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark, and Nick Lee,
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.
GVRao
 
Nick Lee
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You could use the customers Social Security number.


hi,Mark
What do u mean with customers Social Security number? I haven't any info about that.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nick,
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?
Regards, Andrew
[ April 23, 2003: Message edited by: Andrew Monkhouse ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, ignore my Social Security part. Basically the client ID is nto something that has to be figured out in code. The users already know the client's ID and will enter it themselves.
Mark
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's back to the original question, In my assignment the create method takes String[] data as input param, we don't know which column is the key, how could we judge when to throw DuplicateKeyException in the implementation? Or just leave it there without doing anything?
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.
Larry
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first value can be passed to the find method which would return the Key.
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.
Mark
 
Larry Li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx, Mark.
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.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that is the case that there are two of the same hotel rooms, then there will be two records that look identical. The only difference is the Kye which is the record number.
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?
Mark
 
Larry Li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I can't find any "unique like" ideas according to code above, neither in other part of the instruction doc.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Larry Li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chan, when read the instruction doc for the first time, I had the same view. But there aren't any specific instruction that mention it, so "may be" couldn't do any help. And I think there possibly two same rooms in a hotel, that is to say, with same hotel name and location.
Appreciate your comments.Keep in touch
Larry.
 
Larry Li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am assuming this is the B&S assignment. Then am I to understand from a post in this thread that we are only booking in this application and nothing more...that we dont have to worry about supposing a company has 10 employees and 3 of them are hired out then the company can still be used by another customer because now there are 7 employees left to be hired out?
 
The only thing that kept the leeches off of me was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic