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

本文探讨了在使用ADFS访问BC时遇到的ClassCastException问题,并提供了解决方法,包括通过ADFContext处理代码前后,确保缓存的locale信息正确获取。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近写一个测试。要访问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.youkuaiyun.com/sbtmbj2010/article/details/38339289
 

 

 

内容概要:该PPT详细介绍了企业架构设计的方法论,涵盖业务架构、数据架构、应用架构和技术架构四大核心模块。首先分析了企业架构现状,包括业务、数据、应用和技术四大架构的内容和关系,明确了企业架构设计的重要性。接着,阐述了新版企业架构总体框架(CSG-EAF 2.0)的形成过程,强调其融合了传统架构设计(TOGAF)和领域驱动设计(DDD)的优势,以适应数字化转型需求。业务架构部分通过梳理企业级和专业级价值流,细化业务能力、流程和对象,确保业务战略的有效落地。数据架构部分则遵循五大原则,确保数据的准确、一致和高效使用。应用架构方面,提出了分层解耦和服务化的设计原则,以提高灵活性和响应速度。最后,技术架构部分围绕技术框架、组件、平台和部署节点进行了详细设计,确保技术架构的稳定性和扩展性。 适合人群:适用于具有一定企业架构设计经验的IT架构师、项目经理和业务分析师,特别是那些希望深入了解如何将企业架构设计与数字化转型相结合的专业人士。 使用场景及目标:①帮助企业和组织梳理业务流程,优化业务能力,实现战略目标;②指导数据管理和应用开发,确保数据的一致性和应用的高效性;③为技术选型和系统部署提供科学依据,确保技术架构的稳定性和扩展性。 阅读建议:此资源内容详尽,涵盖企业架构设计的各个方面。建议读者在学习过程中,结合实际案例进行理解和实践,重点关注各架构模块之间的关联和协同,以便更好地应用于实际工作中。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值