• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: findByCriteria

 
Geoff Parkes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Apologies if this has been asked before, but a search through the board and i've not seen it mentioned.

My DB access interface has this provided as the search method.

public long[] findByCriteria(String[] criteria);

The GUI requirement is to allow an AND/OR search upon name/location.

null values are to match ANY record. So therefore my problem is this:

The OR search where i specify both name and location, will surely match on ALL records as the "null" values provided for the other fields match every record.

I could of course use a "DONT_MATCH" value for every other criteria field, but this is not desirable. Likewise i'm not keen to create a second find method to just search by 2 fields as GUI requires.

How have others handled this?

Thanks in advance, for any assistance.
[ December 24, 2006: Message edited by: Geoff Parkes ]
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple, if one field is empty exclude it from the search criteria.
Otherwise, if one were empty an OR search would indeed return everything if one field were empty but an AND search would return nothing at all...
 
Geoff Parkes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interestingly thats what I did when I first went through and wrote my find routine, however, it does raise some questions.

If null matches every possible field value, and "" matches none -- which is what we're saying here, then how do you search for values that are ""? For example, the owner field, which is the person who's booked the Contractor has a "" state which is perfectly reasonable.

How would you search for all unbooked contractors, i.e owner.equals("")?

Not to mention, you might want to find anyone with a name of "" or location of "". Unlikely, i grant you, but still assumed functionality.

In the end, i think i agree, more text for choices.txt
[ December 24, 2006: Message edited by: Geoff Parkes ]
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An empty string is by definition nothing, so should not affect the search results.
If you do think the user should have an option to explicitly search on an empty string, you'll have to provide for that explicitly by for example having a checkbox that the user can select to force inclusion of the empty string into the search criteria.
If you don't do that (and instead assume that empty input means you want to search on nothing and thus exclude everything), the user has no way to search on a subset of the available fields, hardly what the user would expect.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic