aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes UrlyBird: When will the create() method throw DuplicateKeyException ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "UrlyBird: When will the create() method throw DuplicateKeyException ?" Watch "UrlyBird: When will the create() method throw DuplicateKeyException ?" New topic
Author

UrlyBird: When will the create() method throw DuplicateKeyException ?

Eric Chou
Greenhorn

Joined: Jul 23, 2008
Posts: 20
Hi, ranchers:

Due to the instructions, I have to implement a method -- create(). The description tells me that I should allow user to insert a new record or reuse a deleted one. However, this method must throw a DuplicateKeyException which is not specified in the description.

public int create(String[] data) throws DuplicateKeyException;

I read the data file and found that the data record does not have primary key field (I have to use the index of the record location as primary key to uniquely identify a record). From my understanding, I think only when a new record and an existing record have identical contents in all the fields, a DuplicateKeyException will be thrown out.

However, from the name of the Exception, it implies that the Exception should be thrown when a new record has a key duplicating the key of an existing record. Again, the problem is: there is not nature primary key, there cannot be any primary key violence. Am I right?

What do you think about this issue?

Thanks
Jethro Borsje
Ranch Hand

Joined: Jul 22, 2008
Posts: 100
The most common solution for the DuplicateKeyException issue on this forum seems to be to not ever throw the exception as it is not clear when exactly it should be thrown.


SCJP, SCJD
Jeffry Kristianto Yanuar
Ranch Hand

Joined: Oct 01, 2007
Posts: 759
The most common solution for the DuplicateKeyException issue on this forum seems to be to not ever throw the exception as it is not clear when exactly it should be thrown.


Yes, I didn't throw either.

Jeffry Kristianto Yanuar
SCJP 5.0
SCJA
SCJD (Working on UrlyBird 1.3.2)
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Me neither!

Just don't forget to document why you are doing it.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
 
jQuery in Action, 2nd edition
 
subject: UrlyBird: When will the create() method throw DuplicateKeyException ?