• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DuplicateKeyException question

 
Paul Howells
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

The DBAccess interface defines the createRecord method as throwing the DuplicateKeyException.

My question is this. The flat file database I was provided with does not have any keys and I am not allowed to change the db format so under what condition would a DuplicatekeyException be thrown? There is the customer id but it does not say anywhere that the customer cannnot book more that one room.

Any comments?

Thanks
 
Paul Howells
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should mention that I have URLyBird version 1.2.2
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

This topic is discussed regulary in this forum. The general consensus is that it is acceptable not to throw the exception. You'll have to document that in your choices document of course.

Some people have chosen to define what a key is and implement it. However, this approach raises another question: why is the exception not thrown in the update method?

If you want to read more sides to the story, try searching this forum for DuplicateKeyException.

Frans.
 
Yevgeniy Treyvus
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the B&S project, but I pretty much ran into the same question. I think that the reason the DuplicateKeyException is declared in the method signature is just in case your implementation will do some sort of duplicate key checking.

In other words, I don't think that this is a requirement. Your implementation *does not have* to do any duplicate checking unless it is explicitly stated in the instructions.

So I think that if in your design it does not make sense to check for duplicates then you should simply not throw the exception.

Keep in mind that even if the method is declared to be throwing the exception in the interface, you are not required to declare (or throw) it in the implementation as long as you're not adding to or changing the interface list...

for example, is legal:

 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

If you are able to define a key, I say go ahead and implement the exception. It makes for a better designed application. Frans is right, it should also be thrown in the update method... but let's face it, the interface provided isn't exactly perfect!

However, you said that you have URLyBiry. I have heard that a key is fairly difficult to define with this data set. Most who have defined one that I am aware of use the whole record (it is much easier with B&S, we can use name+location).

Others in this forum have passed without throwing the DuplicateKeyException. Whatever you choose to do, make sure you document your decision and your reasons for making it in your choices.txt and you should be fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic