Create and Remove Methods in Servicing Instance Strategy.

Enterprise Java
Connection Strategies in EntityBeans

Prakash Malani
Listing 5. Create and Remove Methods in Servicing Instance Strategy.


protected void doCreate () {
    mConnection = ConnectionTemplate.
          obtainConnection(DATA_SOURCE_NAME);
    try {
         ProductDAO aPD = new ProductDAO (mConnection);
         aPD.setUPC(mUPC);
         aPD.setDescription(mDescription);
         aPD.create();
    } catch (SQLException e) {
         e.printStackTrace();
         throw new EJBException ("In ProductEJB: doCreate:\t" + 
          e.getMessage());
    }
}

protected void doRemove () {
    try {
         ProductDAO aPD = new ProductDAO (mConnection);
         aPD.setUPC(mUPC);
         aPD.remove();
    } catch (SQLException e) {
         e.printStackTrace();
         throw new EJBException ("In ProductEJB: doRemove:\t" +
          e.getMessage());
    }
    ConnectionTemplate.releaseConnection(mConnection);
}

About the Author

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