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 search method in business layer 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 "search method in business layer" Watch "search method in business layer" New topic
Author

search method in business layer

Ethem Yuksel
Greenhorn

Joined: Feb 06, 2009
Posts: 6
Hi to all,
There are many topics mentioned about search algorithm. But i need a few code fragments how to accomplish the search function in business layer not in data. Data layer will make a search with the all fields starts with criteria[n]. Business layer will filter data's find results with the "equals". This is clear.

But how is it supposed to be combine these two items? What should be the simplest way? I have written something but looking forward to something simpler.

Thanks..
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2584
    
    9

Well Ethem, why you want to implement the search in the "business layer" when searching is one of those required methods in the Data class?

Business layer will filter data's find results with the "equals". This is clear.


What you mean by "equals"? Are you using the comparator or comparable interface to do the searching? Some code will help others what you done so far.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Posts: 158
Ethem Yuksel wrote:What should be the simplest way? I have written something but looking forward to something simpler.

Well, what did you implement so far? Maybe we could help you improve it.


SCJP 1.4 100%
SCJD 99.5%
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11503
    
  95

K. Tsang wrote:why you want to implement the search in the "business layer" when searching is one of those required methods in the Data class?

I would imagine that he would want to do this because of the different requirements.

The Data layer only requires a "begins with" matching.
The presentation layer requires an "exact match".

Therefore you must have different logic in two separate areas.

Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Ethem Yuksel
Greenhorn

Joined: Feb 06, 2009
Posts: 6
@Andrew, exactly right you are.
@Alec, my implementation is as the following. It is working but it really sucks How can i make it simpler? Regards...
Fola Fadairo
Ranch Hand

Joined: Feb 16, 2004
Posts: 35


Looks okay to me. I find it readable and easy to understand, especially for a junior programmer.


Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 176
Hi Fola

Not sure what the spec requirements are for your assignment.

I have done B&S 2.2.1 and the implementation of the DBAccess interface requires a possible search on all fields.

I use a Contractor class as an O-O framework which helps with the search functionality and use booleans for each field passed.

If the passed field is set to true then I check the value against my active Contractor record. Its a bit long winded but easy for a junior programmer to understand. Here's a snippet of code to explain what I mean.




Java5 Tutorials | Java6 Tutorials | HTML/CSS Tutorials | JavaScript and jQuery Tutorials
Fola Fadairo
Ranch Hand

Joined: Feb 16, 2004
Posts: 35
Hello Kevin,
I have URLyBird. The thread is about the search requirements on the business side. Part of the requirements state:

"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"


I understand this to mean, String.equals(...) or String.equalsIgnoreCase(...). The code I posted demonstrates the way which appears most intuitive to me. There are probably easier and more efficient ways to do it, but I like the simplicity of the code.

The find method returns an array of integers, so the code will not work as posted, one will still have some fun providing a working implementation.

Regards,
Fola

Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Guys,

It's always a tough call when to say that a thread is getting a little too detailed in this forum... this one is making me a bit uncomfortable, let's back off the details a bit!

Thanks,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Posts: 158
Ethem Yuksel wrote:@Alec, my implementation is as the following. It is working but it really sucks How can i make it simpler?

What I did is very similar to yours, just that I did not provide "OR" functionality (which makes everything much simpler ).
I also used a Filter object instead of plain parameters or the query[] you're using. This makes everything much easier to extend later with new criteria.
You should also break down your code into more methods, to make it easier to understand and manage.
Nicolas Zozol
Ranch Hand

Joined: Oct 13, 2009
Posts: 33
Kevin Florish wrote:



Hi,
This implementation is absolutely logical, but the definition of the find says that search seek the start of the field.


Aren't you afraid to fail with this search ? Should this be an option (and therefore it brings no more points !) ? One point however is that the interface method documentation doesn't say must.


Robusta Web Library : Open Source for REST & Java
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5534
    
  13

Hi Nicolas,

I actually don't see the problem. The comments of the find-method: criteria[n] matches any field value that begins with criteria[n]. And that's what the code of Kevin Florish exactly does! So why would he be afraid to fail? I also used the startsWith-method, just like him.

Kind regards,
Roel

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Nicolas Zozol
Ranch Hand

Joined: Oct 13, 2009
Posts: 33
Roel De Nijs wrote:Hi Nicolas,

I actually don't see the problem. The comments of the find-method: criteria[n] matches any field value that begins with criteria[n]. And that's what the code of Kevin Florish exactly does! So why would he be afraid to fail? I also used the startsWith-method, just like him.

Kind regards,
Roel


Oups, I read too fast Because specilities was separate, I thought it had a special treatment : the one I was discussing of, and working on. Like lot of scientists says, you read what your brain is ready to read....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: search method in business layer