org.springframework.orm.jdo
Class JdoInterceptor

java.lang.Object
  extended byorg.springframework.orm.jdo.JdoAccessor
      extended byorg.springframework.orm.jdo.JdoInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, InitializingBean, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor

public class JdoInterceptor
extends JdoAccessor
implements org.aopalliance.intercept.MethodInterceptor

This interceptor binds a new JDO PersistenceManager to the thread before a method call, closing and removing it afterwards in case of any method outcome. If there already was a pre-bound PersistenceManager (e.g. from JdoTransactionManager, or from a surrounding JDO-intercepted method), the interceptor simply takes part in it.

Application code must retrieve a JDO PersistenceManager via PersistenceManagerFactoryUtils' getPersistenceManager method, to be able to detect a thread-bound PersistenceManager. It is preferable to use getPersistenceManager with allowCreate=false, as the code relies on the interceptor to provide proper PersistenceManager handling. Typically the code will look as follows:

public void doJdoAction() {
  PersistenceManager pm = PersistenceManagerFactoryUtils.getPersistenceManager(this.pmf, false);
  try {
    ...
  }
  catch (JDOException ex) {
    throw PersistenceManagerFactoryUtils.convertJdoAccessException(ex);
  }
}

Note that the application must care about handling JDOExceptions itself, preferably via delegating to PersistenceManagerFactoryUtils' convertJdoAccessException that converts them to ones that are compatible with the org.springframework.dao exception hierarchy (jlike JdoTemplate does). As JDOExceptions are unchecked, they can simply get thrown too, sacrificing generic DAO abstraction in terms of exceptions though.

This interceptor could convert unchecked JDOExceptions to unchecked dao ones on-the-fly. The intercepted method wouldn't have to throw any special checked exceptions to be able to achieve this. Nevertheless, such a mechanism would effectively break the contract of the intercepted method (runtime exceptions can be considered part of the contract too), therefore it isn't supported.

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

The drawbacks are:

Since:
13.06.2003
Author:
Juergen Hoeller

Field Summary
 
Fields inherited from class org.springframework.orm.jdo.JdoAccessor
logger
 
Constructor Summary
JdoInterceptor()
           
 
Method Summary
 java.lang.Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation)
           
 
Methods inherited from class org.springframework.orm.jdo.JdoAccessor
afterPropertiesSet, convertJdoAccessException, flushIfNecessary, getJdoDialect, getPersistenceManagerFactory, isFlushEager, setFlushEager, setJdoDialect, setPersistenceManagerFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdoInterceptor

public JdoInterceptor()
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 (C) 2003-2004 The Spring Framework Project.