You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Jeremy Quinn <je...@media.demon.co.uk> on 2003/11/04 11:27:03 UTC

Woody: managing persistence sessions

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


Re: Woody: managing persistence sessions

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Jeremy Quinn dijo:
>
> On Tuesday, November 4, 2003, at 11:10 AM, Antonio Gallardo wrote:
>
> Thanks for your feedback, Antonio.
>
>> Hi Jeremy:
>>
>> I use other approach in Flow. Example:
>>
>> function listform(form) {
>>   var factory = cocoon.getComponent(Packages.o.a.c....JdoPMF.ROLE);
>> var bean = new Packages.test.forms.AreasList();
>>   var handler = new Packages.test.forms.AreaHandler();
>>   var criteria = new String (cocoon.request.criteria);
>>
>>   handler.getList(bean, criteria, factory);  // Read from DB
>
> OK, I think I understand your approach ..... AreaHandler.getList and
> AreaHandler.setList open and close the session as required. (?), so
> that the Session is actually closed before Form.showForm is called.

>From your flow code in your first mail. I understand that "session" is a
Hibernate session (line 2) that you get from the factory (line 1):

var factory = cocoon.getComponent (PersistenceFactory.ROLE);
var session = factory.createSession ();

If this is correct this is similar to getting a PersistenManager in OJB.


> Does OJB have a concept similar to Hibernate's 'lazy-initialisation'?

Yep. You can choose if you wish all the resultSet at once or get them as
you  request it.

Also you can define is the Bean will fill all the collections (references
by Foreign Keys - or better called "details" in a "master-detail"
relation). I thought this is "lazy-initialisations", right?

I short OJB support all Hibernate support. I can said this because the
project leader of OJB told that in a recent mail:


> I have not even approached this issue yet, because currently our User
> is not related to any other Tables, but it will be in the future .....

Yes. I am currently at this example (see attached PNG file):

A form that create Roles for users. We have a subform for auth_permisions)
and in each row of subform a a selection list to choose (auth_resources).
Is this the idea?

As we make a step in the application... (BTW, currently very slow because
too many new things - OJB, JDO, Woody, Flow, JXPath .... but it is cool!)
we tought how we can improve the overall. I think it is a nice experience.

BTW, if you ask how I did the diagram. All I will said is: Druid (damn
here is again!).

Currently druid (CVS version) build all the JavaBeans (including Javadocs
for them) and the O/R mapping for OJB. I am sure Drui can do this because
I generated with them the currently database (71 tables with 383 fields).
I thought this will be very boring writing it by hand. Fortunately, druid
did this for me. :-D

All you need to do is:

Choose a target output dir
click some options
generate Java and OJB
and the worse is in the command line you type: ant.
and voila! you have a jar with all your beans + Javadocs of them.

Note: The beans are also JDO enhanced.

It looks very simple, right? ;-)

> Does your AreaHandler clone the persistent properties into your Bean,
> or does it merely make object references?

Currently I am coping them because JDO will clean all the Beans I got from
the Query. And here is when Apache Jarkarta commons-beanutils comes in the
action! We can simply copy beans using:

org.apache.commons.beanutils.PropertyUtils.copyProperties((Object)temp,
(Object)qIter.next());



> AFAIU if you are using
> lazy-initialisation, you would need to clone the values, to make sure
> the SQL calls were made while your session was still open..

Yep.

Best Regards,

Antonio Gallardo


[OT] OJB features and Hibernate....

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Here is a nice description of OJB features from a OJB committer. It
compares it with Hibernate.

http://article.gmane.org/gmane.comp.jakarta.ojb.user/10013

Best Regards,

Antonio Gallardo




Re: Woody: managing persistence sessions

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Tuesday, November 4, 2003, at 11:10 AM, Antonio Gallardo wrote:

Thanks for your feedback, Antonio.

> Hi Jeremy:
>
> I use other approach in Flow. Example:
>
> function listform(form) {
>   var factory = cocoon.getComponent(Packages.o.a.c....JdoPMF.ROLE);
>   var bean = new Packages.test.forms.AreasList();
>   var handler = new Packages.test.forms.AreaHandler();
>   var criteria = new String (cocoon.request.criteria);
>
>   handler.getList(bean, criteria, factory);  // Read from DB

OK, I think I understand your approach ..... AreaHandler.getList and 
AreaHandler.setList open and close the session as required. (?), so 
that the Session is actually closed before Form.showForm is called.

Does OJB have a concept similar to Hibernate's 'lazy-initialisation'?

I have not even approached this issue yet, because currently our User 
is not related to any other Tables, but it will be in the future .....

Does your AreaHandler clone the persistent properties into your Bean, 
or does it merely make object references? AFAIU if you are using 
lazy-initialisation, you would need to clone the values, to make sure 
the SQL calls were made while your session was still open..

>   form.load(bean);
>   form.showForm("list-form-display");
>   form.save(bean);
>
>   handler.setList(bean, criteria, factory); // Store in DB
>   cocoon.releaseComponent(factory);
>   // Show a succes page (end page).
>   success("Administración de Areas",
>           "Actualización de Áreas",
>           "Todos los cambios se procesaron existosamente." +
>           "¿Desea volver a procesar la lista de áreas?",
>           "search");
> }
>
> Instead of open a OJB session inside the flow I call an FormHandler (in
> Java) with the factory as a parameter. Inside the handle I open the OJB
> transaction and close it after it fill the bean with a query.
>
> I don't know if this is the better approach, but it works :-D
>
> We are looking for a more generic solution to almost all the cases.

yes, this would be good ;)

> I hope it would give you more ideas. I will be glad if you share it 
> with
> us. :-D

Thanks for your suggestions!

regards Jeremy


Re: Woody: managing persistence sessions

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hi Jeremy:

I use other approach in Flow. Example:

function listform(form) {
  var factory = cocoon.getComponent(Packages.o.a.c....JdoPMF.ROLE);
  var bean = new Packages.test.forms.AreasList();
  var handler = new Packages.test.forms.AreaHandler();
  var criteria = new String (cocoon.request.criteria);

  handler.getList(bean, criteria, factory);  // Read from DB

  form.load(bean);
  form.showForm("list-form-display");
  form.save(bean);

  handler.setList(bean, criteria, factory); // Store in DB
  cocoon.releaseComponent(factory);
  // Show a succes page (end page).
  success("Administración de Areas",
          "Actualización de Áreas",
          "Todos los cambios se procesaron existosamente." +
          "¿Desea volver a procesar la lista de áreas?",
          "search");
}

Instead of open a OJB session inside the flow I call an FormHandler (in
Java) with the factory as a parameter. Inside the handle I open the OJB
transaction and close it after it fill the bean with a query.

I don't know if this is the better approach, but it works :-D

We are looking for a more generic solution to almost all the cases.

I hope it would give you more ideas. I will be glad if you share it with
us. :-D

Best Regards,

Antonio Gallardo



Re: Woody: managing persistence sessions

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Tuesday, November 4, 2003, at 01:43 PM, Reinhard Poetz wrote:

>
> IIRC catch(break) is must be used as "top-level" statement
> (... but this is only a guess - never tried catch(continue) but
> catch(break)
> works for me.)
>
>

Wow!

Thanks Reinhard, I'll give that a go!!

regards Jeremy


Re: Woody: managing persistence sessions

Posted by Ugo Cei <u....@cbim.it>.
Jeremy Quinn wrote:
> They both work for me too, so does :
> 
> catch (return) {
>     // the page has finished rendering
> }

Would anybody mind summarizing the various uses of "catch" on the Wiki? 
I have a feeling that sooner or later I'm going to use this stuff.

	TIA,

		Ugo


Re: [OT] Using components outside of Cocoon

Posted by Stephen McConnell <mc...@apache.org>.

Steve K wrote:

> Hey folks --
>
> I have developed a few Avalon Components (they all extend 
> AbstractLogEnabled) that I am currently using inside of Cocoon, but I 
> would like to use them in another, much simpler application.  I know 
> the ExcalibirTestCase does a pretty good job at providing a simple 
> environment for the components to run in -- is there a similar wrapper 
> I can use to run the components in another app?  Or do I have to use 
> ECM/Fortress/Merlin to host the components? 


There is a utility in the framework that you can use to set things up.
http://avalon.apache.org/framework/api/org/apache/avalon/framework/container/ContainerUtil.html
Your application would need to include the logic of building the 
artifacts (config, context, service manager, etc.).  If you want to 
avoid coding this sort of information into you application - then an 
embedded container is the alternative approach.

Stephen.

-- 

Stephen J. McConnell
mailto:mcconnell@apache.org




Re: [OT] Using components outside of Cocoon

Posted by Berin Loritsch <bl...@apache.org>.
Steve K wrote:

> Hey folks --
> 
> I have developed a few Avalon Components (they all extend 
> AbstractLogEnabled) that I am currently using inside of Cocoon, but I 
> would like to use them in another, much simpler application.  I know the 
> ExcalibirTestCase does a pretty good job at providing a simple 
> environment for the components to run in -- is there a similar wrapper I 
> can use to run the components in another app?  Or do I have to use 
> ECM/Fortress/Merlin to host the components?

The ExcaliburTestCase is an Avalon base test class.  YOu can continue to
use that to test your components. (although you should feel free to ask
these types of questions on the Avalon Users list as well).

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


[OT] Using components outside of Cocoon

Posted by Steve K <sh...@mm.st>.
Hey folks --

I have developed a few Avalon Components (they all extend 
AbstractLogEnabled) that I am currently using inside of Cocoon, but I 
would like to use them in another, much simpler application.  I know the 
ExcalibirTestCase does a pretty good job at providing a simple 
environment for the components to run in -- is there a similar wrapper I 
can use to run the components in another app?  Or do I have to use 
ECM/Fortress/Merlin to host the components?

cheers,
-steve



Re: Woody: managing persistence sessions

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, November 5, 2003, at 02:45 PM, Antonio Gallardo wrote:

> Hi Jeremy:
>
> Can you explain a little bit? I still does not understand your point.
> Sorry I know it is my fault.

OK, I will try again .... :)

Lets say you have a script that uses continuations (sendPageAndWait is 
called).

Lets also say that you have to do specific things (eg. persistence 
management) just before starting a continuation-cycle (where you want 
to keep sending the form until it has validated), and just after  the 
continuation-cycle is finished.

With no 'continuation-events' you have to place the code before and 
after each function call to sendPageAndWait (or the function that calls 
it like form.sendPage).

If you have several places in your script where sendPageAndWait is 
called, or your scripts call other scripts that do sendPageAndWait, you 
have lots of code duplicated all over the place.

If you use the 'continuation-events' however, you do not need to 
duplicate anything, you stuff just gets called as needed.

The only problem here, is that there is no event that specifies, "the 
continuation-cycle has finished".

There are events that tell you other things like "continue": a 
continuation has resumed , "break": a continuation has started, 
"return": sendPageAndWait has finished rendering the page.


Any clearer?

regards Jeremy

> Jeremy Quinn dijo:
>>
>> On Wednesday, November 5, 2003, at 01:06 PM, Reinhard Poetz wrote:
>>
>>>> I am really impressed with the Cocoon Forms framework!!
>>>> And the continuation-lifecycle 'catch' events work well too!!
>>>> There is one more event that some people could conceivably want ....
>>>> but I do not know if it is possible .... "The Continuation has
>>>> completed".
>>>>
>>>> Many thanks guys!
>>>
>>> Sorry, but I haven't got what you mean with "The Continuation has
>>> completed".
>>> When is this event reached? Can you give a example (maybe using some
>>> code)?
>>
>> This is what I am thinking about:
>>
>> If you take this code snippet here:
>>
>>    . . .
>>     // get the User
>>     form.load (user);
>>     session.close();
>>     form.showForm (formURI);
>>     session = factory.createSession ();
>>     form.save (user);
>>     // save the User
>>    . . .
>>
>> The line "session.close();" in the sample above, could be replaced by
>> this (obviously after the snippet):
>>
>> 	catch (break) {
>> 		session.close();
>> 	}
>>
>> because it will be called just as a continuation is about to start
>>
>> whereas the line "session = factory.createSession ();" does not have 
>> an
>> equivalent handler that would trigger after all continuation handling
>> has completed.
>>
>> do you see what I mean?
>>
>> regards Jerm
>
>
>


Re: Woody: managing persistence sessions

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hi Jeremy:

Can you explain a little bit? I still does not understand your point.
Sorry I know it is my fault.

Best Regards,

Antonio Gallardo

Jeremy Quinn dijo:
>
> On Wednesday, November 5, 2003, at 01:06 PM, Reinhard Poetz wrote:
>
>>> I am really impressed with the Cocoon Forms framework!!
>>> And the continuation-lifecycle 'catch' events work well too!!
>>> There is one more event that some people could conceivably want ....
>>> but I do not know if it is possible .... "The Continuation has
>>> completed".
>>>
>>> Many thanks guys!
>>
>> Sorry, but I haven't got what you mean with "The Continuation has
>> completed".
>> When is this event reached? Can you give a example (maybe using some
>> code)?
>
> This is what I am thinking about:
>
> If you take this code snippet here:
>
>    . . .
>     // get the User
>     form.load (user);
>     session.close();
>     form.showForm (formURI);
>     session = factory.createSession ();
>     form.save (user);
>     // save the User
>    . . .
>
> The line "session.close();" in the sample above, could be replaced by
> this (obviously after the snippet):
>
> 	catch (break) {
> 		session.close();
> 	}
>
> because it will be called just as a continuation is about to start
>
> whereas the line "session = factory.createSession ();" does not have an
> equivalent handler that would trigger after all continuation handling
> has completed.
>
> do you see what I mean?
>
> regards Jerm




Re: Woody: managing persistence sessions

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, November 5, 2003, at 03:23 PM, Reinhard Poetz wrote:

>
> From: Jeremy Quinn
>
>>
>> On Wednesday, November 5, 2003, at 01:06 PM, Reinhard Poetz wrote:
>>
>>>> I am really impressed with the Cocoon Forms framework!!
>>>> And the continuation-lifecycle 'catch' events work well
>> too!! There
>>>> is one more event that some people could conceivably want
>> .... but I
>>>> do not know if it is possible .... "The Continuation has
>> completed".
>>>>
>>>> Many thanks guys!
>>>
>>> Sorry, but I haven't got what you mean with "The Continuation has
>>> completed". When is this event reached? Can you give a
>> example (maybe
>>> using some code)?
>>
>> This is what I am thinking about:
>>
>> If you take this code snippet here:
>>
>>    . . .
>>     // get the User
>>     form.load (user);
>>     session.close();
>>     form.showForm (formURI);
>>     session = factory.createSession ();
>>     form.save (user);
>>     // save the User
>>    . . .
>>
>> The line "session.close();" in the sample above, could be replaced by
>> this (obviously after the snippet):
>>
>> 	catch (break) {
>> 		session.close();
>> 	}
>>
>> because it will be called just as a continuation is about to start
>>
>> whereas the line "session = factory.createSession ();" does
>> not have an
>> equivalent handler that would trigger after all continuation handling
>> has completed.
>
> IIU Sylvain's docs correctly
> (http://wiki.cocoondev.org/Wiki.jsp?page=RhinoWithContinuations)
>
> catch (continue) {
>    session = factory.createSession ();
> }
>
> should do it. Doesn't it work for you (I haven't tried it yet.)?

it works fine .... but I think it has a different meaning .... it is 
when an existing continuation is resumed ... ie. when a Request comes 
back to a continuation-id.

Whereas what I was thinking about is being notifies of when the 
continuation-cycle is complete and the continuation is disposed of.

> If not you'll have to wait for my interceptions implementation 
> (<hint>or
> help me finishing it <hint/> ;-) which would fill this gap.
> Currently I haven't much time doing it (but hopefully things change in
> the next weeks - expect more work on this then).

Cool :)

regards Jeremy


RE: Woody: managing persistence sessions

Posted by Reinhard Poetz <re...@apache.org>.
From: Jeremy Quinn

> 
> On Wednesday, November 5, 2003, at 01:06 PM, Reinhard Poetz wrote:
> 
> >> I am really impressed with the Cocoon Forms framework!!
> >> And the continuation-lifecycle 'catch' events work well 
> too!! There 
> >> is one more event that some people could conceivably want 
> .... but I 
> >> do not know if it is possible .... "The Continuation has 
> completed".
> >>
> >> Many thanks guys!
> >
> > Sorry, but I haven't got what you mean with "The Continuation has 
> > completed". When is this event reached? Can you give a 
> example (maybe 
> > using some code)?
> 
> This is what I am thinking about:
> 
> If you take this code snippet here:
> 
>    . . .
>     // get the User
>     form.load (user);
>     session.close();
>     form.showForm (formURI);
>     session = factory.createSession ();
>     form.save (user);
>     // save the User
>    . . .
> 
> The line "session.close();" in the sample above, could be replaced by 
> this (obviously after the snippet):
> 
> 	catch (break) {
> 		session.close();
> 	}
> 
> because it will be called just as a continuation is about to start
> 
> whereas the line "session = factory.createSession ();" does 
> not have an 
> equivalent handler that would trigger after all continuation handling 
> has completed.

IIU Sylvain's docs correctly
(http://wiki.cocoondev.org/Wiki.jsp?page=RhinoWithContinuations) 

catch (continue) {
   session = factory.createSession ();
}

should do it. Doesn't it work for you (I haven't tried it yet.)?

If not you'll have to wait for my interceptions implementation (<hint>or
help me finishing it <hint/> ;-) which would fill this gap.
Currently I haven't much time doing it (but hopefully things change in
the next weeks - expect more work on this then).

--
Reinhard


Re: Woody: managing persistence sessions

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, November 5, 2003, at 01:06 PM, Reinhard Poetz wrote:

>> I am really impressed with the Cocoon Forms framework!!
>> And the continuation-lifecycle 'catch' events work well too!!
>> There is one more event that some people could conceivably want ....
>> but I do not know if it is possible .... "The Continuation has
>> completed".
>>
>> Many thanks guys!
>
> Sorry, but I haven't got what you mean with "The Continuation has
> completed".
> When is this event reached? Can you give a example (maybe using some
> code)?

This is what I am thinking about:

If you take this code snippet here:

   . . .
    // get the User
    form.load (user);
    session.close();
    form.showForm (formURI);
    session = factory.createSession ();
    form.save (user);
    // save the User
   . . .

The line "session.close();" in the sample above, could be replaced by 
this (obviously after the snippet):

	catch (break) {
		session.close();
	}

because it will be called just as a continuation is about to start

whereas the line "session = factory.createSession ();" does not have an 
equivalent handler that would trigger after all continuation handling 
has completed.

do you see what I mean?

regards Jerm


RE: Woody: managing persistence sessions

Posted by Reinhard Poetz <re...@apache.org>.
> I am really impressed with the Cocoon Forms framework!!
> And the continuation-lifecycle 'catch' events work well too!! 
> There is one more event that some people could conceivably want .... 
> but I do not know if it is possible .... "The Continuation has 
> completed".
> 
> Many thanks guys!

Sorry, but I haven't got what you mean with "The Continuation has
completed". 
When is this event reached? Can you give a example (maybe using some
code)?

Cheers,
Reinhard


Re: Woody: managing persistence sessions

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Wednesday, November 5, 2003, at 12:02 PM, Reinhard Poetz wrote:

>
> From: Jeremy Quinn
>
>> On Tuesday, November 4, 2003, at 01:43 PM, Reinhard Poetz wrote:
>>
>>>    catch (break) {
>>          //   a continuation has been started
>>>    }
>>>    catch (continue) {
>>          //   a continuation has been resumed
>>>    }
>>> }
>>>
>>> IIRC catch(break) is must be used as "top-level" statement
>>
>> I think this is why they did not work before
>>
>>> (... but this is only a guess - never tried catch(continue) but
>>> catch(break)
>>> works for me.)
>>
>> They both work for me too, so does :
>>
>> catch (return) {
>> 	// the page has finished rendering
>> }
>>
>> So I have very fine-grained control over the session management :)
>>
>> What I am not sure about now, is whether the values of widgets on the
>> Form are bound to the Bean via object references, or if they are
>> independent copies.
>>
>> If they are copies, and the Bean does not get touched during the
>> SendPageAndWait/Validate cycle then all one should need to do
>> to manage
>> the HibernateSession is this:
>>
>>   . . .
>>    // get the User
>>    form.load (user);
>>    session.close();
>>    form.showForm (formURI);
>>    session = factory.createSession ();
>>    form.save (user);
>>    // save the User
>>   . . .
>>
>> If I need to make a 'browser' of 'lazy-initialised'
>> relationships then
>> I would be using JXTemplate rather than Woody, with a dynamic model,
>> and I still have enough control to manage the Session with these
>> call-back handlers. Excellent!
>>
>> Thanks for your help.
>
>
> Cocoon Forms Widgets (aka Woody Widgets) have their own values. If you
> do "form.load(myBean)" the values are read out from the bean (--> 
> copies
> - no references). If you are finished with data collecting you can 
> write
> them back using "form.save(myBean)"

Thanks for the clarification.

I am really impressed with the Cocoon Forms framework!!
And the continuation-lifecycle 'catch' events work well too!!
There is one more event that some people could conceivably want .... 
but I do not know if it is possible .... "The Continuation has 
completed".

Many thanks guys!

regards Jeremy


RE: Woody: managing persistence sessions

Posted by Reinhard Poetz <re...@apache.org>.
From: Jeremy Quinn

> On Tuesday, November 4, 2003, at 01:43 PM, Reinhard Poetz wrote:
> 
> >    catch (break) {
>          //   a continuation has been started
> >    }
> >    catch (continue) {
>          //   a continuation has been resumed
> >    }
> > }
> >
> > IIRC catch(break) is must be used as "top-level" statement
> 
> I think this is why they did not work before
> 
> > (... but this is only a guess - never tried catch(continue) but
> > catch(break)
> > works for me.)
> 
> They both work for me too, so does :
> 
> catch (return) {
> 	// the page has finished rendering
> }
> 
> So I have very fine-grained control over the session management :)
> 
> What I am not sure about now, is whether the values of widgets on the 
> Form are bound to the Bean via object references, or if they are 
> independent copies.
>
> If they are copies, and the Bean does not get touched during the 
> SendPageAndWait/Validate cycle then all one should need to do 
> to manage 
> the HibernateSession is this:
> 
>   . . .
>    // get the User
>    form.load (user);
>    session.close();
>    form.showForm (formURI);
>    session = factory.createSession ();
>    form.save (user);
>    // save the User
>   . . .
> 
> If I need to make a 'browser' of 'lazy-initialised' 
> relationships then 
> I would be using JXTemplate rather than Woody, with a dynamic model, 
> and I still have enough control to manage the Session with these 
> call-back handlers. Excellent!
> 
> Thanks for your help.


Cocoon Forms Widgets (aka Woody Widgets) have their own values. If you
do "form.load(myBean)" the values are read out from the bean (--> copies
- no references). If you are finished with data collecting you can write
them back using "form.save(myBean)"

Cheers,
Reinhard


Re: Woody: managing persistence sessions

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On Tuesday, November 4, 2003, at 01:43 PM, Reinhard Poetz wrote:

>    catch (break) {
         //   a continuation has been started
>    }
>    catch (continue) {
         //   a continuation has been resumed
>    }
> }
>
> IIRC catch(break) is must be used as "top-level" statement

I think this is why they did not work before

> (... but this is only a guess - never tried catch(continue) but
> catch(break)
> works for me.)

They both work for me too, so does :

catch (return) {
	// the page has finished rendering
}

So I have very fine-grained control over the session management :)

What I am not sure about now, is whether the values of widgets on the 
Form are bound to the Bean via object references, or if they are 
independent copies.

If they are copies, and the Bean does not get touched during the 
SendPageAndWait/Validate cycle then all one should need to do to manage 
the HibernateSession is this:

  . . .
   // get the User
   form.load (user);
   session.close();
   form.showForm (formURI);
   session = factory.createSession ();
   form.save (user);
   // save the User
  . . .

If I need to make a 'browser' of 'lazy-initialised' relationships then 
I would be using JXTemplate rather than Woody, with a dynamic model, 
and I still have enough control to manage the Session with these 
call-back handlers. Excellent!

Thanks for your help.

regards Jeremy


RE: Woody: managing persistence sessions

Posted by Reinhard Poetz <re...@apache.org>.
From: Jeremy Quinn

> 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.

Hi Jeremy,

Try it this way:

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;
       } finally {                     // dispose of components
         session.close();
         cocoon.releaseComponent(factory);
       }
     } // end while
   } else {
     cocoon.sendPage("screen/error", 
       {
        message: "Unable to retreive your user information"
       }
      );
   }

   catch (break) {
     session.close();
   } 
   catch (continue) {
     session.reconnect(); 
   } 


}

IIRC catch(break) is must be used as "top-level" statement
(... but this is only a guess - never tried catch(continue) but
catch(break) 
works for me.)

Cheers,
Reinhard