⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entityutil.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public static List filterByAnd(List values, List exprs) {        if (values == null) return null;        if (exprs == null || exprs.size() == 0) {            // no constraints... oh well            return values;        }        List result = FastList.newInstance();        Iterator iter = values.iterator();        while (iter.hasNext()) {            GenericValue value = (GenericValue) iter.next();            Iterator exprIter = exprs.iterator();            boolean include = true;            while (exprIter.hasNext()) {                EntityCondition condition = (EntityCondition) exprIter.next();                include = condition.entityMatches(value);                if (!include) break;            }            if (include) {                result.add(value);            }        }        return result;    }    /**     *returns the values that match any of the exprs in list     *     *@param values List of GenericValues     *@param exprs the expressions that must validate to true     *@return List of GenericValue's that match the values in fields     */    public static List filterByOr(List values, List exprs) {        if (values == null) return null;        if (exprs == null || exprs.size() == 0) {            return values;        }        List result = FastList.newInstance();        Iterator iter = values.iterator();        while (iter.hasNext()) {            GenericValue value = (GenericValue) iter.next();            boolean include = false;            Iterator exprIter = exprs.iterator();            while (exprIter.hasNext()) {                EntityCondition condition = (EntityCondition) exprIter.next();                include = condition.entityMatches(value);                if (include) break;            }            if (include) {                result.add(value);            }        }        return result;    }    /**     *returns the values in the order specified     *     *@param values List of GenericValues     *@param orderBy The fields of the named entity to order the query by;     *      optionally add a " ASC" for ascending or " DESC" for descending     *@return List of GenericValue's in the proper order     */    public static List orderBy(Collection values, List orderBy) {        if (values == null) return null;        if (values.size() == 0) return FastList.newInstance();        if (orderBy == null || orderBy.size() == 0) {            List newList = FastList.newInstance();            newList.addAll(values);            return newList;        }        List result = FastList.newInstance();        result.addAll(values);        if (Debug.verboseOn()) Debug.logVerbose("Sorting " + values.size() + " values, orderBy=" + orderBy.toString(), module);        Collections.sort(result, new OrderByList(orderBy));        return result;    }    public static List getRelated(String relationName, List values) throws GenericEntityException {        if (values == null) return null;        List result = FastList.newInstance();        Iterator iter = values.iterator();        while (iter.hasNext()) {            result.addAll(((GenericValue) iter.next()).getRelated(relationName));        }        return result;    }    public static List getRelatedCache(String relationName, List values) throws GenericEntityException {        if (values == null) return null;        List result = FastList.newInstance();        Iterator iter = values.iterator();        while (iter.hasNext()) {            result.addAll(((GenericValue) iter.next()).getRelatedCache(relationName));        }        return result;    }    public static List getRelatedByAnd(String relationName, Map fields, List values) throws GenericEntityException {        if (values == null) return null;        List result = FastList.newInstance();        Iterator iter = values.iterator();        while (iter.hasNext()) {            result.addAll(((GenericValue) iter.next()).getRelatedByAnd(relationName, fields));        }        return result;    }    public static List filterByCondition(List values, EntityCondition condition) {        if (values == null) return null;        List result = FastList.newInstance();        Iterator iter = values.iterator();        while (iter.hasNext()) {            GenericValue value = (GenericValue) iter.next();            if (condition.entityMatches(value)) {                result.add(value);            }        }        return result;    }    public static List filterOutByCondition(List values, EntityCondition condition) {        if (values == null) return null;        List result = FastList.newInstance();        Iterator iter = values.iterator();        while (iter.hasNext()) {            GenericValue value = (GenericValue) iter.next();            if (!condition.entityMatches(value)) {                result.add(value);            }        }        return result;    }    public static List findDatedInclusionEntity(GenericDelegator delegator, String entityName, Map search) throws GenericEntityException {        return findDatedInclusionEntity(delegator, entityName, search, UtilDateTime.nowTimestamp());    }    public static List findDatedInclusionEntity(GenericDelegator delegator, String entityName, Map search, Timestamp now) throws GenericEntityException {        EntityCondition searchCondition = new EntityConditionList(UtilMisc.toList(            new EntityFieldMap(search, EntityOperator.AND),            EntityUtil.getFilterByDateExpr(now)        ), EntityOperator.AND);        return delegator.findByCondition(entityName,searchCondition,null,UtilMisc.toList("-fromDate"));    }    public static GenericValue newDatedInclusionEntity(GenericDelegator delegator, String entityName, Map search) throws GenericEntityException {        return newDatedInclusionEntity(delegator, entityName, search, UtilDateTime.nowTimestamp());    }    public static GenericValue newDatedInclusionEntity(GenericDelegator delegator, String entityName, Map search, Timestamp now) throws GenericEntityException {        List entities = findDatedInclusionEntity(delegator, entityName, search, now);        if (entities != null && entities.size() > 0) {            search = null;            for (int i = 0; i < entities.size(); i++) {                GenericValue entity = (GenericValue)entities.get(i);                if (now.equals(entity.get("fromDate"))) {                    search = FastMap.newInstance();                    search.putAll(entity.getPrimaryKey());                    entity.remove("thruDate");                } else {                    entity.set("thruDate",now);                }                entity.store();            }            if (search == null) {                search = FastMap.newInstance();                search.putAll(EntityUtil.getFirst(entities));            }        } else {            /* why is this being done? leaving out for now...            search = new HashMap(search);            */        }        if (now.equals(search.get("fromDate"))) {            return EntityUtil.getOnly(delegator.findByAnd(entityName, search));        } else {            search.put("fromDate",now);            search.remove("thruDate");            return delegator.makeValue(entityName, search);        }    }    public static void delDatedInclusionEntity(GenericDelegator delegator, String entityName, Map search) throws GenericEntityException {        delDatedInclusionEntity(delegator, entityName, search, UtilDateTime.nowTimestamp());    }    public static void delDatedInclusionEntity(GenericDelegator delegator, String entityName, Map search, Timestamp now) throws GenericEntityException {        List entities = findDatedInclusionEntity(delegator, entityName, search, now);        for (int i = 0; entities != null && i < entities.size(); i++) {            GenericValue entity = (GenericValue)entities.get(i);            entity.set("thruDate",now);            entity.store();        }    }        public static List getFieldListFromEntityList(List genericValueList, String fieldName, boolean distinct) {        if (genericValueList == null || fieldName == null) {            return null;        }        List fieldList = FastList.newInstance();        Set distinctSet = null;        if (distinct) {            distinctSet = FastSet.newInstance();        }                Iterator genericValueIter = genericValueList.iterator();        while (genericValueIter.hasNext()) {            GenericValue value = (GenericValue) genericValueIter.next();            Object fieldValue = value.get(fieldName);            if (distinct) {                if (!distinctSet.contains(fieldValue)) {                    fieldList.add(fieldValue);                    distinctSet.add(fieldValue);                }            } else {                fieldList.add(fieldValue);            }        }                return fieldList;    }        public static List getFieldListFromEntityListIterator(EntityListIterator genericValueEli, String fieldName, boolean distinct) {        if (genericValueEli == null || fieldName == null) {            return null;        }        List fieldList = FastList.newInstance();        Set distinctSet = null;        if (distinct) {            distinctSet = FastSet.newInstance();        }                GenericValue value = null;        while ((value = (GenericValue) genericValueEli.next()) != null) {            Object fieldValue = value.get(fieldName);            if (distinct) {                if (!distinctSet.contains(fieldValue)) {                    fieldList.add(fieldValue);                    distinctSet.add(fieldValue);                }            } else {                fieldList.add(fieldValue);            }        }                return fieldList;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -