• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

NX: URLyBird1.1.3, about the find method in Data class.

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a little confused about the find method in DB interface:


public interface DB
{
...
// 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);
...
}


My question is : should I return the records which has been set the deleted flag?
Thanks a lot!
James
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James here's how we should intrepret that. Say suppose "criteria" is a String array of length 7(it depends on the number of fields in each record of your assignment), then if you call find like below

The above search exaclty gives one record and so only that particular record number is returned in integer array.
Suppose now the criteria is like this

Now all of the hotels with "Hilton" as their name in db file are returned. We shuold treat "null" as "*" i.e. wild card match.
If criteria is

Now as all null, the entire db records(to be specific, record numbers) should be returned from find method.

My question is : should I return the records which has been set the deleted flag?
Thanks a lot!
James
Nope. Deleted flags are treated to be deleted. I tried to explain with some examples above. If you have any questions, please ask them. Good Luck
 
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,

Originally posted by james wang:
My question is : should I return the records which has been set the deleted flag?


I agree with Satish, deleted records should never be returned. The only use for a deleted record is in the create method where the space taken by a deleted record can be reused to store the new record. Deleted records are skipped when doing a find. Attempting to access a particular deleted record in the other database methods should cause the RecordNotFoundException to be thrown.
 
Arthur, where are your pants? Check under this tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic