• 在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
  • 相关阅读:
    Java的值传递和引用传递的说法
    将对象写道硬盘上and从硬盘上读入对象
    分割一个文件and合并一个文件(并且带有配置信息记录)
    文件的切割和合并
    SequenceInputStream的用法(用来合并流然后一起操作)
    PrintStream和PrintWrite用法
    将一个文件夹中的所有含有某个后缀的文件写进一个文件里面
    关于Properties的制作配置文件(当一个app已经5次被打开我们就收费)
    Properties的用法
    深层删除一个目录(java)
  • 原文地址:https://www.cnblogs.com/huanghongbo/p/6840443.html
Copyright © 2020-2023  润新知