Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes 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
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

how to guys interprete "A null value in criteria[n] matches any field"

 
pioneer
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my search GUI, when user input "Name" field with "A", but leave "Location" blank, I go search based on criteria "Name" starts with "A". Then how about if user neither input "Name" nor "Location",then click search button. Should I return a list of all records to user? Doing this way satisfy the requirement of "A null value in criteria[n] matches any field" ? I personally don't want to go this way as I already provided user a separate button to allow view all the records. I intend to prevent user from going further to search if he/she leave all search fields blank. But just scared by doing this, I wouldn't fulfill the requirement of "A null value in criteria[n] matches any field". How do you guys think?
 
pioneer
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by kaymen ji:
Hi,

In my search GUI, when user input "Name" field with "A", but leave "Location" blank, I go search based on criteria "Name" starts with "A". Then how about if user neither input "Name" nor "Location",then click search button. Should I return a list of all records to user? Doing this way satisfy the requirement of "A null value in criteria[n] matches any field" ?


Your best option is to follow the criteria as set down for the data class when implementing the find[] method, so null on all fields returns all records. As I think it would be risking automatic failure not to do so.

However...


I personally don't want to go this way as I already provided user a separate button to allow view all the records. I intend to prevent user from going further to search if he/she leave all search fields blank. But just scared by doing this, I wouldn't fulfill the requirement of "A null value in criteria[n] matches any field". How do you guys think?



There is nothing to stop you having another search method in a higher business layer that the GUI interacts with instead of dealing directly with data. This method could be used to filter the results of the find[] method in whatever way you see fit for your search function.
 
pioneer
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do this:



You would get all the hotels that start with "Marriot" irrespective of the values of the rest of the fields.


If you do this:



You would be fetching all the records.
 
lambertlee Li
pioneer
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks Mark and Edwin. Yes, I have those


In my Database class. So that means as long as I providing those methods in my Database class, I could do something a little bit different on GUI side, is what you mean Mark?
 
Edwin Dalorzo
pioneer
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, now your business class can retrieve all records and do some filtering to exclude those not matching a specific criteria.

For instance, those hotels which are not available, or the hotels that are not booked yet.
 
Mark Smyth
pioneer
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by kaymen ji:
Hi,

thanks Mark and Edwin. Yes, I have those


In my Database class. So that means as long as I providing those methods in my Database class, I could do something a little bit different on GUI side, is what you mean Mark?



Well in my implementation I have a DataClient class with two methods bookRoom(id, recNo) and search(Room searchCriteria, boolean exactMatch, boolean caseSensitive).

The room object is just a wrapper for the record data. In my search method if I want to return all records I send an empty room object to the method. This way it is also very easy to add in addtional search fields in the future.

For example If I want an exact match on a name / location I call data.find() to return all similar records and then discard the one that don't exactly match.

For example if I searched the location "Clare"

And find method returned
"Clare"
"Claregalway"
"Claremorris"

If exact match flag is set to trueI return only "Clare" to the client.
If it is false I return all three to the client.

Hope this helps,
Mark
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!