zoukankan      html  css  js  c++  java
  • OAF 中的EO 和VO

    EO :oracle.apps.fnd.framework.server.OAEntityImpl

    VO:oracle.apps.fnd.framework.server.OAViewRowImpl

    1.准备插入的视图VO

    此VO 只是插入行,不从数据库中查询。则此时必须 setMaxFetchSize(0)进行初始化。

    AM 中的逻辑代码:

    //检查并确保 VO 中没有行,在插入之前进行初始化

               if (vo.getFetchedRowCount() == 0)

                    {

                vo.setMaxFetchSize(0);

                     }

                 // Perform insert

            Row row = vo.createRow();

               vo.insertRow(row);

               //如果row是事物的,则进行此设置

            row.setNewRowState(Row.STATUS_INITIALIZED);

    2.EO 中的create  

    (1).简单的单表create

    // AM

    public void create()

    {

      OAViewObject vo = getSuppliersVO();

      vo.insertRow(vo.createRow());

     //插入行之后重新设置row状态

        vo.setNewRowState(Row.STATUS_INITIALIZED);

    }

    /** 在EOImpl中可以初始化插入的行 */
    Public void create(AttributeList attributeList)
    {
      super.create(attributeList); 
      OADBTransaction transaction = getOADBTransaction();
      // ID 从表序列中获得
      Number supplierId = transaction.getSequenceValue("FWK_TBX_SUPPLIERS_S");
      setSupplierId(supplierId);
    
    
      // Start date设置为当前时间
      setStartDate(transaction.getCurrentDBDate());
    }  

    给table插入新的行后,立即设置 setNewRowState(STATUS_INITIALIZED)

    这样的话BC4J 就会删除EO相对应的事物和验证监听,因此设置后将不会验证或提交给数据库

     (2)主从关系表的create

    3.EO 中验证主键是否唯一 在SupplierEOImpl

    public void setSupplierId(Number value)
    { 
      if (value != null)
      {
         //Supplier id 必须唯一,findByPrimaryKey()确保检查所有的suppliers,首先它检查entity缓存,然后检查数据库
    
       OADBTransaction transaction = getOADBTransaction();
        Object[] supplierKey = {value};
        EntityDefImpl supplierDefinition = SupplierEOImpl.getDefinitionObject();
        SupplierEOImpl supplier = 
          (SupplierEOImpl)supplierDefinition.findByPrimaryKey(transaction, new Key(supplierKey));
        if (supplier != null)
        {
          throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
                 getEntityDef().getFullName(), // EO name
                 getPrimaryKey(), // EO PK
                 "SupplierId", // Attribute Name
                 value, // Bad attribute value
                 "ICX", // Message application short name
                 "FWK_TBX_T_SUP_ID_UNIQUE"); // Message name 
        }
      }
      
      setAttributeInternal(SUPPLIERID, value);
    }  

    4. EO 的删除

    /*删除采购订单从PoSimpleSummaryVO根据poHeaderId 参数*/

    public Boolean delete(String poHeaderId)

    {

        int poToDelete = Integer.parseInt(poHeaderId);

     

      OAViewObject vo = getPoSimpleSummaryVO();

      PoSimpleSummaryVORowImpl row = null;

     //缓存中的行数

      int fetchedRowCount = vo.getFetchedRowCount();

      boolean rowFound = false;

      // 用iterator

      RowSetIterator deleteIter = vo.createRowSetIterator("deleteIter");

      if (fetchedRowCount > 0)

      {

        deleteIter.setRangeStart(0);

        deleteIter.setRangeSize(fetchedRowCount);

        for (int i = 0; i < fetchedRowCount; i++)

        {

          row = (PoSimpleSummaryVORowImpl)deleteIter.getRowAtRangeIndex(i);  

          // Number primaryKey = (Number)row.getAttribute("HeaderId");

          Number primaryKey = row.getHeaderId();

          if (primaryKey.compareTo(poToDelete) == 0)

          {

              row.remove();

            rowFound = true;

            getTransaction().commit();

            break; // only one possible selected row in this case

          }

        }

      }

      // Always close iterators.

      deleteIter.closeRowSetIterator();

      return new Boolean(rowFound);

    }  

    5.EO 验证name 不为空,且唯一

    SupplierEOImpl

    public void setName(String value)
    {
        if ((value != null) || (!("".equals(value.trim()))))
      {
        // 验证name是否唯一,将先从entity 缓存,然后在数据库检查.
        com.sun.java.util.collections.Iterator supplierIterator = 
          getEntityDef().getAllEntityInstancesIterator(getDBTransaction());
           Number currentId = getSupplierId();
    
    
    while ( supplierIterator.hasNext() ) { SupplierEOImpl cachedSupplier = (SupplierEOImpl)supplierIterator.next(); String cachedName = cachedSupplier.getName(); Number cachedId = cachedSupplier.getSupplierId(); // 如果数据库可以查询出来相同的name和ID则抛异常. If (cachedName != null && value.equalsIgnoreCase(cachedName) && cachedId.compareTo(currentId) != 0 ) { throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT, getEntityDef().getFullName(), // EO name getPrimaryKey(), // EO PK "Name", // Attribute Name value, // Attribute value "ICX", // Message product short name "FWK_TBX_T_SUP_DUP_NAME"); // Message name } } // 检查数据库
    OADBTransaction transaction = getOADBTransaction(); OAApplicationModule vam; //查看am是否创建,如果没有创建,则在事物中创建. vam = (OAApplicationModule)transaction.findApplicationModule("supplierVAM"); if (vam == null) { vam = (OAApplicationModule)transaction.createApplicationModule("supplierVAM", "oracle.apps.fnd.framework.toolbox.schema.server.SupplierVAM"); } SupplierNameVVOImpl valNameVo = (SupplierNameVVOImpl)vam.findViewObject("SupplierNameVVO"); valNameVo.initQuery(value); if (valNameVo.hasNext()) { throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT, getEntityDef().getFullName(), // EO name getPrimaryKey(), // EO PK "Name", // Attribute Name value, // Attribute value "ICX", // Message application short name "FWK_TBX_T_SUP_DUP_NAME"); // Message name } } setAttributeInternal(NAME, value); }

    事务锁
    // In the application module...
    OADBTransaction txn = getOADBTransaction();
    txn.setLockingMode(Transaction.LOCK_PESSIMISTIC);
    事物提交:
    getTransaction()Commit();
    事物回滚:

        getTransaction().rollback();

    Entity State

    • STATUS_NEW - the entity object is new in the current transaction.
    • STATUS_DELETED - the entity object originated in the database and has been deleted in the current transaction.
    • STATUS_MODIFIED - the entity object originated in the database and has been changed.
    • STATUS_UNMODIFIED - the entity object originated in the database and has not been changed, or it has been changed and those changes have been committed.
    • STATUS_DEAD - the entity object is new in the current transaction and it has been deleted.
    • STATUS_INITIALIZED - the entity object is in a "temporary" state and will not be posted or validated.

     

  • 相关阅读:
    react入门教程 |菜鸟教程
    React 组件构造方法: ES5 (createClass) 还是 ES6 (class)?
    代码设置LinearLayout的高度
    android调用webservice发送header身份验证不成功
    GridView中item获得焦点放大缩小
    关于url从服务器上获取图片资源
    Android中删除照片操作
    android采用Ksoap2访问webservice,AndroidHttpTransport call方法异常
    创建新的Android项目,Eclipse自动创建的appcompat内容
    Windroy、Windroye、Bluestacks运行Android实现原理
  • 原文地址:https://www.cnblogs.com/daodan/p/4026786.html
Copyright © 2011-2022 走看看