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 B&S: Searching at the business service layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Searching at the business service layer" Watch "B&S: Searching at the business service layer" New topic
Author

B&S: Searching at the business service layer

Vairoj Arunyaangkul
Greenhorn

Joined: Sep 23, 2006
Posts: 9
I am kind of stuck with the design of providing search service at the business layer to the GUI layer. The search service is the method at the business layer which calls find method in the DB interface and do some filtering to provide result that match the requirements. From my understanding, the returned result is preferrable a collection of value object to decouple GUI from knowing the column number of each fields.

However, what is the type of search criteria as parameter? In my opinion, the criteria should provide flexibility for future extension. Some of the possible extensions are:
- Searching by other fields such as size or rate
- Adding fields to the database

So the criteria should be decoupled from the column index and should not hardcoded to search for a specific field.

How does anyone come up with a design solution that meets these requirements?


[ September 24, 2006: Message edited by: Vairoj Arunyaangkul ]
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Vairoj,

The answer to your question is simple DAO.
Builds a object which warpps your String array and provide some setXXX/getXXX
In thos way you can use the setXXX, getXXX whitout to care about the coresponding fied index.

Regards M


SCJP, SCJD, SCWCD, OCPJBCD
Vairoj Arunyaangkul
Greenhorn

Joined: Sep 23, 2006
Posts: 9
Could you elaborate more on your reply?
If I understand correctly, what you suggested is to wrap the String array with a Transfer Object / Value Object. So in my case the search method would return collection of Contractor object. Is that correct?

However, my question is about the search criteria, how to make the criteria argument of the search method more flexible and more resilient to changes.
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Yes, I think Mihai is refering to DTO.
Vairoj, could you post the provided interface?
Asignments differ quite enough.


SCJP, OCMJD, OCMJEA
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Guys,

Oricio,
I not a pattern expert, to be honest I just read what means DTO, but I still think that here we have to deal with a DAO.
The DTO purpose is to group together some entities and to transport them, all together - but this is not what I mean.
I just try to "provide access to a particular data resource without coupling the resource's API to the business logic".
My let's call it DAO adaptor has (implements) a generic interface, it knows how a record(String array) is builded and it provides access to it. The client only see the adaptor generic interface - he has no information about the record intern structure.

I still think that this is DAO.

What you guys are thinking ?

Regards M.
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Hello Mihai,

My let's call it DAO adaptor has (implements) a generic interface, it knows how a record(String array) is builded and it provides access to it. The client only see the adaptor generic interface - he has no information about the record intern structure.

I think is a Wrapper, since it do not encapsulate access to a data source.
Vairoj Arunyaangkul
Greenhorn

Joined: Sep 23, 2006
Posts: 9
Mihai, I understand your suggestion on the DAO pattern. However, isn't that what DB, the provided interface is acting as?

My DB interface contains lock, unlock and CRUD methods. The find method looks like this:


My question is rather about another class that is layered on top of this interface. The business logic layer, where it provide services to the GUI layer. In this layer, method such as "book", "unbook" or "search" is provided. The search method signature might looks like this:


What I am trying to fill is the argument of the search method. How can I make the method signature supports future enhancement with minimal disruption. For example, if I make the signature looks like this:



The method will have to be modified if I need to add criterias to the search method.


Oricio,
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Vairo,


isn't that what DB, the provided interface is acting as ?


Yes, in a ver simplisitc way a String array follows the described pattern(IMHO an (String) array is more Value object than DAO)


How can I make the method signature supports future enhancement with minimal disruption.


Small tip , take a look at the java.util.Comparator
This is Strategy pattern.
I hope this will help.

Regards M
Vairoj Arunyaangkul
Greenhorn

Joined: Sep 23, 2006
Posts: 9
Mihai,

Thanks for pointing out. However, while I am used to the Comparator interface, I still could not figure out how this Stategy pattern can be applied to this case. Would you mind elaborate more on the subject..?
[ October 04, 2006: Message edited by: Vairoj Arunyaangkul ]
Vairoj Arunyaangkul
Greenhorn

Joined: Sep 23, 2006
Posts: 9
I was thinking about Query Object pattern which is a kind of Interpreter pattern. But I feel it is a bit overkill. Moreover, I would need a schema mapping mechanism in place to be able to use these patterns. I feel a simpler solution should be better.

Any idea?
 
Consider Paul's rocket mass heater.
 
subject: B&S: Searching at the business service layer