Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: DuplicateKeyException

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers,
I have a confusion in implemention of method create(String[] data)from the interface DBMain.java!The signature of the method is

My question is under what condition the method should throw DuplicateKeyExcetion?
My understanding: Since the record does not contain any single primary key,it should throw when all the field of data matches with any field in the database file.If I'm wrong please correct me.
[ August 21, 2007: Message edited by: Sanjeev Singh ]
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took very simple approach, which seems to work quite well: not implementing it, because there are few issues which are not clear in assignment about DuplicateKeyException.
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you need to decide for yourself as a designer since the specification didn't explain it.

some decided that since the specifications didn't explain then just skip it check http://www.coderanch.com/t/184523/java-developer-SCJD/certification/NX-Notes-design-passed

another alternative would be the one you mentioned..

either way you choose you have to document it well.

regards
 
Daniel Vogt
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you should not implement this exception. if you throw this exception when the data match exactly - or defined by your design-decision (matching name/city) - you have to test the update method in the same manner. and there it is only possible to throw a securityexception or a record not found exception. it would be a little bit confusing to throw there a runtime exception.
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my URLyBird assignment I took Hotel Name and location as combine primary key. If you notice data provided by SUN also follow the same pattern. Create method will throw duplicate exception if new record has same location and name. But Update method will not throw since it is not allow to change name and location field. Also you have to mention your choice and explain that in future it can change if hotel booking allow same hotels from same location but not in current version. Your assignment is different so look into the data and take decision accordingly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic