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

📄 hibernatetransactioninterceptor.java

📁 spring+acegi编写的网上书城
💻 JAVA
字号:
package net.livebookstore.raw.hibernate;

import org.aopalliance.intercept.*;
import org.apache.commons.logging.*;
import org.hibernate.Transaction;

/**
 * To do hibernate transaction interceptor. This interceptor is another 
 * alternative way to handle transaction if do not use OpenSessionInView 
 * pattern. Not used in livebookstore.
 * 
 * @author xuefeng
 * 
 * #spring.bean id="hibernateTransactionInterceptor"
 * 
 * @deprecated
 */
public class HibernateTransactionInterceptor implements MethodInterceptor {

    private Log log = LogFactory.getLog(getClass());

    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object ret = null;
        Transaction tx = null;
        try {
            log.info("Hibernate transaction forcurrent session: about to begin...");
            tx = HibernateUtil.getCurrentSession().beginTransaction();
            ret = invocation.proceed();
            log.info("Hibernate transaction for current session: about to commit...");
            tx.commit();
        }
        catch(Throwable t) {
            if(tx!=null) {
                log.info("Hibernate transaction for current session: about to rollback...", t);
                tx.rollback();
            }
            throw t;
        }
        return ret;
    }

}

⌨️ 快捷键说明

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