当前页面:
在线文档首页 >
Spring Framework 1.2.9 API 文档英文版
TopLinkInterceptor (Spring Framework) - Spring Framework 1.2.9 API 文档英文版
org.springframework.orm.toplink
Class TopLinkInterceptor
java.lang.Object
org.springframework.orm.toplink.TopLinkAccessor
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:
- 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:
- 1.2
- Author:
- Juergen Hoeller
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TopLinkInterceptor
public TopLinkInterceptor()
invoke
public Object invoke(MethodInvocation methodInvocation)
throws Throwable
- Specified by:
invoke
in interface MethodInterceptor
- Throws:
Throwable
Copyright (c) 2002-2007 The Spring Framework Project.