• 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:

findByCriteria

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Just a Quick Question on the findByCriteria method.

It is defined as below:

// 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 long[] findByCriteria(String[] criteria);


if the criteria was [Smallville, 210]?

Should I return only row numbers that have columns with both *Smallville* and 210 in this?

I guess this means looping through each record and then on each record looping through each field?

Am I on the correct track with this please?

Many thanks in advance,

Sophie J
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Originally posted by Sophie Jane:

Should I return only row numbers that have columns with both *Smallville* and 210 in this?

I guess this means looping through each record and then on each record looping through each field?



Yes, I do this -- checking each record in the database (that does not have the deleted flag) and each field of that record against the criteria. I interpret the search to be an 'AND' search where each record must have all components of the criteria to be included in the results.

Cheers, Jared.
 
Sophie Jane
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many Thanks Jared..
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
// Field n in the database file is described by
// criteria[n].

The way I understood and implemented this:

The criteria array has to have the same length as the number of columns on each field, so that: index 0 of the criteria needs to match the first column, index 1 of the criteria needs to match the second column and so on.

This includes some iteration over records and on each record matching each column with the corresponding value from the criteria.
 
Sophie Jane
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right I understand...

I guess this has an impact on how we let the user specify the search criteria in the front-end. If the search criteria array map directly onto the database record, I would have to specify a value for each, or a null in the case of a "Don't Care".

In two minds about this, Did you allow users to specify all values?

Thanks in advance...
Sophie J
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Sophie

I am working on URLyBird, just like you. It is a couple weeks ago since I implemented findByCriteria(String[] criteria).

My approach was fairly simple.

1. I check that the provided criteria array has the exact number of fields as the database file, if not throw an IllegalArgumentException. This way I make sure the array contains a field for every database column.
2. Then I start a loop that visits every record in the file. For that purpose I have a method isValidRecord(long recNo) that validates if a record number is withing the database scope.
3. If the record is valid I check the record is not deleted by means of reading its delete flag. If it is deleted, I ignore it and continue with the next record.
4. Then I read the record using the readRecord(long recNo) method already implemented.
5. Then I compare every field in the retrieved record with the fields in the provided criteria array. In this comparison I ignore any field which is null, and non-null fields are compared using the String.startsWith(String) method.
5. If a record matches all provided criteria, I add it to a List<Long>.
6. At the end I conver the List<Long> contents into a long[] and return it to the user. If no record is found I return an empty array.

However my implementation of DBAccess which I named DBAccessImpl is not the class directly exposed to the client applications through RMI. My RMI Server class works as wrapper (adapter) over the DBAccessImpl.

In the Server class I use a Map<String,String> to specify the search criteria, where the key is the column name, and the value is the criterium to be searched. If a column is not specified I assume it is null when I create the criteria array to be passed to the underlaying DBAccessImpl.

Now, I am working on my UI now. It is my intention that user fill in a form with all possible values he wants to filter the data with. Then I create a Map with all this values and pass it to the RMI Server. It will then convert it into an array and pass it to the underlaying DBAccessImpl.

That's the way I am doing it.

I hope this helps!
[ July 28, 2006: Message edited by: Edwin Dalorzo ]
 
Sophie Jane
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Edwin,

Thanks (again) for the advice. My initial thoughts were wide of the mark on this one, but I have a clear idea of this now.

Many thanks for helpful responses,
Sophie
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic