All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.litongjava.db.activerecord.tx.TxFun Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
package com.litongjava.db.activerecord.tx;

import java.sql.Connection;
import java.sql.SQLException;

import com.litongjava.jfinal.aop.Invocation;

/**
 * 支持定制事务行为,否则 Tx 拦截器只会在抛出异常时回滚事务
 *
 * 
 * 例如通过返回值 Ret 对象来决定事务的提交与回滚:
 *   Tx.setTxFun((inv, conn) -> {
 *       inv.invoke();
 *
 *       // 根据业务层返回值 Ret 对象的状态决定提交与回滚
 *       Object retValue = inv.getReturnValue();
 *       if (retValue instanceof Ret) {
 *           Ret ret = (Ret)retValue;
 *           if (ret.isOk()) {
 *               conn.commit();
 *           } else {
 *               conn.rollback();
 *           }
 *           return ;
 *       }
 *
 *       // 返回其它类型值的情况
 *       conn.commit();
 *    });
 * 
*/ @FunctionalInterface public interface TxFun { void call(Invocation inv, Connection conn) throws SQLException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy