• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

find and RecordNotFoundException in B&S

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// 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)
throws RecordNotFoundException;


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 ?


Please reply.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when a record is deleted, this record doesn't exist anymore. so it can certainly not match the criteria because it doesn't exist

i should throw a RNFE when no records match your criteria and show in the gui a message to user "No records found"
 
Ranch Hand
Posts: 158
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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"



Agreed.
 
pramod karnani
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


So my assumption is okay?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Kind regards,
Roel
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also don't advise throwing exception when a deleted record is found that matches the given criteria.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic