I think that Maverick should guarantee that discard() method of
ModelLifetime implementing classes get's called whatever happens during
rendering view or executing command.
Here is my modifications to CommandBase class go() method:
/**
* Execute the command and render the results!
*/
public void go(MaverickContext mctx) throws IOException,
ServletException
{
try {
// There must be a controller class to distinguish between views
String viewName = this.controller.go(mctx);
log.info("Switching to view: " + viewName);
View target = (View)this.getView(viewName);
if (null == target)
throw new ServletException("Controller specified view \"" +
viewName + "\", but no view with that name is defined.");
target.go(mctx);
} finally {
// Allow the model to manage resources
if (mctx.getModel() instanceof ModelLifetime)
((ModelLifetime)mctx.getModel()).discard();
}
}
Why I need this? I use hibernate and I also want to use lazy
collections. I open hibernate session in Command execution and leave
connections open. When view is rendered I want to be sure that discard()
method gets called so I can be sure that connections are released to the
pool and hibernate Session gets closed. Without this modification it is
not guaranteed that discard() method get's called (e.g. in case of
exception in view rendering or command execution.
Kind Regards
Aapo Laakkonen
-------------------------------------------------------
This SF.net email is sponsored by: Microsoft Visual Studio.NET
comprehensive development tool, built to increase your
productivity. Try a free online hosted session at:
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr0003en
[INVALID FOOTER]