//service
public class SaleImpl implement ISaleManager, IDAOLayer{
public Account openAccount(int ID){
Connetion conn;
doSth(conn); // connection is not initialized
}
private doSth(Connection conn)throws Exception{
...
}
}
//configure
<component name="Refundment" class="RefundmentImpl">
<aspect pointcut="doSth">transactionInterceptor</aspect>
</component>
<component name="transactionInterceptor"
class="MyTransactionInterceptor"/>
//we just need a extra interceptor
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class MyInterceptor implements MethodInterceptor{
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Connection conn = DriverManager.getConnection(“XXX”); //get connection
try{
methodInvocation.setArguments(conn);
Object result = methodInvocation.proceed();
return result;
} // deal with exception
finally{
...
}
}
}
|