• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Another Q: SFSB and DAO

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys for your replies.
I thought so too.
Debanjana
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sanjay for the explanation.
Debanjana
 
It's a tiny ad. At least, that's what she said.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic