Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

criteria and criteriaFind

 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Jack Jiang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
lev grevnin
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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
 
Surya Gangadharan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic