• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Review of my first Session EJB bean for best practice

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Please review the EJB 3.1 Session bean for best practice and taking advantage of interceptors. This session bean will be called by the JSF managed bean. I am having the following questions
1) Where do I place the dmd object so that it can be used by both getTables() and getColumns() business methods?
2) How can I use the interceptors for cross cutting code like logging?
3) What other parts of the code can be improved like exception handling, lifecycle callback methods etc?



Thanks in advance
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

thomas jacob wrote:Hi All,
Please review the EJB 3.1 Session bean for best practice and taking advantage of interceptors. This session bean will be called by the JSF managed bean. I am having the following questions
1) Where do I place the dmd object so that it can be used by both getTables() and getColumns() business methods?




I would remove that Connection instance variable and instead create and close a connection wherever required, like in the getTables method.

As for where to store the "dmd" (DatabaseMetaData), it's really upto your requirements. Do you want to query the DatabaseMetaData on every call to the getTables() or do you want the getTables() to return a cached instance? If you want to return a cached instance, then I guess you can make that MetaDataBean a @Singleton and then store the DatabaseMetaData after the first call to the getTables().

thomas jacob wrote:
2) How can I use the interceptors for cross cutting code like logging?



Well, you can use interceptors. But again it depends on the kind of log messages you want to output. Each bean and each business method in that bean will practically have to write out various (specific) log messages and not necessarily just at entry and/or exit. In such cases, having an interceptor wouldn't help much.

As for exception handling - just printing out the exception stacktrace isn't really a good idea, in a practical application. Most of the times, you have to throw back an ApplicationException or a system exception so that the client and the container know what to do with it.
reply
    Bookmark Topic Watch Topic
  • New Topic