当前位置: 首页>>代码示例>>Java>>正文


Java GenericPK.getAllKeys方法代码示例

本文整理汇总了Java中org.ofbiz.entity.GenericPK.getAllKeys方法的典型用法代码示例。如果您正苦于以下问题:Java GenericPK.getAllKeys方法的具体用法?Java GenericPK.getAllKeys怎么用?Java GenericPK.getAllKeys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ofbiz.entity.GenericPK的用法示例。


在下文中一共展示了GenericPK.getAllKeys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCurrentValueWithCachedPK

import org.ofbiz.entity.GenericPK; //导入方法依赖的package包/类
public static void getCurrentValueWithCachedPK(HttpServletRequest request, Delegator delegator, GenericPK cachedPK, String entityName) {
    Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
    // Build the primary key that may have been passed in as key values
    GenericValue v = delegator.makeValue(entityName);
    GenericPK passedPK = v.getPrimaryKey();
    Collection<String> keyColl = passedPK.getAllKeys();
    for (String attrName : keyColl) {
        String attrVal = (String)request.getAttribute(attrName);
        if (UtilValidate.isEmpty(attrVal)) {
            attrVal = (String)paramMap.get(attrName);
        }
        if (UtilValidate.isNotEmpty(attrVal)) {
            passedPK.put(attrName,attrVal);
        }
    }

    // If a full passed primary key exists, it takes precedence over a cached key
    // I cannot determine if the key testing utils of GenericEntity take into account
    // whether or not a field is populated.
    boolean useCached = false;
    boolean usePassed = true;
    if (cachedPK != null) {
        useCached = true;
        keyColl = cachedPK.getPrimaryKey().getAllKeys();
        for (String ky : keyColl) {
            String sCached = null;
            String sPassed = null;
            Object oPassed = null;
            Object oCached = null;
            oPassed = passedPK.get(ky);
            if (oPassed != null) {
                sPassed = oPassed.toString();
                if (UtilValidate.isEmpty(sPassed)) {
                    // If any part of passed key is not available, it can't be used
                    usePassed = false;
                } else {
                    oCached = cachedPK.get(ky);
                    if (oCached != null) {
                        sCached = oCached.toString();
                        if (UtilValidate.isEmpty(sCached)) {
                            useCached = false;
                        } else {
                        }
                    } else {
                        useCached = false;
                    }
                }
            } else {
                //useCached = false;
                usePassed = false;
            }
        }
    }

    GenericPK currentPK = null;
    if (usePassed && useCached) {
        currentPK = passedPK;
    } else if (usePassed && !useCached) {
        currentPK = passedPK;
    } else if (!usePassed && useCached) {
        currentPK = cachedPK;
    }

    if (currentPK != null) {
        request.setAttribute("currentPK", currentPK);
        GenericValue currentValue = null;
        try {
            currentValue = EntityQuery.use(delegator).from(currentPK.getEntityName()).where(currentPK).queryOne();
        } catch (GenericEntityException e) {
        }
        request.setAttribute("currentValue", currentValue);
    }

}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:75,代码来源:ContentManagementWorker.java

示例2: getCurrentValueWithCachedPK

import org.ofbiz.entity.GenericPK; //导入方法依赖的package包/类
public static void getCurrentValueWithCachedPK(HttpServletRequest request, Delegator delegator, GenericPK cachedPK, String entityName) {
    Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
    // Build the primary key that may have been passed in as key values
    GenericValue v = delegator.makeValue(entityName);
    GenericPK passedPK = v.getPrimaryKey();
    Collection<String> keyColl = passedPK.getAllKeys();
    for(String attrName : keyColl) {
        String attrVal = (String)request.getAttribute(attrName);
        if (UtilValidate.isEmpty(attrVal)) {
            attrVal = (String)paramMap.get(attrName);
        }
        if (UtilValidate.isNotEmpty(attrVal)) {
            passedPK.put(attrName,attrVal);
        }
    }

    // If a full passed primary key exists, it takes precedence over a cached key
    // I cannot determine if the key testing utils of GenericEntity take into account
    // whether or not a field is populated.
    boolean useCached = false;
    boolean usePassed = true;
    if (cachedPK != null) {
        useCached = true;
        keyColl = cachedPK.getPrimaryKey().getAllKeys();
        for(String ky : keyColl) {
            String sCached = null;
            String sPassed = null;
            Object oPassed = null;
            Object oCached = null;
            oPassed = passedPK.get(ky);
            if (oPassed != null) {
                sPassed = oPassed.toString();
                if (UtilValidate.isEmpty(sPassed)) {
                    // If any part of passed key is not available, it can't be used
                    usePassed = false;
                } else {
                    oCached = cachedPK.get(ky);
                    if (oCached != null) {
                        sCached = oCached.toString();
                        if (UtilValidate.isEmpty(sCached)) {
                            useCached = false;
                        } else {
                        }
                    } else {
                        useCached = false;
                    }
                }
            } else {
                //useCached = false;
                usePassed = false;
            }
        }
    }

    GenericPK currentPK = null;
    if (usePassed && useCached) {
        currentPK = passedPK;
    } else if (usePassed && !useCached) {
        currentPK = passedPK;
    } else if (!usePassed && useCached) {
        currentPK = cachedPK;
    }

    if (currentPK != null) {
        request.setAttribute("currentPK", currentPK);
        GenericValue currentValue = null;
        try {
            currentValue = delegator.findOne(currentPK.getEntityName(), currentPK, false);
        } catch (GenericEntityException e) {
        }
        request.setAttribute("currentValue", currentValue);
    }

}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:75,代码来源:ContentManagementWorker.java


注:本文中的org.ofbiz.entity.GenericPK.getAllKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。