You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by MG...@escholar.com on 2010/04/26 23:26:21 UTC
Cayenne integration question
Hi,
I'm trying to into integrate Cayenne into a new Click project I'm
working on and I have a few questions. If I have a DataContextFilter from
the extras configured in my web.xml, how does that work with
CayenneTemplate from the extras? It looks like DataContextFilter is
storing the data context in the user's session whereas CayenneTemplate is
storing it thread local. Are they mutually exclusive? Also, I need to
create some utilities that will run outside the web application server,
but will also access the same tables in the DB. Because of this I wanted
to break out my Cayenne DB access stuff into a common library, but if I'm
using CayenneTemplate as the base for my DAO's this won't fly in utility
programs, will it? I looked at the source for CayenneTemplate and didn't
see any "web specific" code in there, but all the stuff from Click is
meant only for web use, no?
Quite a few problems in there I know, but I appreciate the help. :)
Thanks.
-Mike
Re: Cayenne integration question
Posted by Bob Schellink <sa...@gmail.com>.
Hi Mike,
On 27/04/2010 07:26, MGargano@escholar.com wrote:
>
> I'm trying to into integrate Cayenne into a new Click project
> I'm working on and I have a few questions. If I have a
> DataContextFilter from the extras configured in my web.xml, how does
> that work with CayenneTemplate from the extras? It looks like
> DataContextFilter is storing the data context in the user's session
> whereas CayenneTemplate is storing it thread local.
DataContextFilter always binds the DataContext to the current thread, whether request or session
scoped. See this line in DataContextFilter:
// Bind DataContext to the request thread
BaseContext.bindThreadObjectContext(dataContext);
Are they mutually
> exclusive?
Yes, although you might want to customize the CayenneTemplate#getDataContext method for your
specific environment. Binding the dataContext to the current thread is well suited for web
applications where multiple requests are handed off to each thread. For a Swing based application
another strategy might be better suited.
Also, I need to create some utilities that will run outside
> the web application server, but will also access the same tables in the
> DB. Because of this I wanted to break out my Cayenne DB access stuff
> into a common library, but if I'm using CayenneTemplate as the base for
> my DAO's this won't fly in utility programs, will it? I looked at the
> source for CayenneTemplate and didn't see any "web specific" code in
> there, but all the stuff from Click is meant only for web use, no?
I don't see any issue if you include click-extras.jar in a utility program and use CayenneTemplate
as a base for your DAOs. Alternatively you can copy/paste CayenneTemplate into your utility program
and customize it further. You can then include your utility jar inside the web application and use
your custom CayenneTemplate as a base service.
Kind regards
Bob