NC独立事务的使用

1、public 端新建接口,创建方法并将方法名带后缀_RequiresNew,注意这里的下划线是英文状态的下_,并抛出异常

public interface IPrivateUtilMaintain {

/**   
     * @Title executeAction__RequiresNew
     * @Description 执行单据动作(独立事务),private端使用
     * @param actionName
     * @param billtype
     * @param aggVO
     * @return String
     * @throws 
     */ 
    Object executeAction_RequiresNew(String actionName, String billtype, AggregatedValueObject aggVO) throws BusinessException;

}

2、private 创建该接口的实现类,并实现该方法,编写具体的业务逻辑

public class PrivateUtilMaintainImpl implements IPrivateUtilMaintain {

/*
     * 执行单据动作(独立事务)
     */
    @Override
    public Object executeAction_RequiresNew(String actionName, String billtype, AggregatedValueObject aggVO) throws BusinessException {
        return BaseDaoUtil.executeAction(actionName, billtype, aggVO);
    }

}

3、通过调用接口方法实现该方法开启独立事务,使该方法与当前类中的事务分离,可以防止该方法出现异常后导致类中所有的数据库操作全部回滚,这样可以使用 try catch 来捕获异常,使正常的数据操作成功,异常操作可以自己记录日志。

               try {

                    // 实例化接口

    IPrivateUtilMaintain ipu = NCLocator.getInstance().lookup(IPrivateUtilMaintain.class);
                    // 保存
                    ArriveVO[] saveBase = (ArriveVO[]) ipu.executeAction_RequiresNew("SAVEBASE", "23", avo[0]);
                    // 审批
                    ipu.executeAction_RequiresNew("APPROVE", "23", saveBase[0]);
                } catch (Exception e) {

                    // 记录异常日志
                    log.append(e.getMessage() + "\n");
                }

备注:

1)因为是新建接口,所以要新建 upm 配置文件 xxxx.upm,并放在 META-INF 文件夹下

<?xml version='1.0' encoding='UTF-8'?>
<module name="xxxx">
    <public>
        <component remote="true" singleton="true" tx="CMT">
            <interface>nc.itf.dao.IPrivateUtilMaintain</interface>
            <implementation>nc.impl.dao.PrivateUtilMaintainImpl</implementation>
        </component>
    </public>
</module>

2)在打包补丁并部署在服务器时,要用 sysconfig 对该补丁模块进行 EJB 部署

3)因为 client 端是没有事务的,所以独立事务只应用于 private 端

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晓_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值