cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ramiro Aparicio <ramiro.apari...@prot-on.com>
Subject Re: ServerRuntime Best Practice? [3.1]
Date Thu, 28 Feb 2013 17:31:55 GMT
Hi Michel,

Here is our template:  https://gist.github.com/frisco82/5058374

We are using a custom filter to bind a context per request.
And then with our template you have auto rollback  with auto rollback on 
errors (without losing exception info)  and deadlock retries for mysql.

Also this template can be used for async task as if there is not context 
bound to thread it just spans one using servlet config (you can change 
it to your needs).

All this working with Spring without problems.

We still haven't found the need to use context per session (indeed that 
caused a lot of problems also for us) or shorted lived context, but in 
that case I would think in using child contexts instead of context.

The template still uses the old semantics of deleteObject/Objects 
becouse it was based on another one I found somewhere for Cayenne 2.X 
but we have been using it for several months and it is a great 
improvement over messing with context in almost every method, before 
this we didn't use the filter (nor Spring IoC but that's antoher story) 
and there were contexts everywhere.

But anyway just try different options until you are sattisfied with one 
Cayenne is really flexible so there is always a workaround to do the 
same thing.

Ramiro

El 28/02/2013 17:12, Michael Gentry escribió:
> Hi Ramiro,
>
> I typically create web applications, so manually binding a single context
> to the thread isn't really an option.  I need to create them on an ad-hoc
> basis for each user, etc.
>
> Thanks,
>
> mrg
>
>
> On Thu, Feb 28, 2013 at 10:28 AM, Ramiro Aparicio <
> ramiro.aparicio@prot-on.com> wrote:
>
>> El 28/02/2013 16:15, John Huss escribió:
>>
>>   If it's a servlet app, then the runtime is created in CayenneFilter and
>>> bound to the thread for each request and you access it via
>>>
>>> WebUtil.getCayenneRuntime(**servletContext);
>>>
>>>
>>> Or you can get a context from the injector if you have bound that to a
>>> thread:
>>>
>>> ObjectContext context =
>>> CayenneRuntime.**getThreadInjector().**getInstance(**
>>> ObjectContextFactory.class
>>> ).createContext();
>>>
>>>
>>> If not a servlet app, then yeah, I'd just store it in a static variable or
>>> application instance.
>>>
>>>
>>>
>>> On Thu, Feb 28, 2013 at 8:43 AM, Michael Gentry <mgentry@masslight.net
>>>> wrote:
>>>   Is there an existing place (class) in 3.1 to stuff a ServerRuntime
>>>> instance
>>>> for global use or is it expected that you'll create a separate class to
>>>> hold a static instance variable of ServerRuntime?
>>>>
>>>> Thanks,
>>>>
>>>> mrg
>>>>
>>>>
>> We avoid storing it as a singleton and use the same concept for non web
>> apps using BaseContext
>> <http://cayenne.apache.org/**docs/3.1/api/org/apache/**
>> cayenne/BaseContext.html<http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/BaseContext.html>
>>> **BaseContext.**bindThreadObjectContext(**context)||
>> context  = BaseContext.**getThreadObjectContext()
>>
>> So you usually just bind the context on startup and don't need to have
>> write your own singleton for that.
>>
>> Indeed we made a DAO Template that works in both scenarios to be able to
>> reuse the dao library.
>>
>>
>>
>>
>>


Mime
View raw message