Craig, Thanks for the idea.
Only problem I see with this that I usually make my "real" actions some flavor of a DispatchAction, usually a MappingDispatchAction. So to keep that type of functionality, it appears that I'd have to replicate a lot of the Struts dispatch/reflection logic inside of my abstract Action subclass. Calling super.execute() gets me that, but that is precisely what this concept seems to try to avoid. :-/ > -----Original Message----- :snip: > A useful design pattern for something like this is to create > a common subclass for your actions that does the > setup/teardown work in the > execute() method, and then delegates to the action-specific > work in some other method. For your scenario, it might look > like this: > > public abstract class BaseAction extends Action { > > public ActionForward execute(...) throws Exception { > Persistence persistence = > ActionHelper.getPersistenceObject(request); > try { > ActionForward forward = delegate(mapping, > form, request, response, persistence); > } finally { > persistence.release)(; > } > } > > protected abstract ActionForward > delegate(ActionMapping mapping, ActionForm form, > HttpServletRequest request, HttpServletResponse > response, Persistence persistence) > throws Exception; > > } > > Then, your real business logic is implemented in a delegate() > method that is passed in for you, and you never have to > remember to allocate and release the persistence object. > > public class RealAction extends BaseAction { > > protected ActionForward delegate(...) { > ... use the persistence object as needed ... > } > > } > > This is pretty close to what you've got now ... the key > difference is that it uses a local variable instead of an > instance variable to avoid sharing problems. Also, because > of the finally clause, it also ensures that the persistence > object is cleaned up, even if the > delegate() method throws an exception. > > Craig > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]