org.springframework.extensions.jcr
Class JcrInterceptor

java.lang.Object
  extended by org.springframework.extensions.jcr.JcrAccessor
      extended by org.springframework.extensions.jcr.JcrInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.InitializingBean

public class JcrInterceptor
extends JcrAccessor
implements org.aopalliance.intercept.MethodInterceptor

This interceptor binds a new Jcr Session to the thread before a method call, closing and removing it afterwards in case of any method outcome. If there already is a pre-bound Jcr Session (e.g. from JcrTransactionManager, or from a surrounding JCR-intercepted method), the interceptor simply participates in it.

Application code must retrieve a JCR Session via the JcrSessionFactoryUtils.getSession method, to be able to detect a thread-bound Jcr Session. It is preferable to use getSession with allowCreate=false, if the code relies on the interceptor to provide proper session handling. Typically, the code will look as follows:

    public void doJcrAction() {
      Session session = JcrSessionFactoryUtils.getSession(this.jsf, false);
      try {
        ...
      }
      catch (RepositoryException ex) {
        throw JcrSessionFactoryUtils.convertJcrAccessException(ex);
      }
    }
 
Note that the application must care about handling RepositoryExceptions itself, preferably via delegating to the JcrSessionFactoryUtils.convertJcrAccessException method that converts them to exceptions that are compatible with the org.springframework.dao exception hierarchy (like JcrTemplate does).

This class can be considered a declarative alternative to JcrTemplate's callback approach. The advantages are:

The drawbacks are:

Author:
Costin Leau, Sergio Bossa, Salvatore Incandela

Constructor Summary
JcrInterceptor()
           
 
Method Summary
 java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation)
           
 
Methods inherited from class org.springframework.extensions.jcr.JcrAccessor
afterPropertiesSet, convertJcrAccessException, convertJcrAccessException, convertJcrAccessException, getSessionFactory, setSessionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JcrInterceptor

public JcrInterceptor()
Method Detail

invoke

public java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation)
                        throws java.lang.Throwable
Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
java.lang.Throwable


Copyright © 2009. All Rights Reserved.