• 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

how to understand throws RecordNotFoundException when record is marked as deleted?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Help please, I am very close to upload my assignment. But I suddenfly found this statement "Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file". I have a readRecord() method, which read the record from database. It throws RecordNotFoundException only when that record physically non-exist in the database file. If I stick to the requirement, check deleted flag in my readRecord() and throws RecordNotFoundException, I would cause myself problem in find() method. Because in my find() method, I need to call this readRecord(), if readRecord() throws RecordNotFoundException when encounter a deleted record, my search would be interrupted and exit.

My question is : could I keep my old implementation? throws RecordNotFoundException in readRecord() only when record non-existing in database file? But if I keep it this way, is it risky for the accessor to fail me? Does it deviate the requirement? Nearly to submit, any change on the codes would be a cost to me .

By the way, I do have a isValidRecord() to check if that record is marked as deleted. In my lock() method, before locking a record, I need to make sure that record is not deleted, if record is deleted, RecordNotFoundException would be thrown from lock() method.
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're likely going to need to do some rethinking.
Either have the find method catch the exception and interpret it as there being no record, or rewrite the read method to be more generic, with another method to actually return the read record or throw the exception (and the find method ignoring the result if it's marked as deleted).

What I've done is create a method that reads in the entire recordset in one operation.
That method makes use of another method that checks whether a record is marked as deleted before actually calling readRecord to read it only if it is not so marked.



and in readAllRecords


As a result the find methods will always have a recordset that contains only records that weren't deleted at the time the recordset was read.
That's the best you can expect, there is of course always the possibility that a record is actually deleted between the moment it is read and the moment it is filtered by the find method, but IMO you can ignore that.
The chance of that happening later, between the moment the find method returns it and the moment the end user tries to do something with it, it far greater as that interval is far longer.
 
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kaymen ji:
Help please, I am very close to upload my assignment. But I suddenfly found this statement "Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file". I have a readRecord() method, which read the record from database. It throws RecordNotFoundException only when that record physically non-exist in the database file. If I stick to the requirement, check deleted flag in my readRecord() and throws RecordNotFoundException, I would cause myself problem in find() method. Because in my find() method, I need to call this readRecord(), if readRecord() throws RecordNotFoundException when encounter a deleted record, my search would be interrupted and exit.

My question is : could I keep my old implementation? throws RecordNotFoundException in readRecord() only when record non-existing in database file? But if I keep it this way, is it risky for the accessor to fail me? Does it deviate the requirement? Nearly to submit, any change on the codes would be a cost to me .

By the way, I do have a isValidRecord() to check if that record is marked as deleted. In my lock() method, before locking a record, I need to make sure that record is not deleted, if record is deleted, RecordNotFoundException would be thrown from lock() method.



An approach that I have used and which may require less changes to your code is to define a private readRecord method to do the work for the public read method. Instead of throwing a record not found exception when a record does not exist this method simply returns null for the returned String[]. You can then throw a RecordNotFoundException in your read method when null is read by the private method. If null is read by the find method you can simply ignore it.

Mark.
 
lambertlee Li
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, there,

Thanks for your guys suggestion. I got some idea from your posts. One more doubt came out : "Search All" means find only those record not marked as deleted? God! my current implementation when user want to search all, i return all records including those marked as deleted and display on GUI, with a status showing "deleted/active". It seems my understanding of "search all" is wrong? right? suggestion please! Thanks!
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kaymen ji:
Hi, there,

Thanks for your guys suggestion. I got some idea from your posts. One more doubt came out : "Search All" means find only those record not marked as deleted? God! my current implementation when user want to search all, i return all records including those marked as deleted and display on GUI, with a status showing "deleted/active". It seems my understanding of "search all" is wrong? right? suggestion please! Thanks!



I believe that the CSRs would be taking phone calls from customers that want to book a room for the night using the application that we have designed (Doing Urlybird myself). So I think that displaying deleted records would not be useful information to be cluttering up the screen with and is less user friendly.

I suppose it comes down to whether or not you consider a deleted record to be a record at all. Just answer this question, do you ever envisage a situation when a CSR would need to access a deleted record? Would there be some future undelete function? Remember that we cannot specify a particular record number when we do a create.

Mark
[ November 24, 2006: Message edited by: Mark Smyth ]
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I suppose it comes down to whether or not you consider a deleted record to be a record at all.



You should NOT consider a deleted record to be a record at all. The way database file is designed, when a record is deleted it is marked as "deleted" for performance reason. When a record is deleted, there are 2 ways to handle it:
1) Delete it and shift all records up so there is no wasted space between records. Obviously, this is going to be painful slow if you have lots of records.
2) Mark it as deleted and ignore it on querying/updating operations. The space of the deleted record can be reused by an insert. If the insert appends new record at end of file, the file will keep growing. Either way, a database file compress will removed all deleted records so that there are no wasted space between records.
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike Ng:


You should NOT consider a deleted record to be a record at all. The way database file is designed, when a record is deleted it is marked as "deleted" for performance reason. When a record is deleted, there are 2 ways to handle it:
1) Delete it and shift all records up so there is no wasted space between records. Obviously, this is going to be painful slow if you have lots of records.
2) Mark it as deleted and ignore it on querying/updating operations. The space of the deleted record can be reused by an insert. If the insert appends new record at end of file, the file will keep growing. Either way, a database file compress will removed all deleted records so that there are no wasted space between records.



I think you took that sentance a bit out of context to be fair. If you read the rest of my post what I was trying to do was to get him thinking about why he would ever want to show a deleted record. At no stage did I say that deleted records should be shown in the GUI.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic