// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public int  find(String  criteria)
When find method will throw RecordNotFoundException ?
let say when there are records for given specified criteria in the database file and those records are marked as deleted then find method will throw RecordNotFoundException ?
let say when array of record numbers that match the specified criteria has 0 element then find method will throw RecordNotFoundException ?
Roel De Nijs wrote:i should throw a RNFE when no records match your criteria and show in the gui a message to user "No records found"
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
posted 11 years ago
I think Alecsandru Cocarla is right we should not throw RNFE when find method returns array size 0.
And Roel De Nijs I need to tell you one thing that I am not deleting record physically from database file I am just changing deleted flag to 1 so it is possible criteria can match the deleted record .In that case find method will throw RNFE.
So what I conclude find method will throw RNFE only when criteria matches with any record in the database file and that records has deleted flag 1
I don't agree with that at all. it's completely unlogical.
if you delete a record (if you mark it as deleted or you physically delete it), the record isn't there anymore and because if it's not there any more it can certainly not match some criteria. because there is no record anymore.
You can compare it with a file search on windows xp/vista. if you delete a file on your hard disk, the file is marked as deleted and the space is indicated to be used again. but the file isn't really gone (because with special programs you can recover deleted files, if of course the space where the file was, isn't overwritten with another file). if you make a search to your file, that "deleted" file will never appear in your result list. nor will you get a message telling you "hi dude, i found a file that you deleted but it matches your criteria".
so for me there are just 2 possibilities:
- return null or an empty array
- throw a RNFException
i choose to throw the RNFException and i will add that to my choices.txt and you have to decide what you are going to do and document that in your choices.txt but i would certainly not throw a RNFException if a record is marked as deleted but that matches the criteria. But it's all up to you
My implementation of the find method does not attempt to match deleted records to the search criteria. If the criteria do not match any of the records in the database, no records are found. I understand that to mean 0 records were found, so an empty array is returned.
Something must be done about this. Let's start by reading this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!