• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

primary key for a record?

 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

having been assigned URLyBird 1.1.2, I couldn't identify any natural criteria to distinguish between different records.
Although, there's no such two records in the provided .db-file, for me there could potentially be two records specifying the same hotel in the same location with each a room for 4 persons, non-smoking, same price and available on the same date. Having this, there's no way now to discriminate the two records, so if one client requests to delete one of these records, which one is actually chosen?
Having no information about how to identify a record uniquely, I just created an artificial primary key by using the unique position of a record in the file.
This works well in my application, but anyway, is this the right approach expected by Sun?

Using the position of the record in the file as primary key now involves another problem:
The method specification of create() in interface DB declares a DuplicateKeyException in its throws clause.
Using the position of the file as primary key, however, makes throwing this exception actually obsolete, so it would never be thrown by my implementation of this method. On the other hand, if I had chosen the combination of all known fields in a record to be the the primary key, throwing a DuplicateKeyException would guarantee that no duplicates would ever happen to exist in the file.

Does this dilemma imply that I was wrong with my assumtion to have duplicates in the file?

Thanks in advance for your help,
Andy

 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
having been assigned URLyBird 1.1.2, I couldn't identify any natural criteria to distinguish between different records.


My approach was the following:

There is one id... the position in the record file. Different line = Different entry. When there are two identical entries in the record file, then those are still different. There is nothing in my assignment forcing me to create an ID or to prevent identical entries. So recNo = lineNr.

The method specification of create() in interface DB declares a DuplicateKeyException in its throws clause.


Yuo donĀ“t have to use this exception. I completely ignored it.

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andy,

Having no information about how to identify a record uniquely, I just created an artificial primary key by using the unique position of a record in the file.
Me too

The method specification of create() in interface DB declares a DuplicateKeyException in its throws clause.
A throws clause doesn't mean this method must throw that kind of exception. It just means it might throw it. In the URLyBird application it is unlikely that this exception is thrown, because a real primary key (like the room number) is missing and a hotel can perfectly have two (or even more) different rooms with exactly the same characteristics (smoking not allowed, 2 persons,...)

Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic