Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic