org.apache.cayenne.conf
Class WebApplicationContextProvider

java.lang.Object
  extended by org.apache.cayenne.conf.WebApplicationListener
      extended by org.apache.cayenne.conf.WebApplicationContextProvider
All Implemented Interfaces:
java.util.EventListener, javax.servlet.http.HttpSessionListener, javax.servlet.ServletContextListener, javax.servlet.ServletRequestListener

Deprecated. since 1.2. This class is deprecated to reduce confusion due to multiple redundant choices of web application configuration. 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
extends WebApplicationListener
implements javax.servlet.ServletRequestListener

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.*

Since:
1.1
Author:
Scott McClure

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

WebApplicationContextProvider

public WebApplicationContextProvider()
Deprecated. 
Method Detail

requestInitialized

public void requestInitialized(javax.servlet.ServletRequestEvent sre)
Deprecated. 
Retrieves the DataContext bound earlier to the HttpSession, and binds it to the current thread.

Specified by:
requestInitialized in interface javax.servlet.ServletRequestListener

requestDestroyed

public void requestDestroyed(javax.servlet.ServletRequestEvent sre)
Deprecated. 
Removes the reference to the DataContext from the thread.

Specified by:
requestDestroyed in interface javax.servlet.ServletRequestListener


Copyright © 2001-2006 Apache.org All Rights Reserved.