Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Where to put initialization code for SLSB or MDB? ejbCreate or setXXXContext?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Which is the most appropriate place to put a code that caches a JNDI InitialContext object or a JDBC data source object for SLSB or MDB? Is it setXXXContext() or ejbCreate() method? Pros and cons for each one? (please, for this time forget the ServiceLocator pattern; I just want to know where is the most appropriate place to put initialization code).
Thanks in advance,
Dani Mazzuca
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think ejbCreate() will be appropiate. Since setXXXContext() is called before the ejbCreate(), it is, as of its name, better use for context issues. For caching the JNDI lookup instance, it is better to be done inside ejbCreate().
Nick
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we can do both the ways as everybody know . But It might be more appropriate to do it in the setXXXContext() methods . I remember i read some where in the spec , that we will write code that required for the life time of the bean in setXXContext() methods . But I read that for entity beans . Should be same for session as well as MDB . Any comments?
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setSessionContext(), - as long as you do not call any methods on the Data source object, it is fine...
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say, ejbCreate() method is the right place to have "Initialization code", no matter it is for SLSB, SFSB or MDBs. The reason being, you can do anything you need to from this method, including things you can't do in setSessionContext(). See HFE Page - 195 (point 3).
Hope, this answers your question.
On the way to certification.
 
Dani Mazzuca
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Baskaran,

Originally posted by Baskaran Vengesanam:
I would say, ejbCreate() method is the right place to have "Initialization code", no matter it is for SLSB, SFSB or MDBs. The reason being, you can do anything you need to from this method, including things you can't do in setSessionContext(). See HFE Page - 195 (point 3).
Hope, this answers your question.
On the way to certification.


I also think that it is better to put the code in ejbCreate() method, although I am not sure of that. However, note that HFE page 195 (point 3) is referring to Stateful session beans, especially por the purpose of passing arguments values to the bean. This is not the case for SLSB and MDB.
Dani Mazzuca
 
That new kid is a freak. Show him this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic