aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RecordNotFoundException in find(...) method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RecordNotFoundException in find(...) method" Watch "RecordNotFoundException in find(...) method" New topic
Author

RecordNotFoundException in find(...) method

Chris Popz
Greenhorn

Joined: Feb 19, 2007
Posts: 14
*URLyBird 1.3.3*
Hi all:
The spec of the find(String[] criteria) method says:

Throws RecordNotFoundException if the specified record was not found or marked as deleted in the database file.

Now, for each record in the db file that match the criteria I make a check to see if the record is deleted, if it is, then I (should) throw a RNFE, which in my case is handled in the client. No to the problem: If I find a deleted record in say the middle of the result set (records matching criteria), a RNFE i thrown, but somehow I would like to go back to check the remaining records in the result set. How do you solve this?

Regards, Christian
[ May 10, 2007: Message edited by: Chris Popz ]
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Chris Popz:
*URLyBird 1.3.3*
Hi all:
The spec of the find(String[] criteria) method says:

Now, for each record in the db file that match the criteria I make a check to see if the record is deleted, if it is, then I (should) throw a RNFE, which in my case is handled in the client. No to the problem: If I find a deleted record in say the middle of the result set (records matching criteria), a RNFE i thrown, but somehow I would like to go back to check the remaining records in the result set. How do you solve this?

Regards, Christian

[ May 10, 2007: Message edited by: Chris Popz ]


I didn't throw RecordNotFoundException from my find method at all if no records were found, I dropped the exception in my Data class implementation of DBMain. There is no need to even match the criteria if the record is deleted so you could do this check before comparing the record to the criteria. A client is not at all interested in a record that has been deleted, all a clients wants is a array of record numbers if any that match), so throwing RNFE is not really a suitable course of action in my opinion. I returned an empty (or null can't remember) array if no matches are found.

To avoid duplication of code in the read and find methods I had a private readRecord method that was used by both methods. This method returned the record data String[] if a record existed or null if a record had been deleted so it could quickly be determined if a record was useful or not.


SCJP<br />SCJD
Lucy Hummel
Ranch Hand

Joined: Apr 07, 2005
Posts: 232
Hi,

Nor do I.

I think a RecordNotFoundException should be thrown if you requested for a single record and not if you question for a set of records that should full fill a certain criteria.


----------------------------------<br />| SCJP, SCWCD, SCBCD, SCEA, SCJD |<br />----------------------------------
Chris Popz
Greenhorn

Joined: Feb 19, 2007
Posts: 14
Hi Mark:
Ok, yes your proposal sounds logical... I'm just afraid that I will break the contract...

Thanks btw

Regards,

Christian
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Chris Popz:
Hi Mark:
Ok, yes your proposal sounds logical... I'm just afraid that I will break the contract...

Thanks btw

Regards,

Christian



It not breaking the contract because clients of the interface can still be prepared to catch the RecordNotFoundException, it just that if they are using an instance of your Data class it will never come. I passed by doing this, so once a mention is made in the choics.txt you should be fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RecordNotFoundException in find(...) method