Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.orm.jdo
Class JdoInterceptor

    java.lang.Object
      org.springframework.orm.jdo.JdoAccessor
          org.springframework.orm.jdo.JdoInterceptor

All Implemented Interfaces:
  Advice, Interceptor, MethodInterceptor, InitializingBean

    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 is a pre-bound PersistenceManager (e.g. from JdoTransactionManager, or from a surrounding JDO-intercepted method), the interceptor simply participates in it.

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

     public void doSomeDataAccessAction() {
       PersistenceManager pm = PersistenceManagerFactoryUtils.getPersistenceManager(this.pmf, false);
       ...
     }

Note that this interceptor automatically translates JDOExceptions, via delegating to the `PersistenceManagerFactoryUtils.convertJdoAccessException` method that converts them to exceptions that are compatible with the `org.springframework.dao` exception hierarchy (like JdoTemplate does). This can be turned off if the raw exceptions are preferred.

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 drawback is the dependency on interceptor configuration. However, note that this interceptor is usually not necessary in scenarios where the data access code always executes within transactions. A transaction will always have a thread-bound PersistenceManager in the first place, so adding this interceptor to the configuration just adds value when fine-tuning PersistenceManager settings like the flush mode - or when relying on exception translation.

Since:
  13.06.2003
Author:
  Juergen Hoeller
See Also:
  `PersistenceManagerFactoryUtils.getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)`, `JdoTransactionManager`, `JdoTemplate`

Field Summary

Fields inherited from class org.springframework.orm.jdo.JdoAccessor
`logger`

Constructor Summary
`JdoInterceptor()`

Method Summary
`Object` | `invoke(MethodInvocation methodInvocation)`
`void` | `setExceptionConversionEnabled(boolean exceptionConversionEnabled)` Set whether to convert any JDOException raised to a Spring DataAccessException, compatible with the `org.springframework.dao` exception hierarchy.

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

### setExceptionConversionEnabled

    public void setExceptionConversionEnabled(boolean exceptionConversionEnabled)

  Set whether to convert any JDOException raised to a Spring DataAccessException, compatible with the `org.springframework.dao` exception hierarchy.

  Default is "true". Turn this flag off to let the caller receive raw exceptions as-is, without any wrapping.

  See Also:
    `DataAccessException`

### invoke

    public Object invoke(MethodInvocation methodInvocation)
                  throws Throwable

  Specified by:
    `invoke` in interface `MethodInterceptor`
  Throws:
    `Throwable`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2008 The Spring Framework.