org.springframework.extensions.jcr.support
Class OpenSessionInViewInterceptor

java.lang.Object
  extended by org.springframework.web.servlet.handler.HandlerInterceptorAdapter
      extended by org.springframework.extensions.jcr.support.OpenSessionInViewInterceptor
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, org.springframework.web.servlet.HandlerInterceptor

public class OpenSessionInViewInterceptor
extends org.springframework.web.servlet.handler.HandlerInterceptorAdapter
implements org.springframework.beans.factory.InitializingBean

Spring web HandlerInterceptor that binds a JCR Session to the thread for the entire processing of the request. Intended for the "Open Session in View" pattern, i.e. to allow for lazy loading in web views despite the original transactions already being completed.

This filter works similar to the AOP JcrInterceptor: It just makes JCR Sessions available via the thread. It is suitable for non-transactional execution but also for middle tier transactions via JcrTransactionManager or JtaTransactionManager. In the latter case, Sessions pre-bound by this filter will automatically be used for the transactions.

In contrast to OpenSessionInViewFilter, this interceptor is set up in a Spring application context and can thus take advantage of bean wiring. It derives from JcrAccessor to inherit common JCR configuration properties.

Author:
Costin Leau, Sergio Bossa, Salvatore Incandela

Field Summary
protected static org.slf4j.Logger LOG
           
static java.lang.String PARTICIPATE_SUFFIX
          Suffix that gets appended to the SessionFactory toString representation for the "participate in existing persistence manager handling" request attribute.
 
Constructor Summary
OpenSessionInViewInterceptor()
           
 
Method Summary
 void afterCompletion(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex)
           
 void afterPropertiesSet()
           
protected  java.lang.String getParticipateAttributeName()
          Return the name of the request attribute that identifies that a request is already filtered.
 SessionFactory getSessionFactory()
          Return the JCR JcrSessionFactory that should be used to create Sessions.
 boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler)
           
 void setSessionFactory(SessionFactory sf)
          Set the JCR JcrSessionFactory that should be used to create Sessions.
 
Methods inherited from class org.springframework.web.servlet.handler.HandlerInterceptorAdapter
postHandle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARTICIPATE_SUFFIX

public static final java.lang.String PARTICIPATE_SUFFIX
Suffix that gets appended to the SessionFactory toString representation for the "participate in existing persistence manager handling" request attribute.

See Also:
getParticipateAttributeName(), Constant Field Values

LOG

protected static final org.slf4j.Logger LOG
Constructor Detail

OpenSessionInViewInterceptor

public OpenSessionInViewInterceptor()
Method Detail

setSessionFactory

public void setSessionFactory(SessionFactory sf)
Set the JCR JcrSessionFactory that should be used to create Sessions.


getSessionFactory

public SessionFactory getSessionFactory()
Return the JCR JcrSessionFactory that should be used to create Sessions.


preHandle

public boolean preHandle(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response,
                         java.lang.Object handler)
                  throws org.springframework.dao.DataAccessException
Specified by:
preHandle in interface org.springframework.web.servlet.HandlerInterceptor
Overrides:
preHandle in class org.springframework.web.servlet.handler.HandlerInterceptorAdapter
Throws:
org.springframework.dao.DataAccessException

afterCompletion

public void afterCompletion(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response,
                            java.lang.Object handler,
                            java.lang.Exception ex)
                     throws org.springframework.dao.DataAccessException
Specified by:
afterCompletion in interface org.springframework.web.servlet.HandlerInterceptor
Overrides:
afterCompletion in class org.springframework.web.servlet.handler.HandlerInterceptorAdapter
Throws:
org.springframework.dao.DataAccessException

getParticipateAttributeName

protected java.lang.String getParticipateAttributeName()
Return the name of the request attribute that identifies that a request is already filtered. Default implementation takes the toString representation of the JcrSessionFactory instance and appends ".FILTERED".

See Also:
PARTICIPATE_SUFFIX

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception
See Also:
InitializingBean.afterPropertiesSet()


Copyright © 2009. All Rights Reserved.