• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

When to throw a DuplicateKeyException

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When name/location pair is already known in the database,
of when all fields (except the "booked" field) match the input.

This is very unclear to me since NOTHING in the DB file specifies name/location as the key for a record !
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frank Verbruggen:
When name/location pair is already known in the database,
of when all fields (except the "booked" field) match the input.

This is very unclear to me since NOTHING in the DB file specifies name/location as the key for a record !


Yes, and I chose NOT to throw DuplicateKeyException in my data access class implementation.
I documented this uncertainty in my choices.txt.
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frank Verbruggen:
When name/location pair is already known in the database,
of when all fields (except the "booked" field) match the input.

This is very unclear to me since NOTHING in the DB file specifies name/location as the key for a record !


Frank, there has been much discussion on this topic, and some have felt that there needs to be some sort of unique key field in order to throw it. I actually took the opposite approach and a DuplicateKeyException was thrown if all the record's values (except customer id, don't check that one) were identical to the newly created record after trimming the record values. If so, then a DKE is thrown. I documented my decision and didn't get anything taken off because of it. It's really up to you.
 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frank:

I'm checking on name/location only and justifying my decision. I think this is closest to what would happen in the real world if you had an incomplete specification.

In my opinion, checking all of the fields is straying too far from the concept of keys. Except for very small records, this is not too realistic. I don't think the sample database given to us by Sun supports this hypothesis too well either.

Then again, I think the point of the exam is the thinking through the problem and documenting your thoughts part, not the ultimate solution.

Reza
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Reza Rahman:
Frank:

I'm checking on name/location only and justifying my decision. I think this is closest to what would happen in the real world if you had an incomplete specification.

In my opinion, checking all of the fields is straying too far from the concept of keys. Except for very small records, this is not too realistic. I don't think the sample database given to us by Sun supports this hypothesis too well either.

Then again, I think the point of the exam is the thinking through the problem and documenting your thoughts part, not the ultimate solution.

Reza



I don't throw it based on the choice that a true duplicate for a room would require Location, Name, Date and RoomNumber to be identical. And room number is not currently part of the data.
 
Frank Verbruggen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in the end, most of all the solutions are good, as long as u justify yourself in the choices file.
Thanx all
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic