• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

find method and criteria with multiple not null values

 
Margarita Babkova
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.
 
Anton Kuzmin
Greenhorn
Posts: 19
Eclipse IDE Java Mac OS X
  • 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.
 
Roel De Nijs
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic