• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

search method in business layer

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ethem Yuksel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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...
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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


 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Fola Fadairo
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Nicolas Zozol
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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....
reply
    Bookmark Topic Watch Topic
  • New Topic