Hi,
Suggestions by Eric and Sat make sense to me. However I am not sure what
problem Scott is trying to solve.
Scott, could you give an example where you think obtaining a DataContext
in a web application might be a problem? If this is within DAO
(DataObject) itself, DataContext is already "injected", so
dataObject.getDataContext() gives you a context... If you mean some
"static" utility class within the DAO layer, could you arrange all
"static" methods to take DataContext as one of the parameters (that will
be passed from the Session whenever the method is called)? Passing
DataContext to such helpers seems like the most clean solution to me.
I am asking for the details in part cause there are "Spring integration"
discussions poping up every now and then, and I fail to see what extra
integration is needed beyond replacing static Configuration/DataDomain
with a one loaded by Spring. I am really trying to understand whether I'm
missing some scenario or we can claim that Cayenne is "integrated with
Spring" by nature :-)
Thread DataContext... You are right that using a thread-attached
DataContext in a web application is not a good idea. It maybe a good idea
in case of "stateless" worker threads, and I was about to post some code
how to do that, but this is probably not your scenario.
An example of truly stateless multithreaded DB application was something I
worked on last year. This was a system that received and dispatched SMS
messages from/to cell phones. Each thread performed extensive DB access,
as all the dispatch rules and user preferences were stored in DB, however
once the message was dispatched, there was no communication state carried
between the messages (even if they were coming from the same phone). So
threads were stateless, but still could use persistent objects caching...
web applications are different...
Andrus
> In the documentation, the suggested method for retrieving a DataContext
> is to store a DataContext in the HttpSession. While this works well, I
> do not want to pass my HttpSession into the DAO layer of my application,
> since it is not currently part of the DAO interfaces. At the same time,
> I do not want to retrieve a new DataContext for every method call. In
> Spring-Hibernate integration, this problem is solved by tying the
> Hibernate Session to the thread, and calling another SessionUtil class
> to either retrieve a session from the thread or create a new one. I do
> not think this will work as well in Cayenne due to the differences in
> Hibernate Sessions and Cayenne DataContexts. What is the best way to
> deal with this? Basically, the underlying goal is to implement a Cayenne
> DAO that is stateless and has no HttpSession passed in, without causing
> unnecessary overhead with too many DataContexts.
>
> In general, I would be interested to hear how people deal with
> DataContexts in a web application if it is different than the
> one-datacontext-per-session method.
>
> oh, btw, awesome project!
>
> Scott
This archive was generated by hypermail 2.0.0 : Mon Jun 28 2004 - 00:18:11 EDT