Template Method in Connection Template.

Enterprise Java
Connection Strategies in EntityBeans

Prakash Malani
Listing 2. Template Method in Connection Template.


public final Object invokeMethod (String aDataSourceName) {
     Object aReturn = null;
     try {
         Connection c = obtainConnection (aDataSourceName);
         try {
              aReturn = doMethod (c);
         } finally {
              releaseConnection (c);
         }
     } catch (Exception e) {
         e.printStackTrace();
         throw new EJBException (e.getMessage());
     }
     return aReturn;
 }

About the Author

Prakash Malani is principal engineer at eBuilt Inc., Irvine, CA. Mr. Malani can be contacted at [email protected].