Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

find() in URLyBIRD - returning all records

 
Ranch Hand
Posts: 30
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 only
  • find() is responsible for returning record numbers that match the specified criteria
  • Specification 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 returned
  • view 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
     
    Sheriff
    Posts: 11604
    178
    Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    Rafal Kawecki
    Ranch Hand
    Posts: 30
    Eclipse IDE Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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
    Sheriff
    Posts: 11604
    178
    Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 30
    Eclipse IDE Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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
    Sheriff
    Posts: 11604
    178
    Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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
    Posts: 30
    Eclipse IDE Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks man !!!
     
    Evil is afoot. But this tiny ad is just an ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
      Bookmark Topic Watch Topic
    • New Topic