• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

criteria and criteriaFind

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is the question about the criteria string used in criteriaFind method.
According to Sun, if one of the field name is not valid, then we return null because it is considered as the same as no matched record.
How about the following cases:
1) The criteria string is null or only white space? I see a lot people take it as "want all"
2) Right field name, no value?
such as "Origin="
3) Extra ","
example: "Origin='SFO',"
4) No single quote or mix
example: "Origin=SFO,Destination='LUX'"
5) No field name
example: "Origin='SFO','LUX'
..... etc.
a) Can we consider the malformatted criteria as the same as invalid field name and return null ?
b) Can I use the real databse field name as the field name in the criteria string ? Do I need to do match between them ?
example: Database field name = "Origin airport"
Sun's example = "Origin"

Thanks,
John Chien
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a) yes malformed criteria strings count as no match.
b) Yes use the field names, I think they had a slight typo in their example of their criteria string.
I used field names so that I can compare filed names and values to make my matches. Otherwise you would need to come up with a matching template to let the class know what "Origin" mapped to which field in the database.
Mark
Mark
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark,
Thanks. I think I can start to code criteriaFind now. There are many discussions about it. I will follow them when I code.
Thanks,
John Chien
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may use ComboBox on your GUI to narrow the user options for search criteria. No worry about the malformatted criteria.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,
Just a side note.
I used regular expressions (java.util.regex package) extensively in my criteriaFind implementation. It made my code compact, easy to understand. Most importantly, it's very robust - handles every concievable incorrect input string. You might want to explore it a bit. It definitely pays to learn about regex, since, like i said, it will do the matching for you (just gotta come up with the right expressions, of course) and will automatically handle errors - accept correct input, reject wrong input.
-lev
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lev,
Can you please tell me the logic of your criteriaFind using regex. I started off using the predefined character class "\\W" to strip off the non-words (",= and ''). Now I am stuck. Can you tell me your algorithm?
Thanks
Surya
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jack: Although we can narrow down the Malformed criteria case, the criteriaFind() itself should be generic enough to handle all the cases.
Lev: Thank you for the suggestion. However, I have already finished coding and tested. It is satifactory to me. I won't spent more time on it. But, I will keep your suggestion in mind to learn the regular expression later.
Thanks,
John Chien
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic