Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jamy Wang
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • 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
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic