RE: Tapestry and O/R persitence services

Eric Everman <[email protected]> Thu, 16 Jan 2003 21:30:00 -0600
Newsgroups gmane.comp.java.tapestry.devel
Message-ID <[email protected]>
Its seems like the page itself could determine if it needs an isolated 
transaction and get a new Session if appropriate.

I would propose something like this:
-Add EngineListener with serviceBegin/serviceEnd events (as prev. suggested)
-Use a Tapestry Extension as a Hibernate SessionSource
-Only create Sessions when they are requested and commit them when they go 
out of scope
-Provide SessionSource methods that retrieve Sessiosn with request scope or 
page scope.  All methods SessionSource methods returning a Session would 
require a RequestCycle as an argument so that the SessionSource can 
determine the current page or request as appropriate.

A fragment from a page that requires an isolated transaction would look 
like this:

//////////////////////  Code 
Snip   ///////////////////////////////////////////////
SessionSource ss = (SessionSource)
   (getEngine().getSpecification().getExtension("SS"));

Session session = ss.getSinglePageSession(cycle);
//////////////////////  Code 
Snip   ///////////////////////////////////////////////
The session returned above would be committed as soon as the page renders
and would not be shared across pages.  This is how my original
SessionSource extension worked.

Alternatively, if you are certain that the interaction of a particular page
can share a session with other pages that are like minded, you could
as for a request scope session:
//////////////////////  Code 
Snip   ///////////////////////////////////////////////
//In page One
SessionSource ss = (SessionSource)
   (getEngine().getSpecification().getExtension("SS"));

Session session = ss.getSingleRequestSession(cycle);
//Do some work
cycle.setPage("Two");

////Page Break/////

//In page Two
SessionSource ss = (SessionSource)
   (getEngine().getSpecification().getExtension("SS"));

//Returns the same uncommitted session from page one
Session session = ss.getSingleRequestSession(cycle);
//////////////////////  Code 
Snip   ///////////////////////////////////////////////
The session returned above would be committed when the request is
complete and would be shared across pages.

In all cases, the SessionSource does not create a Session until you ask for 
one.

Thoughts?

Eric Everman


At 1/16/2003, Norrman Per wrote:
>I agree. However, one problem is to
>determine which requests that should be transaction
>demarcated. A configuration item?
>
>There could be an EngineListener with serviceBegin/serviceEnd
>methods.
>
>/Per Norrman
>
>-----Original Message-----
>From: Eric Everman
>To: Christian Sell; Neil Clayton
>Cc: Norrman Per; [email protected]
>Sent: 2003-01-17 00:06
>Subject: Re: [Tapestry-developer] Tapestry and O/R persitence services
>
>
>At 1/16/2003, Christian Sell wrote:
> >what about making this a generic hook in the framework proper, for
>anyone
> >who requires transaction demarcation. After all that is not an
> >O/R-specific issue..
>
>
>Yes!  This is really what my previous message was getting at.  It
>doesn't
>need to be a hook for transaction demarcation specifically, but we do
>need
>a hook to mark the beginning and ending of a request, even if it crosses
>
>several pages.
>
>Does this exist and I'm just not seeing it?
>
>Eric Everman
>
>###########################################
>
>This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
>For more information, connect to http://www.F-Secure.com/



-------------------------------------------------------
This SF.NET email is sponsored by: Thawte.com
Understand how to protect your customers personal information by implementing
SSL on your Apache Web Server. Click here to get our FREE Thawte Apache 
Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en