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

RecordNotFoundException

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The spec says:

Any method that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file


Now, to check if the record is deleted is done simply by checking the flag value. But how about if the record is missing? Currently I'm thinking of something like:

Would this "check" cover both "deleted" and "missing"? Or how do you fellow ranchers solve this?
 
Ranch Hand
Posts: 92
Android Eclipse IDE Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

When you delete a record, you do so by marking it with the delete flag in the file. So when you read a record, you should read first its flag and see if it is the valid flag or the deleted flag.
If the file pointer is beyond the end of the file, for example recNo = 100, of course the record is missing.
My original dbFile doesn't have deleted records, but you need to implement the behavior.

Regards,
[ May 08, 2007: Message edited by: Romeo Son ]
 
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I threw an unchecked IllegalArguement exception if the record number was < 0 or if it was beyond the bounds of the file, I only throw a RecordNotFoundException if a record has been marked as deleted.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My recNo is an sequence starting from 0 (same as position in the db file). Then I stored all valid and deleted recNos into 2 separated sortedSet. When
recNo < 0 || recNo > validRecNos.last() + 1 || deletedRecNos.contains(recNo), I through a RecordNotFoundException
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I also store all valid record numbers in a static attribute so that I know which record numbers are valid. If the record number is not stored, I throw the RecordNotFoundException.

@Tai,
I have a question to your statement:

Originally posted by Tai Hu:
When
recNo < 0 || recNo > validRecNos.last() + 1 || deletedRecNos.contains(recNo), I through a RecordNotFoundException


I do not get why you have the second operator
 
Tai Hu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the second operator should be recNo > validRecNo.last() I stored all the valid recNo into a SortedSet. So the validRecNo.last() represent the maximum recNo. If a given recNo is larger than the maximum recNo, it is out of range.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic