Live Pool Strategy.

Enterprise Java
Connection Strategies in EntityBeans

Prakash Malani
Listing 4. Live Pool Strategy.


public void setEntityContext (EntityContext aEC) {
    super.setEntityContext(aEC);
    mConnection = ConnectionTemplate.obtainConnection (DATA_SOURCE_NAME);
}

public void unsetEntityContext () {
    super.unsetEntityContext();
    ConnectionTemplate.releaseConnection (mConnection);
}

protected void doCreate () {
    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());
    }
}

About the Author

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