|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.extras.cayenne.DataContextFilter
public class DataContextFilter
Provides a servlet filter which binds DataContext objects to the current request thread and optionally the users HttpSession. This filter will automatically rollback any uncommitted changes at the end of each request.
When the click application is in debug or trace mode this filter will log any uncommitted data objects at the end of each request. For units of work spanning multiple requests, such as a multi-page work flow, it is recommended that you add a separate DataContext to the session for the unit of work.<filter> <filter-name>DataContextFilter</filter-name> <filter-class>org.apache.click.extras.cayenne.DataContextFilter</filter-class> <init-param> <param-name>lifecycle-listener</param-name> <param-value>com.mycorp.service.AuditListener</param-value> </init-param> </filter>
<web-app> <filter> <filter-name>DataContextFilter</filter-name> <filter-class>org.apache.click.extras.cayenne.DataContextFilter</filter-class> </filter> <filter-mapping> <filter-name>DataContextFilter</filter-name> <servlet-name>ClickServlet</servlet-name> </filter-mapping> <servlet> <servlet-name>ClickServlet</servlet-name> <servlet-class>org.apache.click.ClickServlet</servlet-class> .. </web-app>An example data context filter configuration in the web application's /WEB-INF/web.xml file is provided below. This example creates a new DataContext object for each request and does not use the Cayenne shared cache when creating DataContext objects. This configuration is useful when multiple applications are making changes to the database.
<web-app> <filter> <filter-name>DataContextFilter</filter-name> <filter-class>org.apache.click.extras.cayenne.DataContextFilter</filter-class> <init-param> <param-name>session-scope</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>shared-cache</param-name> <param-value>false</param-value> </init-param> </filter> <filter-mapping> <filter-name>DataContextFilter</filter-name> <servlet-name>ClickServlet</servlet-name> </filter-mapping> <servlet> <servlet-name>ClickServlet</servlet-name> <servlet-class>org.apache.click.ClickServlet</servlet-class> .. </web-app>
WebApplicationContextFilter
.
Field Summary | |
---|---|
protected boolean |
autoRollback
Automatically rollback any changes to the DataContext at the end of each request, the default value is true. |
protected org.apache.cayenne.access.DataDomain |
dataDomain
The Cayenne DataDomain. |
protected FilterConfig |
filterConfig
The filter configuration object we are associated with. |
protected LogService |
logger
The Click log service. |
protected boolean |
sessionScope
Maintain user DataContext object in their HttpSession, the default value is false. |
protected Boolean |
sharedCache
Create DataContext objects using the shared cache. |
Constructor Summary | |
---|---|
DataContextFilter()
|
Method Summary | |
---|---|
protected org.apache.cayenne.access.DataContext |
createDataContext()
Return a new DataContext instance using a shared cache if the filter is configured with use-shared-cache, otherwise the DataContext will not use a shared cache. |
void |
destroy()
Destroy the DataContextFilter. |
void |
doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
This filter binds the session DataContext to the current thread, and removes the DataContext from the thread once the chained request has completed. |
protected org.apache.cayenne.access.DataContext |
getDataContext(HttpServletRequest request)
Return a DataContext instance. |
FilterConfig |
getFilterConfig()
Return filter config. |
void |
init(FilterConfig config)
Initialize the shared Cayenne configuration. |
void |
setFilterConfig(FilterConfig filterConfig)
Set filter configuration. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean autoRollback
protected org.apache.cayenne.access.DataDomain dataDomain
protected FilterConfig filterConfig
protected boolean sessionScope
protected Boolean sharedCache
protected LogService logger
Constructor Detail |
---|
public DataContextFilter()
Method Detail |
---|
public void init(FilterConfig config)
init
in interface Filter
config
- the filter configuration
RuntimeException
- if an initialization error occursFilter.init(FilterConfig)
public void destroy()
destroy
in interface Filter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
doFilter
in interface Filter
request
- the servlet requestresponse
- the servlet responsechain
- the filter chain
IOException
- if an I/O error occurs
ServletException
- if a servlet error occurspublic void setFilterConfig(FilterConfig filterConfig)
filterConfig
- the filter configuration objectpublic FilterConfig getFilterConfig()
protected org.apache.cayenne.access.DataContext getDataContext(HttpServletRequest request)
request
- the page request
protected org.apache.cayenne.access.DataContext createDataContext()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |