Class TopLinkInterceptor

  extended by org.springframework.orm.toplink.TopLinkAccessor
      extended by org.springframework.orm.toplink.TopLinkInterceptor
All Implemented Interfaces:
Advice, Interceptor, MethodInterceptor, InitializingBean

public class TopLinkInterceptor
extends TopLinkAccessor
implements MethodInterceptor

This interceptor binds a new TopLink 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 Session (e.g. from TopLinkTransactionManager, or from a surrounding TopLink-intercepted method), the interceptor simply takes part in it.

Application code must retrieve a TopLink Session via the SessionFactoryUtils.getSession method, to be able to detect a thread-bound 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 doTopLinkAction() {
   Session session = SessionFactoryUtils.getSession(this.sessionFactory, false);
   try {
   catch (TopLinkException ex) {
     throw SessionFactoryUtils.convertTopLinkAccessException(ex);
Note that the application must care about handling TopLinkExceptions itself, preferably via delegating to the SessionFactoryUtils.convertTopLinkAccessException method that converts them to exceptions that are compatible with the org.springframework.dao exception hierarchy (like TopLinkTemplate does).

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

The drawbacks are:

Juergen Hoeller

Field Summary
Fields inherited from class org.springframework.orm.toplink.TopLinkAccessor
Constructor Summary
Method Summary
 Object invoke(MethodInvocation methodInvocation)
Methods inherited from class org.springframework.orm.toplink.TopLinkAccessor
afterPropertiesSet, convertJdbcAccessException, convertTopLinkAccessException, getJdbcExceptionTranslator, getSessionFactory, setJdbcExceptionTranslator, setSessionFactory
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public TopLinkInterceptor()
Method Detail


public Object invoke(MethodInvocation methodInvocation)
              throws Throwable
Specified by:
invoke in interface MethodInterceptor

Copyright (c) 2002-2007 The Spring Framework Project.