• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

find method and criteria with multiple not null values

Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I was working under find(Criteria[n]) method, and implemented couple scenarios, like:
1. if criteria has all null values – return all recNo from cache.
2. If criteria has only one real value and all rest are nulls -> return recNo matching single criteria.

But scenario when criteria has more than one not null value and potentially all values are not null puzzles me.
String[] criteria = {“Nice Place”, “My Town”, ” 2”, ”Y”, ”$200”, “2012/08/01”,null} ->

My interpretation of it is “select recNO from table where name=Nice Place AND city=My Town AND size = 2 AND price= 200 and etc.”
So, if database has hotel “Nice Place” in two locations: “My Town” and “Your Town”, only one record, can be returned, and only if , all rest criteria for size, price will match.

So, I have to create a count of internal matches between criteria and db record. So, if criteria has 5 values to search for – db record should have precisely 5 matching fields.

Is another interpretation like find any hotel with name =Nice Place OR location =My Town OR size= 2 OR price 200, etc will work?
Find in this case can return: x number of record Nice Place ( all different locations)
m number of record My Town ( all different hotels)
xx number of record size 2 ( all different hotels/ locations), etc
Any suggestion?

Thank you.
Posts: 19
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If instructions do not have specific search algorithm, you have to make decisions yourself and justify them in choices.txt. Think of some use cases that may happen with client and operator working with the application and implement the business logic accordingly.
Margarita Babkova
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i will try to implement db find method with all criterias and use AND instead of OR between elements.
Posts: 11604
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I opted to have a match if one criterium matches a record (so using OR instead of AND). There are a lot of threads discuss this issue, so just decide for yourself what's best (or what's most logical to you) and stick with it.
It's feeding time! Give me the food you were going to give to this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic