cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <jer...@media.demon.co.uk>
Subject Woody: managing persistence sessions
Date Tue, 04 Nov 2003 10:27:03 GMT
Dear All,

I am using Woody (for the first time), with Hibernate, to edit Beans.
Below is my first stab at a function for updating one of my Beans (a 
User Bean).

The issue you may be able to offer advice on is this:

How can I manage my HibernateSession, while using the Woody Framework?

HibernateSessions need to be closed before a SendPageAndWait sends 
response, and re-opened on the returning Request. In the past I have 
handled this successfully via a ServletFilter, though I was led to 
understand at the time that this is not DIR [1].

Christopher kindly added two special 'catch' handlers to implement 
this, catch (break) and catch (continue), see 
<http://wiki.cocoondev.org/Wiki.jsp?page=RhinoWithContinuations>.

Unfortunately I do not think I understand their usage (see below) and 
had to comment them out, as the function does not compile with them in. 
Depending on whether I place them before or after the catch (e), I get 
different compile errors.

function updateUser (form) {
   var factory = cocoon.getComponent (PersistenceFactory.ROLE);
   var session = factory.createSession ();
   var userid = cocoon.parameters["userid"];
   var successURI = cocoon.parameters["successURI"];
   var formURI = cocoon.parameters["formURI"];
   var user = UserPeer.load (session, userid);

   if (user != null) {
     while (true) {
       try {
         form.load (user);
         form.showForm (formURI);
         form.save (user);
         var id = UserPeer.save (session, user);
         if (id != null) {
           cocoon.sendPage (successURI, { bean: user });
           break;
         } else {
           // get woody to report the error on the form
         }
       } catch (e) {
         cocoon.log.error (e);
         cocoon.sendPage("screen/error", {message: e});
         break;
//   } catch (break) {           // close the connection
//     session.close();
//   } catch (continue) {      // re-open the connection
//     session.reconnect();
       } finally {                     // dispose of components
         session.close();
         cocoon.releaseComponent(factory);
       }
     } // end while
   } else {
     cocoon.sendPage("screen/error", {message: "Unable to retreive your 
user information"});
   }
}

So while this script works .... I cannot deploy it because the 
HibernateSession will be held open during user think-time, which is 
something that is not recommended. I do not know if OJB suffers from 
this issue .... but it would be nice to come up with a generic solution.

So my question is two-fold ....

How do you take advantage of the support Christopher has added; to call 
code just after a SendPageAndWait has finished rendering its pipeline, 
and just before the request is returned.

And, as I assume this handling needs to be 'closer' to the actual call 
to SendPageAndWait, how would this be integrated into the woody 
framework?

Many thanks for any suggestions.

regards Jeremy


[1] DIR = Doing It Right


Mime
View raw message