Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another Q: SFSB and DAO

 
Debanjana Dasgupta
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
This is from Whizlabs again.
When would you use the DAO pattern in regards to a Stateful Session Bean?
Ans is : You wdn't use DAO with SFSB Because it is expensive.
My question is
But if you were to do Database read/write , wouldn't it be appropriate to use DAO?
Thanks
Debanjana
 
Rufus BugleWeed
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't entirely agree with whiz labs. One of the purposes of DAO is to uncouple the biz tier from a DB implementation. SFSB to DAO is local references and I don't see a huge performance hit.
What does the rest of the peanut gallery think?
 
Thomas Hofmann
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data access objects (DAO) encapsulate database access code (JDBC, SQLJ, ...). So DAO is appropriate also for SFSB. The usage of DAO doesn't depend on the EJB type u use.
 
Bhagawanlu Durvasula
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Debanjana,
I agree with Rufus, and if you really were to do some DB operations in SFSB, you could use DAO alternatively, but it would not really a performance killer.
Regards
Durvasula
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question has come up before, however I am too lazy to search for that thread...
Possibly, the intention of the Whiz Labs' answer was that one should not be doing database access from within a Stateful Session Bean. In general, that is good advice but I would never make such a blanket statement.
In most cases SFSB is not a good choice for database heavy activities, however there are situations where it is. One thing that makes SFSBs powerful, and therefore a viable choice at times, is their ability to interact with transactions via the SessionSynchronization interface.
To get back to the question at hand, if I were to access a database from a SFSB then I would certainly use DAO to encapsulate that activity. I completely agree with Rufus's assessment of the purpose of DAO.
 
Debanjana Dasgupta
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys for your replies.
I thought so too.
Debanjana
 
Sanjay Raghavan
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Chris says, its not appropriate to say that you would never use SFSB with DAOs. But as Chris also points out, the author meant that from a best practices point of view, rather than a feasibility point.
Although SUN would vouch for SFSB, I have not seen too many EJB implementations where SFSB are even used. They are expensive to maintain.
Also (according to the best practices) you would use DAOs to retrieve data (and possibly update data that is non-concurrent). Could you use a SFSB to manage the retrieval/update, yes you could. But if your app already has a SFSB for managing state, you will probably leverage it from your Session Managers (Stateless beans that interact with DAOs).
Hope this helps.
 
Debanjana Dasgupta
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sanjay for the explanation.
Debanjana
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic