访问oracle中的BC之通过AM,而非ADF

21 篇文章 0 订阅

最近写一个测试。要访问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类来访问就会出现很常见的异常

java.lang.ClassCastException: oracle.jbo.common.DefLocaleContext cannot be cast to oracle.jbo.common.DefLocaleContext
at oracle.jbo.common.DefLocaleContext.getInstance(DefLocaleContext.java:105)
at oracle.jbo.common.JboNameUtil.getLocaleName(JboNameUtil.java:1086)
at oracle.jbo.ViewCriteria.getLocaleName(ViewCriteria.java:4382)
at oracle.jbo.ViewCriteria.resolveResourceProperty(ViewCriteria.java:4403)
at oracle.jbo.ViewCriteria.getProperty(ViewCriteria.java:4551)
at oracle.jbo.ViewCriteria.getProperty(ViewCriteria.java:4561)
at oracle.jbo.common.CommonCriteriaAdapter.doConvertCriteriaItemToWhereFragment(CommonCriteriaAdapter.java:548)
通到度娘和谷哥。知道原因大概如下
别人原话1
Looking at the source code for the two versions, there is a difference in the way that the getLocaleName() method in JboNameUtil is implemented. In Patchset 2 rather than just working out the Local from scratch every time (which is in the scheme of things expensive). The utility picks up a cached copy of the locale information from the request. 
It is this call that is causing a class cast exception.

In your case, because you are bypassing the binding layer and creating the AM explicitly I guess that the setup required to store this cached value is not done.
原话2
The reason is that the current request gets the ADFContext cached by the previous thread. As these threads may have different class loaders, casting class loaded by one loader to the other result in weird ClassCastException. This post contains a solution for such cases. Here you go...
 
后有一高人就指出解决办法如下
 If the technology that you use do not support any interceptors around method  invocation as discussed above, then you can try adding the ADFContext handling code before and after of your custom code that access AM method as listed below:
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
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值