• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Me neither!

Just don't forget to document why you are doing it.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic