E9代码使用事务
注意代码里有两行update语句
第一行是文本值,可以修改。
第二行fpsl 是数字,改为文本的话会报错。
提交事务,最终效果两行都没有改变。证明事务回滚成功。
package com.test; import com.engine.sunnypol.util.SapRfc; import org.apache.http.client.config.RequestConfig; import org.springframework.transaction.annotation.Transactional; import weaver.conn.RecordSet; import weaver.conn.RecordSetTrans; import weaver.general.BaseBean; import weaver.interfaces.workflow.action.Action; import weaver.soa.workflow.request.MainTableInfo; import weaver.soa.workflow.request.Property; import weaver.soa.workflow.request.RequestInfo; import java.util.*; public class ActionTest extends BaseBean implements Action { public String execute(RequestInfo request) { /* * Process custom interface code example * * 1:Log * writeLog("in my online edited action"); * * 2:Exception * boolean error=true; * if(error) { * request.getRequestManager().setMessageid("90001"); * request.getRequestManager().setMessagecontent("System Abnormal Termination Process Submission!"); * } * * 3:Get requestid * String requestId = request.getRequestid(); * * 4:Get form tableName * String tablename = request.getRequestManager().getBillTableName(); * * 5:Find form content * RecordSet rs = new RecordSet(); * rs.execute("select * from "+tablename+" where requestid = "+requestId); * rs.next(); * String mainid = rs.getString("id"); //id:Form primary key * String formData = rs.getString("formData"); //formData:Field name for form design * * */ String requestId = request.getRequestid(); String tablename = request.getRequestManager().getBillTableName(); RecordSetTrans recordSetTrans = new RecordSetTrans(); recordSetTrans.setAutoCommit(false); try { recordSetTrans.executeSql("update formtable_main_291_dt1 set wlbm = '123' where id = 10"); recordSetTrans.executeSql("update formtable_main_291_dt1 set fpsl = 'zhuangjun' where id = 11"); recordSetTrans.commit(); }catch (Exception e){ recordSetTrans.rollback(); request.getRequestManager().setMessageid("90001"); request.getRequestManager().setMessagecontent("系统业务处理失败或者网络问题,请稍后重试!错误信息:"+e.getMessage()); return Action.FAILURE_AND_CONTINUE; }finally { } return Action.SUCCESS; } private void test() { RecordSet rs = new RecordSet(); rs.execute("update formtable_main_291_dt1 set wlbm = '45645623311' where id = 10"); rs.execute("update formtable_main_291_dt1 set wlbm = '78978923311' where id = 11"); // throw new Exception("test"); throw new RuntimeException("test"); } }