最近写一个测试。要访问BC,但像接口一样,而非是ADF页面layout去访问,一次还可以,如果多次调用刷新,就会出现问题
代码如下
public String getData(String parmas) {
String backQuery="";
AppModuleImpl am=(AppModuleImpl)this.getAM(amDef, config);
JSONObject data;
try {
data = new JSONObject(parmas);
if(data.has("SQDZJ")){
JSONObject resultJson=new JSONObject();
String sqdzj=data.getString("SQDZJ");
ViewObject vo=am.getXkWfzyjbView1();
ViewCriteria vc=vo.createViewCriteria();
ViewCriteriaRow vcr=vc.createViewCriteriaRow();
vcr.setAttribute("Sqdzj", sqdzj);
vc.add(vcr);
vo.applyViewCriteria(vc);
vo.executeQuery();
if(vo.hasNext()){
JSONObject ywtableJson=new JSONObject();
resultJson.put("result", "1");
resultJson.put("info", "已成功查找到此申请单!");
resultJson.put("datas", ywtableJson);
ywtableJson.put("tableName", "XK_WFZYJB");
JSONObject ywRowJson=new JSONObject();
ywtableJson.put("row", ywRowJson);
Row sqdRow=vo.first();
String[] yw_zd={"Sqdzj","Cbzj","Cbdjh","Cbsbh","Ccdjh","Pbh","Mmsi","Imo","Hh","Zwcm","Ywcm","Hhcbzdm","Zdw","Jdw","Ckzzd",
"Zjzgl","Cbzc","Cbxk","Cbxs","Csys","Jzrq","Syrzj","Syr","Syryw","Syrdz","Syrdzyw","Syrlxdh","Jyrzj","Jyr","Jyrdz","Jyrdzyw","Jyrlxdh",
"Zydw","Zydwlxr","Zydwlxdh","Wzmc","Bwmc","Bwdm","Zyqy"};
//需要转化前的
String[] yw_zhq={"Cjgdm","Cqgdm","Cbzldm","Hdhqdm"};
//字典类别
String[] yw_zhlx={"DM_F01_5","DM_F01_15","DM_F01_6","DM_F01_3"};
//需要转化后的
String[] yw_zhh={"CJG","CQG","CBZL","HDHQ"};
//时间类型的
String[] yw_rqsj={"Zykssj","Zywcsj"};
for(String str:yw_zd){
Object ob=sqdRow.getAttribute(str);
if(!CommonUtils.isNull(ob)){
ywRowJson.put(str.toUpperCase(), ob);
}
}
for(String str:yw_rqsj){
Object ob=sqdRow.getAttribute(str);
if(!CommonUtils.isNull(ob)){
ob=ob.toString().substring(0, 16);
ywRowJson.put(str.toUpperCase(), ob);
}
}
for(int i=0;i<yw_zhq.length;i++){
Object ob=sqdRow.getAttribute(yw_zhq[i]);
if(!CommonUtils.isNull(ob)){
ywRowJson.put(yw_zhq[i].toUpperCase(), ob);
String xdm=ob.toString();
ViewObject zd_vo=am.getJcZdmxView1();
ViewCriteria zd_vc=zd_vo.createViewCriteria();
ViewCriteriaRow zd_vcr=zd_vc.createViewCriteriaRow();
ViewCriteriaRow zd_vcr2=zd_vc.createViewCriteriaRow();
zd_vcr2.setConjunction(ViewCriteriaRow.VC_CONJ_AND);
zd_vcr.setAttribute("Zdlxdm", yw_zhlx[i]);
zd_vcr2.setAttribute("Zdxdm", xdm);
zd_vc.add(zd_vcr);
zd_vc.add(zd_vcr2);
zd_vo.applyViewCriteria(zd_vc);
zd_vo.executeQuery();
if(zd_vo.hasNext()){
Row zdRow=zd_vo.first();
String zdmc=zdRow.getAttribute("Zdxmc").toString();
ywRowJson.put(yw_zhh[i], zdmc);
}
}
}
backQuery=resultJson.toString();
}else{
backQuery="{\"result\":\"0\",\"info\":\"无查询记录!\"}";
}
}else{
backQuery="{\"result\":\"0\",\"info\":\"查询失败,请确认参数!\"}";
}
} catch (JSONException e) {
backQuery="{\"result\":\"0\",\"info\":\"查询失败,请确认参数!\"}";
}finally{
Configuration.releaseRootApplicationModule(am, true);
}
return backQuery;
}
就是通过生成AM去调用BC中的数据信息。但是,在MAIN方法中正常,如是用servlet类来访问就会出现很常见的异常
public void someBusinessMethod() throws Exception { ADFContext currentADFContext = null; try { currentADFContext = ADFContext.initADFContext(null, null, null, null); //Your code that access AM and doing business some
//actions go here } finally { ADFContext.resetADFContext(currentADFContext); } }
于是我就在我的调用方法getData(param)外加上
ADFContext currentADFContext = null; try { currentADFContext = ADFContext.initADFContext(null,null, null,null); //Your code that access AM and doing business some
getData(param);
} finally {
ADFContext.resetADFContext(currentADFContext);
}
果然不服重望啊,呵呵,记下以供后参考
外加一参考
http://www.jobinesh.com/2013/04/what-you-may-need-to-know-while-calling.html
http://blog.csdn.net/sbtmbj2010/article/details/38339289