在EORow或者VORow中对数据进行重复性校验

需求:在设置付款条件时不允许账期+付款方式重复。

在EORow或者VORow中对数据进行重复性校验


由于本次需求仅需要对VO缓存中的数据进行重复性校验,所以仅需进行缓存遍历即可,不需要校验数据库。

方式1,在EORow的进行数据校验。

    public void setPaymentTermsId(Number value) {
if(value!=null && !"".equals(value) && this.getPaymentMethod()!=null && !"".equals(getPaymentMethod()) ){
validateRepeat(value, getPaymentMethod(), "TERMS");
}
setAttributeInternal(PAYMENTTERMSID, value);
} public void setPaymentMethod(String value) {
if(value!=null && !"".equals(value) && this.getPaymentTermsId()!=null && !"".equals(getPaymentTermsId()) ){
validateRepeat(getPaymentTermsId(), value, "METHOD");
}
setAttributeInternal(PAYMENTMETHOD, value);
} public void validateRepeat(Number payTerms,String payMethod,String cloumn){
com.sun.java.util.collections.Iterator payIterator =
getEntityDef().getAllEntityInstancesIterator(getDBTransaction());
String currentStr = payTerms+"-"+payMethod; while(payIterator.hasNext()){
CuxPoPayProvisionTempEOImpl cachePay = (CuxPoPayProvisionTempEOImpl)payIterator.next();
String validationStr = cachePay.getPaymentTermsId()+"-"+cachePay.getPaymentMethod();
if(currentStr.equals(validationStr)){
if("TERMS".equals(cloumn)){
//发生重复异常时,设置选择值为空,避免选择后提示了异常,选择值仍然放置到了Poplist中
setPaymentTermsId(null);
}
if("METHOD".equals(cloumn)){
//发生重复异常时,设置选择值为空,避免选择后提示了异常,选择值仍然放置到了Poplist中
setPaymentMethod(null);
} throw
new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
getEntityDef().getFullName(),
getPrimaryKey(),
"PayProvisionTempId", currentStr,
"CUX",
"CUX_PO_PAY_PROVI_VALIDATION"); // Message name
} } }

2.在VORow中进行校验,

    public void setPaymentTermsId(Number value) {
if(value!=null && !"".equals(value) && this.getPaymentMethod()!=null && !"".equals(getPaymentMethod()) ){
validateRepeat(value, getPaymentMethod(), "TERMS");
}
setAttributeInternal(PAYMENTTERMSID, value);
} public String getPaymentMethod() {
return (String) getAttributeInternal(PAYMENTMETHOD);
} public void validateRepeat(Number payTerms,String payMethod,String cloumn){
CuxPoPayProvisionTempEOImpl tempEO =(CuxPoPayProvisionTempEOImpl)this.getEntity(0);
com.sun.java.util.collections.Iterator payIterator = tempEO.getDefinitionObject().getAllEntityInstancesIterator(tempEO.getDBTransaction()); String currentStr = payTerms+"-"+payMethod; while(payIterator.hasNext()){
CuxPoPayProvisionTempEOImpl cachePay = (CuxPoPayProvisionTempEOImpl)payIterator.next();
String validationStr = cachePay.getPaymentTermsId()+"-"+cachePay.getPaymentMethod();
if(currentStr.equals(validationStr)){
if("TERMS".equals(cloumn)){
setPaymentTermsId(null);
}
if("METHOD".equals(cloumn)){
setPaymentMethod(null);
} throw
new OAAttrValException(OAException.TYP_VIEW_OBJECT,
getViewObject().getFullName(),
getKey(),
"PayProvisionTempId", currentStr,
"CUX",
"CUX_PO_PAY_PROVI_VALIDATION"); // Message name
} }
}

在实际的使用中存在以下需求,不仅要对VO中未提交的缓存进行校验,同时要校验数据库中已存在的值。

方法1.使用标准的同时扫描EORow和TABLE的方式,如果存在结果集,则说明该值已存在。

参考:同时查询数据库和缓存中的数据

public boolean attachmentExistsInCacheOrDb( String entityName, String[] pkValues){
boolean atchExists = false;
if ( pkValues != null )
{
if ( pkValues.length > 5 )
throw new OAException("FND", "ATTCH_TOO_MANY_PKVALUES");
ViewObject vo = null;
vo = this.findViewObject("CheckFndAttachedDocumentsVO");
if ( vo == null ){
vo = this.createViewObject("CheckFndAttachedDocumentsVO",
"oracle.apps.fnd.server.FndAttachedDocumentsVO");
} vo.addQueryMode(vo.QUERY_MODE_SCAN_DATABASE_TABLES |
vo.QUERY_MODE_SCAN_ENTITY_ROWS);
ViewCriteria vc = vo.createViewCriteria();
ViewCriteriaRow vcr = vc.createViewCriteriaRow();
//设定标准查询参数,可以多个,参数与Attribute类型一定要一致
vcr.setAttribute("EntityName", entityName);
vcr.setAttribute("Pk1Value", pkValues[0]);
vcr.setConjunction(ViewCriteriaRow.VCROW_CONJ_AND);
vc.addElement(vcr); vc.setCriteriaMode(ViewCriteria.CRITERIA_MODE_QUERY |
ViewCriteria.CRITERIA_MODE_CACHE);
vo.applyViewCriteria(vc);
vo.clearCache();
vo.reset();
vo.setWhereClause(null);
vo.setWhereClauseParams(null);
vo.setMaxFetchSize(-1);
vo.executeQuery();
if(vo.hasNext()){
atchExists = true;
}
}
else {
throw new OAException("FND", "ATTCH_PKVALUES_CANNOT_NULL");
}
return atchExists;
}

方法二:在EO或者VO缓存中进行校验之后再调用查询方法查询数据库中是否已存在值

EORowImpl

    public void setItemCategoryId(Number value) {
if (value != null) {
//此部分与缓存中的行进行校验
//具体实现参考前文 OADBTransaction transaction = getOADBTransaction();
CategoryEntityExpert expert = getCategoryEntityExpert(transaction);
if (expert.categoryExists(posMappingId,orgId,orgType, value, orgDepartment))
{
throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
getEntityDef().getFullName(),
getPrimaryKey(),
"ItemCategoryId",
value,
"CUX",
"CUX_SUP_PERMIT_001"); // Message name
} } setAttributeInternal(ITEMCATEGORYID, value);
} public static CategoryEntityExpert getCategoryEntityExpert(OADBTransaction txn){
return (CategoryEntityExpert)txn.getExpert(CuxSuppItemCateMappingEOImpl.getDefinitionObject());
} public static CategoryEntityExpert getCategoryEntityExpert(OADBTransaction txn){
return (CategoryEntityExpert)txn.getExpert(CuxSuppItemCateMappingEOImpl.getDefinitionObject());
}

CategoryEntityExpert类

mport oracle.jbo.domain.Number;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.server.OAEntityExpert; public class CategoryEntityExpert extends OAEntityExpert { public boolean categoryExists(Number posMappingId, Number orgId,
String orgType, Number categoryId,
String orgDepartment) {
boolean exists = false; CategoryIdVVOImpl vvo =
(CategoryIdVVOImpl)findValidationViewObject("CategoryIdVVO1");
vvo.initQuery(posMappingId, orgId, orgType, categoryId, orgDepartment); if (vvo.hasNext()) {
exists = true;
} return exists; } }
CategoryIdVVO1是在AM中实例化的ValidateVO,通常VVO就是用于验证的VO
上一篇:js常用事件及事件对象


下一篇:nginx配置文件中的location中文详解