|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.cayenne.conf.WebApplicationListener
org.apache.cayenne.conf.WebApplicationContextProvider
WebApplicationContextFilter
is the
official configuration choice for Cayenne, however you can still use a
custom listener similar to WebApplicationContextProvider if you want to.
public class WebApplicationContextProvider
WebApplicationContextProvider is a helper class integrating Cayenne with web applications. It performs two related operations - (1) whenever an HttpSession is started, it creates a new instance of DataContext and sets it as a session attribute; (2) whenever a new request comes in for the session, it retrieves previously stored session DataContext and binds it to the request worker thread for the duration of the request. This way any class can get access to the correct instance of DataContext without knowing anything about the servlet environment. This is useful for decoupling the controller layer (Servlets, Struts, etc.) from a DAO layer, making public DAO API independent from DataContext.
Installation in the web container: WebApplicationContextProvider should be
installed as a listener, similar to the WebApplicationListener). Per servlet
specification, listener is configured in web.xml
deployment descriptor:
<listener> <listener-class>org.apache.cayenne.conf.WebApplicationContextProvider</listener-class> </listener>
Accessing thread DataContext: A DataContext bound to a worker thread can be
retrieved for the duration of the request processing by calling the static method
DataContext.getThreadDataContext()
.
Upgrading from WebApplicationListener
: WebApplicationContextProvider
supersedes WebApplicationListener. WebApplicationContextProvider relies on
ServletRequestListener API that is a part of Servlet Specification since version 2.4.
Therefore it requires a container that supports 2.4 spec, e.g. Tomcat 5.*
Constructor Summary | |
---|---|
WebApplicationContextProvider()
Deprecated. |
Method Summary | |
---|---|
void |
requestDestroyed(javax.servlet.ServletRequestEvent sre)
Deprecated. Removes the reference to the DataContext from the thread. |
void |
requestInitialized(javax.servlet.ServletRequestEvent sre)
Deprecated. Retrieves the DataContext bound earlier to the HttpSession, and binds it to the current thread. |
Methods inherited from class org.apache.cayenne.conf.WebApplicationListener |
---|
contextDestroyed, contextInitialized, getConfiguration, newConfiguration, sessionCreated, sessionDestroyed, setConfiguration |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WebApplicationContextProvider()
Method Detail |
---|
public void requestInitialized(javax.servlet.ServletRequestEvent sre)
requestInitialized
in interface javax.servlet.ServletRequestListener
public void requestDestroyed(javax.servlet.ServletRequestEvent sre)
requestDestroyed
in interface javax.servlet.ServletRequestListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |