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.