File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Validating Field names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Validating Field names" Watch "Validating Field names" New topic
Author

Validating Field names

Padmaja Prasad
Ranch Hand

Joined: Nov 14, 2001
Posts: 76
Hi,
My criteriaFind() method does not validate each of the field names in the criteria string seperately. Instaed it checks the whole record for name-value pair in the criteria string. It will return an empty DataInfo [] object if the field name is wrong or the criteria String is not valid. Is this approach good??
Also, the field names in the criteria String must exactly match with the field names of the record. So the criteria "Origin='SFO'" will get an empty DataInfo array.(Only "Origin airpot='SFO'" is valid).
Please let me know if anything is wrong...
Thanks
Padmaja
Thomas Fly
Ranch Hand

Joined: Sep 09, 2002
Posts: 164
Hi Padmaja,
My requirements state:
Note that only exact matches need to be handled in this criteriaFind(String) method./QUOTE]so I'd say you're mostly all right. I think it would be fair (though I don't do it this way) to define "Origin" as a field name, however.
Originally posted by Padmaja Prasad:
Also, the field names in the criteria String must exactly match with the field names of the record. So the criteria "Origin='SFO'" will get an empty DataInfo array.(Only "Origin airpot='SFO'" is valid).
Please let me know if anything is wrong...
Yes... I believe "Origin airpot" (unless you're trying to smuggle marijuana in your luggage).


Fly by Night Consultants<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr><i>I climbed on the back of a giant albatross<br />which flew through a crack in the cloud<br />to a place where happiness reigned...<br />all year 'round<br />the music played ever so loudly!</i><p><a href="http://thomasfly.com/songs/Traffic/Hole_in_my_Shoe_qt.htm" target="_blank" rel="nofollow">Hole in My Shoe</a><hr></blockquote>
Thomas Fly
Ranch Hand

Joined: Sep 09, 2002
Posts: 164
P.S. Obviously this forum software is in need of non-greedy regular expressions...
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Padmaja,

My criteriaFind() method does not validate each of the field names in the criteria string seperately. Instaed it checks the whole record for name-value pair in the criteria string. It will return an empty DataInfo [] object if the field name is wrong or the criteria String is not valid. Is this approach good??

That's probably OK but may not be as efficient as verifying the field names first since you can short-circuit the search on the first invalid field. Also, how do you handle an ANY situation? It seems to me that yours is an additive method as opposed to the easier subtractive method of gathering the matching records.

Also, the field names in the criteria String must exactly match with the field names of the record. So the criteria "Origin='SFO'" will get an empty DataInfo array.(Only "Origin airpot='SFO'" is valid).
Please let me know if anything is wrong...

That's fine. That's exactly what I did. Since it is assumed that your program builds the criteria, that should always work.
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Padmaja Prasad
Ranch Hand

Joined: Nov 14, 2001
Posts: 76
Thanks for your reply.
I apologise for mis-spelling airport.
Originally posted by Michael Morris:
That's probably OK but may not be as efficient as verifying the field names first since you can short-circuit the search on the first invalid field. Also, how do you handle an ANY situation? It seems to me that yours is an additive method as opposed to the easier subtractive method of gathering the matching records.

Hi Michael, I am constructing HashMaps that maps field name with data value for both the criteria string and every record in DB and then comparing their entrySets(using containsAll()). (Not using the for loop for finding the record match)
I'm handling ANY condition like this :
I'm not adding the field to the criteria string if it has ANY value. If the criteria String is empty, then before constructing the Maps, it'll simply return getAllRecords()(method defined in Data which returns an array of DataInfo containg all records).

That's fine. That's exactly what I did. Since it is assumed that your program builds the criteria, that should always work.
Hope this helps,
Michael Morris

Thank you so much, Your advise & guidence really helps me a lot.
Thanks
Padmaja
[ September 27, 2002: Message edited by: Padmaja Prasad ]
Thomas Fly
Ranch Hand

Joined: Sep 09, 2002
Posts: 164
Hmm...
Originally posted by Thomas Fly:
P.S. Obviously this forum software is in need of non-greedy regular expressions...

Originally posted by Thomas Fly:
P.S. Obviously this forum software is in need of non-greedy regular expressions...

Maybe the forum software just needs a preview capability...
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Padmaja,

I am constructing HashMaps that maps field name with data value for both the criteria string and every record in DB and then comparing their entrySets(using containsAll()). (Not using the for loop for finding the record match)
I'm handling ANY condition like this :
I'm not adding the field to the criteria string if it has ANY value. If the criteria String is empty, then before constructing the Maps, it'll simply return getAllRecords()(method defined in Data which returns an array of DataInfo containg all records).

That's essentially what I did so I guess I was just a little confused on your initial post.
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validating Field names
 
Similar Threads
criteria and criteriaFind
FBN: criteriaFind(String criteria) method; is this ok ?
criteriaFind
Data/criteriaFind() - couple of questions
search algorithm: clarity and efficiency