OAF中关于实体专家类的简单理解

来源:互联网 发布:钓鱼生成软件下载 编辑:程序博客网 时间:2024/06/05 20:31

为什么要使用实体专家类呢?
因为我们是在EO中进行一个有效的验证。比如验证一个职业,一个职业是否有效,就是说在数据库的表中可以找到数据。我们在OAF中,找数据库中的数据,可以基于SQL建立VO,判断VO中是否有数据,就可以进行验证。
但是我们在EO中是无法调用VO中的方法来判断VO时候有数据的,我们必须找一个东西来帮我们调用VO中的方法,这个人就是实体专家类。
实现的具体步骤:
1,创建职位验证模块EmployeeVAM 。(步骤就不写了)
2,创建职位验证视图对象PositionVVO ,并放到VAM中托管。
使用的查询语句例如:

    ```    SELECT lookup_code    FROM fwk_tbx_lookup_codes_b    WHERE lookup_code = :1    and lookup_type = 'FWK_TBX_POSITIONS'    ```

3, 添加如下的 initQuery() 方法到 PositionVVOImpl 类中

    ```    public void initQuery(String positionCode)      {        setWhereClauseParams(null); // Always reset        setWhereClauseParam(0, positionCode);        executeQuery();       }    ```   

4, 创建实体专家类。
关键设置。1:Extends 的值为
oracle.apps.fnd.framework.server.OAEntityExpert
2:Optional Attributes区域:
只选择Public选项框。
5,注册 EmployeeEO 实体对象到员工验证应用模块中
在Properties页:
 创建如下的属性
1:  Name : VAMDef
 Value:XXX.EmployeeVAM
2:  Name:ExpertClass
 Value:XXX.EmployeeEntityExpert
(第5步的目的是因为,在实体专家类中获取VO时,会调用一个findValidationViewObject()方法,这一步就相当于自动就可以将这个VAM和专家类关联起来,没做这一步,就会返回一个空。具体可以参考:
oracle.apps.fnd.framework.server
的OAEntityExpert 方法介绍)
6,记得在EOImpl类中添加一个专家类的获得方法。

import oracle.apps.fnd.framework.server.OADBTransaction; public static EmployeeEntityExpert getEmployeeEntityExpert (OADBTransaction txn)   {     return (EmployeeEntityExpert)txn.getExpert(EmployeeEOImpl.getDefinitionObject());  } 

7,添加一个验证方法到实体专家类中

public boolean isPositionValid(String position)  {    boolean isActive = false;    // Note that we want to use a cached, declaratively defined VO instead of creating    // one from a SQL statement which is far less performant.    PositionVVOImpl positionVO =       (PositionVVOImpl)findValidationViewObject("PositionVVO1");    positionVO.initQuery(position);    // We're just doing a simple existence check. If we don't find a match, return false.    if (positionVO.hasNext())    {      isActive = true;    }    return isActive;  } 

8,最后在EO的setPositionCode中加上验证逻辑

  if ((value != null) || (!("".equals(value.trim()))))    {      EmployeeEntityExpert expert = getEmployeeEntityExpert(getOADBTransaction());      if (!(expert.isPositionValid(value)))      {        throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,          getEntityDef().getFullName(), // EO name          getPrimaryKey(), // EO PK          "PositionCode", // Attribute Name          value, // Attribute value          "AK", // Message product short name          "FWK_TBX_T_EMP_POSITION_INVALID"); // Message name      }    }
     这样就完成了,菜鸟的自我总结。  
原创粉丝点击