| Author |
find() in URLyBIRD - returning all records
|
Rafal Kawecki
Ranch Hand
Joined: Feb 08, 2011
Posts: 30
|
|
Hi ranchers,
I need help with the find method because I am all confused now.
Correct me if I'm wrong but:
find() method in Data class should not know anything about the view (as as the whole Data class), espacially that the view is interested in searching by name/location onlyfind() is responsible for returning record numbers that match the specified criteriaSpecification says: 'A null value in criteria[n] matches any field value' - in other words (in my opinion) if there is at least one null then all records should be returnedview will be able to look only for: location, name, name or location so it will create:
so as you can see the find method will always return ALL records beacuse there will always be at least one null (of course I know there is additional filtering required becasue view expects exact matches)if someday I'll add searching by all fields than no changes to the find() will be required
Am I missing somethig?
Thanks in advance
Rafal
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 4351
|
|
|
I decided to ignore null values in the criteria array. If all values in criteria array are null I return all valid records. That's how I interpreted things and how I implemented the find-method of the Data class
|
SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
|
 |
Rafal Kawecki
Ranch Hand
Joined: Feb 08, 2011
Posts: 30
|
|
Thanks for extremely fast response.
Roel De Nijs wrote:I decided to ignore null values in the criteria array.
I don't get it. Can you please elaborate more on that? An example would be useful ;).
Thanks in advance.
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 4351
|
|
It's not hard: only non-null values are used to search the records.
For example: using String[] criteria = {"par", null, null, ..., null }; will return all non-deleted records which name starts with "par".
|
 |
Rafal Kawecki
Ranch Hand
Joined: Feb 08, 2011
Posts: 30
|
|
Roel De Nijs wrote:using String[] criteria = {"par", null, null, ..., null }; will return all non-deleted records which name starts with "par".
and String[] criteria = {"par", "loc", null, ..., null }; will return all non-deleted records which name starts with "par" OR location starts with "loc"?
One more question: ignoring null values in the criteria array isn't breaking the requirements ?
String[] criteria = {"par", "loc", null, ..., null }; shouldn't return all the records according to the specification ?
Thanks
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 4351
|
|
Rafal Kawecki wrote:and String[] criteria = {"par", "loc", null, ..., null }; will return all non-deleted records which name starts with "par" OR location starts with "loc"?
Rafal Kawecki wrote:One more question: ignoring null values in the criteria array isn't breaking the requirements ?
String[] criteria = {"par", "loc", null, ..., null }; shouldn't return all the records according to the specification ?
I passed with that approach, so I assume it's not against the requirements But that's of course a decision you have to document in choices.txt (and maybe also a bit in javadoc). The javadoc of my find-method mentions that passing a String[] with all null-values will result in all non-deleted records being returned.
|
 |
Rafal Kawecki
Ranch Hand
Joined: Feb 08, 2011
Posts: 30
|
|
|
Thanks man !!!
|
 |
 |
|
|
subject: find() in URLyBIRD - returning all records
|
|
|