aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes find method and criteria with multiple not null values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "find method and criteria with multiple not null values" Watch "find method and criteria with multiple not null values" New topic
Author

find method and criteria with multiple not null values

Margarita Babkova
Ranch Hand

Joined: May 09, 2012
Posts: 32
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

Joined: Feb 22, 2012
Posts: 19

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

Joined: May 09, 2012
Posts: 32
ok i will try to implement db find method with all criterias and use AND instead of OR between elements.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4907
    
  10

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.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: find method and criteria with multiple not null values
 
Similar Threads
RecordNotFoundException in locking
NX: URLyBird questions about database
Beta Question: unlock
URLyBird 1.1.3 find() interface method
What is the UrlyBird?