This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RecordNumbers and FlightNumbers!

 
Lina Mahl
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I the only one that is irritated that you are supposed to use recordnumber and not flightnumber as a unique identifier for the Flights?
I mean that flightnumber are unique. Recordnumber are just a number in a database.
I can live with it but I would have made the flightnumber the key value in my database.
regards
/Lina
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And yes i don't like it either. According to me the flightnumber is the unique key as the add and find functionality search for the first row, which is the flightnumber.
You cannot add records with duplicate flightnumbers (at least not programmatically, through the add method).
Therefore i am using the flightnumber as unique key and put that in my assumptions, but i havent finished the certification.
However mark s.(bartender) points out the flightnumber may not be the unique key and he wrote another function to get the recordnumber, which is then used as unique key.
So, no conclusive answer.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the db.db file is just a small db. And the flights all seem to fly on only one day. But in the real world flights have the same flight number each and every day.
Now of course, this also isn't a real world app. But by looking at the code that Sun supplied in the Data class, it's getRecord method is using the record number. But the find method uses flight number, and it only returns one record.
Here's a quote from the Javadoc, so this will tell us that we can look at both a the PK, so we can all be happy
/**
* This method searches the database for an entry which has a first
* field which exactly matches the string supplied.
If the required
* record cannot be found, this method returns null. For this
* assignment, the key field is the record number field.

*
* @param toMatch The key field value to match upon for
* a successful find.
* @return DataInfo The matching record.
* @exception DatabaseException Thrown when database file could not be accessed.
*/


The first bold line leads us to believe that Flight Number can be used as the Primary Key, but the second line explicitly says Record number is the key for theis assignment.
Mark
 
Eduard Jodas
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean that flightnumber are unique. Recordnumber are just a number in a database.

RecordNumber is also unique. And it is always there, while a flightnumber may change. RecordNumber is the key to access a Record, which is the flight data container, and the flight data is much more important that just its flightnumber.
If you lock by flight number, in the end, the database must also lock by record number. And what happens if you lock by flight number because you want to change the flight number?
Locking by record number is much easier, and it is what is required for the assignment.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic