You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Gary Jarrel <ga...@gmail.com> on 2007/01/20 04:24:15 UTC

Best Way to get a DataContext (in this case)

Hi All!

I've got a web app using struts, spring and cayenne. I use a web
application listener to setup the thread bound data context for any
given actions. All database access is abstracted away via a number of
DAOs. For any given action (all managed by spring) the required DAOs
are injected and are able to access the data context as it has been
bound to the thread. All works very well.

Now we've created a number of objects which collect various stats on
the data in the DB. These are executed at various time intervals and
are managed by Spring and the Quartz API. My question is what is the
best practice in providing a data context for these types of objects.
Can't use a listener as no Action is being executed - Spring simply
instantiates the object and executes the specified method. Should I
perhaps go the way described in the Cayenne/Spring example? Seems as
though there is a fair bit of implementation for just a few objects.

Any suggestions would be much appreciated!

Thank you!

- garyj

Re: Best Way to get a DataContext (in this case)

Posted by Gary Jarrel <ga...@gmail.com>.
No the data context does not need to be shared anywhere else! I just
though that perhaps there may be a cleaner solution, but I guess your
suggestion is simple enough and would work for me!

Thank you!

- garyj

On 1/21/07, Michael Gentry <bl...@gmail.com> wrote:
> When your timer goes off and you collect your statistics, do you need
> to share those statistics (the actual DataContext) elsewhere?  If not,
> you could just create a new local DataContext in your timer handler
> methods.
>
> /dev/mrg
>
>
> On 1/19/07, Gary Jarrel <ga...@gmail.com> wrote:
> > Hi All!
> >
> > I've got a web app using struts, spring and cayenne. I use a web
> > application listener to setup the thread bound data context for any
> > given actions. All database access is abstracted away via a number of
> > DAOs. For any given action (all managed by spring) the required DAOs
> > are injected and are able to access the data context as it has been
> > bound to the thread. All works very well.
> >
> > Now we've created a number of objects which collect various stats on
> > the data in the DB. These are executed at various time intervals and
> > are managed by Spring and the Quartz API. My question is what is the
> > best practice in providing a data context for these types of objects.
> > Can't use a listener as no Action is being executed - Spring simply
> > instantiates the object and executes the specified method. Should I
> > perhaps go the way described in the Cayenne/Spring example? Seems as
> > though there is a fair bit of implementation for just a few objects.
> >
> > Any suggestions would be much appreciated!
> >
> > Thank you!
> >
> > - garyj
> >
>

Re: Best Way to get a DataContext (in this case)

Posted by Michael Gentry <bl...@gmail.com>.
When your timer goes off and you collect your statistics, do you need
to share those statistics (the actual DataContext) elsewhere?  If not,
you could just create a new local DataContext in your timer handler
methods.

/dev/mrg


On 1/19/07, Gary Jarrel <ga...@gmail.com> wrote:
> Hi All!
>
> I've got a web app using struts, spring and cayenne. I use a web
> application listener to setup the thread bound data context for any
> given actions. All database access is abstracted away via a number of
> DAOs. For any given action (all managed by spring) the required DAOs
> are injected and are able to access the data context as it has been
> bound to the thread. All works very well.
>
> Now we've created a number of objects which collect various stats on
> the data in the DB. These are executed at various time intervals and
> are managed by Spring and the Quartz API. My question is what is the
> best practice in providing a data context for these types of objects.
> Can't use a listener as no Action is being executed - Spring simply
> instantiates the object and executes the specified method. Should I
> perhaps go the way described in the Cayenne/Spring example? Seems as
> though there is a fair bit of implementation for just a few objects.
>
> Any suggestions would be much appreciated!
>
> Thank you!
>
> - garyj
>