@@ -0,0 +1,1202 @@
+package org.nutz.aop.interceptor;%0D%0A%0D%0Aimport java.lang.reflect.Method;%0D%0Aimport java.sql.Connection;%0D%0A%0D%0Aimport org.nutz.aop.AbstractMethodInterceptor;%0D%0Aimport org.nutz.lang.Lang;%0D%0Aimport org.nutz.trans.Atom;%0D%0Aimport org.nutz.trans.Trans;%0D%0A%0D%0A/**%0D%0A * %E5%8F%AF%E4%BB%A5%E6%8F%92%E5%85%A5%E4%BA%8B%E5%8A%A1%E7%9A%84%E6%8B%A6%E6%88%AA%E5%99%A8%0D%0A * %3Cp/%3E %E9%BB%98%E8%AE%A4%E4%BA%8B%E5%8A%A1%E7%99%BB%E8%AE%B0%E4%B8%BA Connection.TRANSACTION_READ_COMMITTED%0D%0A * %3Cp/%3E %E5%8F%AF%E4%BB%A5%E5%9C%A8%E6%9E%84%E5%BB%BA%E6%8B%A6%E6%88%AA%E5%99%A8%E6%97%B6%E8%AE%BE%E7%BD%AE%0D%0A * %0D%0A * @author wendal(wendal1985@gmail.com)%0D%0A * %0D%0A */%0D%0Apublic class TransactionInterceptor extends AbstractMethodInterceptor %7B%0D%0A%0D%0A%09private int level;%0D%0A%0D%0A%09public TransactionInterceptor() %7B%0D%0A%09%09this.level = Connection.TRANSACTION_READ_COMMITTED;%0D%0A%09%7D%0D%0A%0D%0A%09public TransactionInterceptor(int level) %7B%0D%0A%09%09this.level = level;%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public boolean beforeInvoke(Object obj, Method method, Object... args) %7B%0D%0A%09%09return false;%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public Object afterInvoke(%09final Object obj,%0D%0A%09%09%09%09%09%09%09%09Object returnObj,%0D%0A%09%09%09%09%09%09%09%09final Method method,%0D%0A%09%09%09%09%09%09%09%09final Object... args) %7B%0D%0A%09%09final Object%5B%5D returnValue = new Object%5B1%5D;%0D%0A%09%09Trans.exec(level, new Atom() %7B%0D%0A%09%09%09public void run() %7B%0D%0A%09%09%09%09try %7B%0D%0A%09%09%09%09%09returnValue%5B0%5D = method.invoke(obj, args);%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%09catch (Throwable e) %7B%0D%0A%09%09%09%09%09throw Lang.wrapThrow(e);%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%7D);%0D%0A%09%09return returnValue%5B0%5D;%0D%0A%09%7D%0D%0A%7D%0D%0A

添加一个 可以插入事务的拦截器