• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DuplicateKeyException

 
pramod karnani
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Q.1 create method is like that
public int create(String [] data) throws DuplicateKeyException;

please tell me when create method will throw DuplicateKeyException ?

I took record number as primary key for database file .
but whenever create method will insert new record ,It will always insert the record with new record number .
and in Sun specification is also not specified when to throw DuplicateKeyException ?


please let me know .
 
Cless Alvein
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you have noticed, there is probably no need to ever throw a DuplicateKeyException with your version of the assignment and your representation of record numbers. However, since you are defining a generic interface to the database, the specific database file format and internal representation aren't specified by the interface. Thus, another implementation might have to throw that exception. Think about why that could be and include an explanation in your choices.txt file as to why the method signature includes it but you never throw it.
 
Carlos Lacerda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karnani,

As Cless says you can or not throw this exception depending of your implementation, in my assignment i choosed for name/location as composite key and write this in choices.txt file.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

in my assignment i choosed for name/location as composite key and write this in choices.txt file.


ok i know that you want to write about you decision in the choices.txt document but i would ask you a question:
why you think that at DAO implementation level the name-location are the field that must be unique ?

best regards.
SCJP, SCJD in progress ( from 1/8/2007 till now).
 
Carlos Lacerda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i see data in my datafile has a Name/Location/Specialties/Rate/Owner, not sure for all, but seeing the data specialties has separated by "," rate is a any value owner has a id for customer. By this i assumes name and location as a primary key, i not sure for this, this not specified in instructions.html but i implemented so.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Carlos Lacerda;

thank you for you reply and opinion.

i understood that, although in my implementation i don't throw the exception at all as the requirement was not clear about the uniqueness of the records and about the primary key.

Thank you.

best regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic