OAF 中的EO 和VO
EO :oracle.apps.fnd.framework.server.OAEntityImpl
VO:oracle.apps.fnd.framework.server.OAViewRowImpl
1.準(zhǔn)備插入的視圖VO
此VO 只是插入行,不從數(shù)據(jù)庫(kù)中查詢。則此時(shí)必須 setMaxFetchSize(0)進(jìn)行初始化。
AM 中的邏輯代碼:
//檢查并確保 VO 中沒(méi)有行,在插入之前進(jìn)行初始化
if (vo.getFetchedRowCount() == 0)
{
vo.setMaxFetchSize(0);
}
// Perform insert
Row row = vo.createRow();
vo.insertRow(row);
//如果row是事物的,則進(jìn)行此設(shè)置
row.setNewRowState(Row.STATUS_INITIALIZED);
2.EO 中的create
(1).簡(jiǎn)單的單表create
// AM
public void create()
{
OAViewObject vo = getSuppliersVO();
vo.insertRow(vo.createRow());
//插入行之后重新設(shè)置row狀態(tài)
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設(shè)置為當(dāng)前時(shí)間
setStartDate(transaction.getCurrentDBDate());
}
給table插入新的行后,立即設(shè)置 setNewRowState(STATUS_INITIALIZED)
這樣的話BC4J 就會(huì)刪除EO相對(duì)應(yīng)的事物和驗(yàn)證監(jiān)聽(tīng),因此設(shè)置后將不會(huì)驗(yàn)證或提交給數(shù)據(jù)庫(kù)
(2)主從關(guān)系表的create
3.EO 中驗(yàn)證主鍵是否唯一 在SupplierEOImpl
public void setSupplierId(Number value)
{
if (value != null)
{
//Supplier id 必須唯一,findByPrimaryKey()確保檢查所有的suppliers,首先它檢查entity緩存,然后檢查數(shù)據(jù)庫(kù)
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 的刪除
/*刪除采購(gòu)訂單從PoSimpleSummaryVO根據(jù)poHeaderId參數(shù)*/
public Boolean delete(String poHeaderId)
{
int poToDelete = Integer.parseInt(poHeaderId);
OAViewObject vo = getPoSimpleSummaryVO();
PoSimpleSummaryVORowImpl row = null;
//緩存中的行數(shù)
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 驗(yàn)證name 不為空,且唯一
SupplierEOImpl
public void setName(String value)
{
if ((value != null) || (!("".equals(value.trim()))))
{
// 驗(yàn)證name是否唯一,將先從entity 緩存,然后在數(shù)據(jù)庫(kù)檢查.
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();
// 如果數(shù)據(jù)庫(kù)可以查詢出來(lái)相同的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
}
}
// 檢查數(shù)據(jù)庫(kù)
OADBTransaction transaction = getOADBTransaction();
OAApplicationModule vam;
//查看am是否創(chuàng)建,如果沒(méi)有創(chuàng)建,則在事物中創(chuàng)建.
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);
}
事務(wù)鎖
// 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.
總結(jié)
以上是生活随笔為你收集整理的OAF 中的EO 和VO的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 2020年8月PYPL编程语言流行指数排
- 下一篇: 数据可视化之powerBI技巧(四)使用