org.springframework.orm.jdo
Class JdoInterceptor
java.lang.Object
org.springframework.orm.jdo.JdoAccessor
org.springframework.orm.jdo.JdoInterceptor
- All Implemented Interfaces:
- Advice, InitializingBean, Interceptor, MethodInterceptor
- public class JdoInterceptor
- extends JdoAccessor
- implements 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:
- no anonymous classes necessary for callback implementations;
- the possibility to throw any application exceptions from within data access code.
The drawbacks are:
- the dependency on interceptor configuration;
- the delegating try/catch blocks.
- Since:
- 13.06.2003
- Author:
- Juergen Hoeller
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JdoInterceptor
public JdoInterceptor()
invoke
public Object invoke(MethodInvocation methodInvocation)
throws Throwable
- Specified by:
invoke
in interface MethodInterceptor
- Throws:
Throwable
Copyright (C) 2003-2004 The Spring Framework Project.