Hi all, in URLyBird I implemented my delete() method by updating the delete flag to 1. The delete flag in my data file is 1 byte (using raf.writeByte(1)). Now for create() method, it throws DuplicateKeyException (public int create(String data) throws DuplicateKeyException). I implemented mine like this: 1) find total number of records 2) loop to check if delete flag=1 3) if yes assign loop var as return val and break loop 4) update delete flag to 0 and write data
When to throw DuplicateKeyException? Currently in step 3 above, I also check the first field, if it is the same as the input's first field, I throw DKE. Does this look right?
I tested my methods like this. say I use record 5: read(5) delete(5) newRecNum = create(data)) // got record number 5 correct read(newRecNum) // same as read(5) delete(newRecNum) create(data) // throw DKE?
Until now, most of the participants almost never throw the DuplicateKeyException including me. It is very likely that a person (maybe a rich person) books 2 or more rooms (perhaps for his big family) at the same time.
Thanks. After thinking about it, if I do check the fields' contents that would make the record number not a primary key per se. And if PK is numeric, I can't have duplicate records, unless the content consists of the record number as part of its content, which is unlikely.
Now on to the searching
K. Tsang CEng MBCS PMP PMI-ACP OCPJEA OCPJP
Jeffry Kristianto Yanuar
posted 11 years ago
Don't forget to document your decision while working at it. Doing so is the common practice when doing the assignment