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.

OAF 中的EO 和VO的更多相关文章

  1. OAF中为MessageTextInput添加加事件处理

    需求:现在OAF页面上有俩输入框,单价,数量,根据单价数量,自动计算MessageStyledText金额中的值,对应的基于EO的VO的字段为UnitPrice,Quantity,Total. 实现方 ...

  2. OAF_开发系列29_实现OAF中批次处理迭代器RowSet/RowSetIterator(案例)

    20150814 Created By BaoXinjian

  3. EBS OAF中如何在多行表中实现附件功能

    EBS OAF中如何在多行表中实现附件功能 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 在OAF中使用附件功能之前,要先明白Entity( ...

  4. OAF中trunc函数的使用(转)

    原文地址:OAF中trunc函数的使用 需求:在做OAF开发时,经常会需要查询功能,由于需求的不同,往往不能使用OAF标准的查询功能,需要自己客户化实现查询功能,而在查询功能中,经常会遇到查询的时间范 ...

  5. OAF中的面包屑(breadcrumbs)始无法显示(转)

    原文地址:OAF中的面包屑(breadcrumbs)始无法显示 OAF中面包屑是一种重要的导航工具.可以提示用户抵达当前页面的路径,也可以方便的切换到之前的节点. 开始做面包屑开发的时候发现面包屑总是 ...

  6. OAF中多语言的实现(转)

    正好前两天研究过这个问题,分享一下啊. 标题:        OAF中多语言的实现概述:        OAF的多语言的实现有两种方式,其一是直接通过页面上面的“个性化”连接,连接到指定的页面后,进行 ...

  7. OAF中 遍历HGrid组件中的所有VO行

    在HGrid组件中有如下所示的HeaderVO和LineVO 需要在头上的LOV中触发事件去更新行VO中的值,LOV事件的处理方法见 getLovParameter ,但是由于HGrid的特殊性,不能 ...

  8. 校验基于EO的VO中的字段是否发生变化

    I have a table region and there are multiple records fetching from a Entity based VO. Now I have upd ...

  9. java EE中使用PO和VO的注意事项

    1.基本定义  PO(Persistence Object 持久化对象)是直接跟持久层数据库打交道的java Bean (model,entity,bean等叫法都是可以的),里面除了私有的成员变量之 ...

随机推荐

  1. twitter点赞动画详解

    今天在微博上看到@过气网红一丝 的一篇微博,codepen上贴出了twitter点赞那个动画效果的源码,地址 http://codepen.io/yisi/pen/LpXVJb .我看了下效果很好看, ...

  2. Java 对象,数组 与 JSON 字符串 相互转化

    当 Java 对象中包含 数组集合对象时,将 JSON 字符串转成此对象. public class Cart{} public class MemberCoupon{} public class C ...

  3. ./upload/source/class/class_core.php

    定义了core这个类 error_reporting(E_ALL); error_reporting() 设置 PHP 的报错级别并返回当前级别.可以参考手册. define('IN_DISCUZ', ...

  4. Android开发-Android Studio使用问题解决

    回头一看,很久没来更新了,归其原因,还是懒癌发作,倒是生活作息规律了,几乎每天都在11点前休息.今天趁着培训,使用android studio,发现几个坑: 1.android studio每次都提示 ...

  5. protocol

    For every object that can have a delegate, there is a corresponding protocol that declares themessag ...

  6. OpenGL学习笔记3——缓冲区对象

    在GL中特别提出了缓冲区对象这一概念,是针对提高绘图效率的一个手段.由于GL的架构是基于客户——服务器模型建立的,因此默认所有的绘图数据均是存储在本地客户端,通过GL内核渲染处理以后再将数据发往GPU ...

  7. Ubuntu12.04安装到U盘里

    把linux安装到U盘里,随时随地使用自己的系统show一下不仅用起来顺手而且很方便携带.看了一些关于安装Ubuntu到U盘的资料,自己试着折腾了几次,并且成功安装了.花时间更新要保证系统是最新的就要 ...

  8. DVD管理器集合版

    利用所学的集合写出的DVD管理系统,运用到了所学到集合基础. import java.text.ParseException; import java.text.SimpleDateFormat; i ...

  9. Java获取本机ip和服务器ip

    一.获取服务器IP InetAddress addr = InetAddress.getLocalHost().getHostAddress();//获得本机IP 二.获取客户端本机IP String ...

  10. Json 字符串 转换为 DataTable数据集合

    /// <summary> /// 将json转换为DataTable /// </summary> /// <param name="strJson" ...