This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.
swimming certificate (A & B), shoelaces diploma, and some useless java ones.
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
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.