• Post Reply Bookmark Topic Watch Topic
  • New Topic

B&S: findbyCriteria criteria ??

 
Michael Vargenstien
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sup homey's. I'm having an issue with the SCJD assignment regarding the findByCritieria method and its relation to the front end GUI. In more context, there is a bullet in the paper which states the following:

�It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.

That being said, the findbyCritieria takes a String[] criteria as an arguement. I'm a bit new to the expression world but I am reading up on it very heavily.

Would it make sense to build a query expression based on the critieria that is passed in, for example:
...
...
while(i < criteria.size()){
if(data[i] != null)
query += criteria[i] + "(\\s)+";
}
...
...
Wouldn't this satisfy the and/or functionality. Since this would detect if one OR the other is present and also, the AND condition since both would be present. Or does the find functionality need to be more robust?

Any input you guys can give would help me out mucho gusto.

thanks!

 
Michael Vargenstien
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone out there?

 
Michael Vargenstien
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know what's up with this thread but if anyone is out there and wondering something similiar, I'm going to go with this approach. I'll used the findByCriteria for the OR matches and may create an exact AND function that will be used by the application, not the db interface obviously...but somewhere in there which makes the most sense.
 
Brian Kelly
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really understand what you're asking. And I don't understand what your code snippet is doing...

What is this " query expression passed in "? Passed in where? Where's it used? By whom?

Because in my project, the Data class must handle any search mix (where null = all). "Fred" matches "Freddy" etc. The Data class DOES NOT search for records that exactly match the values specified by the user.

It's only the client that searches for "records where the name and/or location fields exactly match values specified by the user."

I just use a combo box with "all" as one option of all possible locations/names ("all" being sent down to Data.java as string = null).
 
Michael Vargenstien
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian,

Thanks for your response. I didn't post the complete code because I tried to conform to the posting criteria with the SCJD forum rules. Basically, I have a case where I expect null, then I return all the records. The other case is the one described above. The question I was originally trying to pose was that if there is a regular expression such that "Fred" also matches "Freddy" by the findByCriteria function, would this function be acceptible based on the what the instructions.html stated previously regarding the and/or requirement which is surrounded by those nasty MUST words. I realize that one requirement is in the GUI and the other is in the db interface, however, it would be nice to promote reuse of code. As a result, the query expression I was trying to build and assemble was something along the lines of this:

criteria = "(" + criteria[i] + ")" + "((\\w)|(\\s))*";

But I wasn't sure if for example, the search needs to be able to handle something like this:

critiera[1] = "Joe Blow";
critiera[2] = null;
criteria[3] = "UK";

At this point, the db interface is done, so I'll need to just test the heck out of it.
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This was my view on the requirements, hopefully it might help, which I included in my design decisions.

Implementing 'AND' and 'OR' logic in Find method


It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.


The distinction I made was that the two requirements are to be implemented in different layers of the application.

i.e You must implement the Data interface and therefore the find method should return the records that start with the search criteria. Thereby keeping the data layer generic and not linked to search for location etc.

However in your business layer you need to implement the business requirement and perform additional filtering of the returned records to ensure they exactly match name/location fields.

Hope it helps

Jason
 
PaulSeldon07
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, I think I have the same requirement as you do about find.
I ignore name and/or location. Instead of that, I chose find from any.
It would be ok, I guess. But, I need some feedback from people, might help.
 
Michael Vargenstien
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys,

I agree with Jason about seperating the requirements from the 2 different layers. Since automatic failures suck, I would rather over do it then under do it. From the forum, I've seen someone else score a perfect that followed this idea. I think it makes most sense to implement it this way going forward. One requirement from the GUI (AND/OR) and the other in the database layer return long[] keys. As for my search method, it may be a bit overkill using pattern and matcher classes since startsWith might also do the trick. I stlil plan on using the pattern, matcher classes because, in real life, most likely that is what we'll need. I've tested the concept using Junit and JunitPerf both tools I recommend to anyone who is figuring out how to validate thier code and check for concurrency at the same time.

(I hate threads and don't trust my judgement. )
 
Yup, yup, yup. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!