cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Best practices for using Cayenne's ObjectContext in a web framework?
Date Sun, 23 Sep 2007 17:41:10 GMT
>  I generally use a new DataContext per thread, with a Filter  
> binding the DataContext to request thread.

I think at some point we should update the docs for 3.0 with  
information discussing 3 main patterns with all drawbacks and  
benefits. Here is a short summary:

* OC per request

   - no synchronization issues, smallest memory footprint
   - some overhead in creating a new DataContext on every request
   - no "local" caching (can be good or bad depending on the app)
   - no uncommitted state is allowed between requests

* OC per session:

   - Potential synchronization issues on update (if the same user  
clicks too fast). Possible solution - nested DataContexts per  
request  working off of a single session context. Another solution is  
synchronization of action methods.
   - efficient local cache
   - uncommitted state can be preserved between requests

  OC per app

   - applicable for read-only applications (no special  
synchronization required in this case)
   - very efficient local cache

Andrus


On Sep 23, 2007, at 2:09 PM, Malcolm Edgar wrote:
> Hi Florin,
>
> I generally use a new DataContext per thread, with a Filter binding  
> the DataContext to request thread.  Please see the attached example.
>
> regards Malcolm Edgar
> http://click.sourceforge.net
>
> On 9/23/07, Florin T.PATRASCU <florin.patrascu@gmail.com> wrote: Hi  
> there,
>
> I am trying to add Cayenne support to the JPublish web framework
> ( http://code.google.com/p/jpublish/) and being very new to Cayenne I
> would like, if possible, to find which is the best practice for
> obtaining and using the OC?
>
> I browsed the threads here and most of the information I have show
> that one of the most common solution is to use the HttpSession.
> That's clear and I can do that very easy, but I wonder if there is a
> better way because I would like to use Cayenne for session-less
> requests as well. So, would it be prohibitive to create an OC for
> every HttpRequest? aka:
>
> ObjectContext oc = DataContext.createDataContext();
>
> If not, would this pattern affect the server stability (memory,
> handlers, threads, db pools, etc.)? What about having a global OC
> instance per application?
>
> Also, is it safe to start developing on top of the Cayenne 3.x  
> version?
>
> Being my first post on this forum, I would like to thank Cayenne's
> creators for making it available and to you, the users, for the
> useful information accumulated in this forum during the time.
>
> Thank you,
> -florin


Mime
View raw message