File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean calling a method from DAO or another bean?

 
trupti nigam
Ranch Hand
Posts: 622
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a MDB which calls the methods that updates or inserts rows to the DB table.
My question is: What is the right way of the method call?
1. Calling method A() directly from DAO
2. Calling method A() from another sessionbean which in turn calls method of DAO?

are there any advantages ,disadvantages in above two approaches?

Thanks in advance,

Trupti
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trupti,
Option 2 makes the code more reusable since you can call it from other (non-mdb) clients as well. Either option provides transaction and security support though.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 1 is better. Why do we need a extra Session bean when a call to DAO will do. Jeanne, Could you please explain why 2 is more reusable. Isn't it a simple call. thanks.
Or I have not understood the question.
[ April 13, 2005: Message edited by: Pradeep Bhat ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
Option 1 is better. Why do we need a extra Session bean when a call to DAO will do.]

Pradeep,
Sometimes a level of indirection is good. There's a quote about any problem being solveable by adding another layer of indirection. (Obviously, this isn't always the case, but its a good quote.) So the session bean isn't inherently good or bad.

Jeanne, Could you please explain why 2 is more reusable. Isn't it a simple call.

Right now the DAO is only called from the MDB. What happens if someone decides that it should be called from a servlet? In that case, it would be good to have a session facade in place to provide the benefits of EJB.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradeep,

Jeanne's explanation was clear. I've a way that could, perhaps, help you understand the reasoning, easier.

Just ask yourself why would you put all the CRUD methods inside a DAO rather than having them as private methods inside the MDB? Then you apply this same reasoning to why you should be using a facade instead of invoking the DAO's method directly inside a MDB.

In short, its all about reuse.

 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now the DAO is only called from the MDB. What happens if someone decides that it should be called from a servlet? In that case, it would be good to have a session facade in place to provide the benefits of EJB.


Yeah Transaction in particualar. I havent worked on EJB's for more that 2.5 years.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic