On Apr 15, 2004, at 8:46 AM, Leonardo Queiroz Antunes wrote:
> Hi everybody!
>
> Which is the best way to retrieve the DataContext inside a Session
> Bean.
>
> Thank´s
> Leonardo Antunes
Hi,
Per our rather primitive EJB example
(http://objectstyle.org/cayenne/examples/ejb-facade/index.html), the
context is created right inside the business method as "DataContext
cayenneContext = DataContext.createDataContext();"
However this might not be a good idea, if you chain a few EJB calls in
the same transaction, and want the same set of data objects shared by
all of them. What you can do instead is implement a simple static
method in one of your utility Java classes, wrapping a DataContext in a
ThreadLocal:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html, and
later use this static method to get the context within a bean.
I will probably add such "thread-local" DataContext method to Cayenne
at some point, for now you'll have to write this yourself.
Andrus
This archive was generated by hypermail 2.0.0 : Thu Apr 15 2004 - 14:31:24 EDT