⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transactionadvice.java

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA
字号:
package com.cloudwebsoft.framework.aop.advice;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import com.cloudwebsoft.framework.aop.base.Advice;
import com.cloudwebsoft.framework.db.JdbcTemplate;
import cn.js.fan.util.ErrMsgException;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class TransactionAdvice implements Advice {
    public TransactionAdvice() {
    }

    public void Before(Object proxy, Method method, Object[] args) throws
            Throwable {
        int len = args.length;
        for (int i=0; i<len; i++) {
            if (args[i] instanceof JdbcTemplate) {
                JdbcTemplate jt = (JdbcTemplate)args[i];
                jt.getConnection().beginTrans();
            }
        }
    }

    public void After(Object proxy, Method method, Object[] args) throws
            Throwable {
        int len = args.length;
        for (int i=0; i<len; i++) {
            if (args[i] instanceof JdbcTemplate) {
                JdbcTemplate jt = (JdbcTemplate)args[i];
                jt.getConnection().commit();
            }
        }
    }

    public void Throw(Object proxy, Method method, Object[] args, Exception e) throws
            Throwable {
        throw new ErrMsgException(e.getMessage());
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -