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

📄 modelviewentity.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: ModelViewEntity.java 6685 2006-02-06 10:30:53Z jonesde $ * * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.entity.model;import java.io.Serializable;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Set;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilTimer;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.UtilXml;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.jdbc.SqlJdbcUtil;import org.w3c.dom.Element;import org.w3c.dom.NodeList;/** * This class extends ModelEntity and provides additional information appropriate to view entities * * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author     <a href="mailto:peterm@miraculum.com">Peter Moon</a>     * @version    $Rev: 6685 $ * @since      2.0 */public class ModelViewEntity extends ModelEntity {    public static final String module = ModelViewEntity.class.getName();    public static Map functionPrefixMap = new HashMap();    static {        functionPrefixMap.put("min", "MIN(");        functionPrefixMap.put("max", "MAX(");        functionPrefixMap.put("sum", "SUM(");        functionPrefixMap.put("avg", "AVG(");        functionPrefixMap.put("count", "COUNT(");        functionPrefixMap.put("count-distinct", "COUNT(DISTINCT ");        functionPrefixMap.put("upper", "UPPER(");        functionPrefixMap.put("lower", "LOWER(");    }    /** Contains member-entity alias name definitions: key is alias, value is ModelMemberEntity */    protected Map memberModelMemberEntities = new HashMap();    /** A list of all ModelMemberEntity entries; this is mainly used to preserve the original order of member entities from the XML file */    protected List allModelMemberEntities = new LinkedList();    /** Contains member-entity ModelEntities: key is alias, value is ModelEntity; populated with fields */    protected Map memberModelEntities = null;    /** List of alias-alls which act as a shortcut for easily pulling over member entity fields */    protected List aliasAlls = new ArrayList();    /** List of aliases with information in addition to what is in the standard field list */    protected List aliases = new ArrayList();    /** List of view links to define how entities are connected (or "joined") */    protected List viewLinks = new ArrayList();    /** A List of the Field objects for the View Entity, one for each GROUP BY field */    protected List groupBys = new ArrayList();    protected Map conversions = new HashMap();    public ModelViewEntity(ModelReader reader, Element entityElement, UtilTimer utilTimer, ModelInfo def) {        super(reader, entityElement, def);        if (utilTimer != null) utilTimer.timerString("  createModelViewEntity: before general/basic info");        this.populateBasicInfo(entityElement);        if (utilTimer != null) utilTimer.timerString("  createModelViewEntity: before \"member-entity\"s");        List memberEntityList = UtilXml.childElementList(entityElement, "member-entity");        Iterator memberEntityIter = memberEntityList.iterator();        while (memberEntityIter.hasNext()) {            Element memberEntityElement = (Element) memberEntityIter.next();            String alias = UtilXml.checkEmpty(memberEntityElement.getAttribute("entity-alias"));            String name = UtilXml.checkEmpty(memberEntityElement.getAttribute("entity-name"));            if (name.length() <= 0 || alias.length() <= 0) {                Debug.logError("[new ModelViewEntity] entity-alias or entity-name missing on member-entity element of the view-entity " + this.entityName, module);            } else {                ModelMemberEntity modelMemberEntity = new ModelMemberEntity(alias, name);                this.addMemberModelMemberEntity(modelMemberEntity);            }        }        // when reading aliases and alias-alls, just read them into the alias list, there will be a pass        // after loading all entities to go back and fill in all of the ModelField entries        List aliasAllList = UtilXml.childElementList(entityElement, "alias-all");        Iterator aliasAllIter = aliasAllList.iterator();        while (aliasAllIter.hasNext()) {            Element aliasElement = (Element) aliasAllIter.next();            ModelViewEntity.ModelAliasAll aliasAll = new ModelAliasAll(aliasElement);            this.aliasAlls.add(aliasAll);        }        if (utilTimer != null) utilTimer.timerString("  createModelViewEntity: before aliases");        List aliasList = UtilXml.childElementList(entityElement, "alias");        Iterator aliasIter = aliasList.iterator();        while (aliasIter.hasNext()) {            Element aliasElement = (Element) aliasIter.next();            ModelViewEntity.ModelAlias alias = new ModelAlias(aliasElement);            this.aliases.add(alias);        }                List viewLinkList = UtilXml.childElementList(entityElement, "view-link");        Iterator viewLinkIter = viewLinkList.iterator();        while (viewLinkIter.hasNext()) {            Element viewLinkElement = (Element) viewLinkIter.next();            ModelViewLink viewLink = new ModelViewLink(viewLinkElement);            this.addViewLink(viewLink);        }        if (utilTimer != null) utilTimer.timerString("  createModelEntity: before relations");        this.populateRelated(reader, entityElement);        // before finishing, make sure the table name is null, this should help bring up errors early...        this.tableName = null;    }        public ModelViewEntity(DynamicViewEntity dynamicViewEntity, ModelReader modelReader) {        this.entityName = dynamicViewEntity.getEntityName();        this.packageName = dynamicViewEntity.getPackageName();        this.title = dynamicViewEntity.getTitle();        this.defaultResourceName = dynamicViewEntity.getDefaultResourceName();                // member-entities        Iterator modelMemberEntitiesEntryIter = dynamicViewEntity.getModelMemberEntitiesEntryIter();        while (modelMemberEntitiesEntryIter.hasNext()) {            Map.Entry entry = (Map.Entry) modelMemberEntitiesEntryIter.next();            this.addMemberModelMemberEntity((ModelMemberEntity) entry.getValue());        }                // alias-alls        dynamicViewEntity.addAllAliasAllsToList(this.aliasAlls);                // aliases        dynamicViewEntity.addAllAliasesToList(this.aliases);                // view-links        dynamicViewEntity.addAllViewLinksToList(this.viewLinks);                // relations        dynamicViewEntity.addAllRelationsToList(this.relations);                // finalize stuff        // note that this doesn't result in a call to populateReverseLinks because a DynamicViewEntity should never be cached anyway, and will blow up when attempting to make the reverse links to the DynamicViewEntity         this.populateFieldsBasic(modelReader);    }    public Map getMemberModelMemberEntities() {        return this.memberModelMemberEntities;    }    public List getAllModelMemberEntities() {        return this.allModelMemberEntities;    }    public ModelMemberEntity getMemberModelMemberEntity(String alias) {        return (ModelMemberEntity) this.memberModelMemberEntities.get(alias);    }    public ModelEntity getMemberModelEntity(String alias) {        if (this.memberModelEntities == null) {            this.memberModelEntities = new HashMap();            populateFields(this.getModelReader());        }        return (ModelEntity) this.memberModelEntities.get(alias);    }    public void addMemberModelMemberEntity(ModelMemberEntity modelMemberEntity) {        this.memberModelMemberEntities.put(modelMemberEntity.getEntityAlias(), modelMemberEntity);        this.allModelMemberEntities.add(modelMemberEntity);    }    public void removeMemberModelMemberEntity(String alias) {        ModelMemberEntity modelMemberEntity = (ModelMemberEntity) this.memberModelMemberEntities.remove(alias);        if (modelMemberEntity == null) return;        this.allModelMemberEntities.remove(modelMemberEntity);    }    /** The col-name of the Field, the alias of the field if this is on a view-entity */    public String getColNameOrAlias(String fieldName) {        ModelField modelField = this.getField(fieldName);        String fieldString = modelField.getColName();        ModelViewEntity.ModelAlias alias = getAlias(fieldName);        if (alias != null) {            fieldString = alias.getColAlias();        }        return fieldString;    }    /** List of aliases with information in addition to what is in the standard field list */    public ModelAlias getAlias(int index) {        return (ModelAlias) this.aliases.get(index);    }        public ModelAlias getAlias(String name) {        Iterator aliasIter = getAliasesIterator();        while (aliasIter.hasNext()) {            ModelAlias alias = (ModelAlias) aliasIter.next();            if (alias.name.equals(name)) {                return alias;            }        }        return null;    }    public int getAliasesSize() {        return this.aliases.size();    }    public Iterator getAliasesIterator() {        return this.aliases.iterator();    }    public List getAliasesCopy() {        return new ArrayList(this.aliases);    }    public List getGroupBysCopy() {        return new ArrayList(this.groupBys);    }    /** List of view links to define how entities are connected (or "joined") */    public ModelViewLink getViewLink(int index) {        return (ModelViewLink) this.viewLinks.get(index);    }    public int getViewLinksSize() {        return this.viewLinks.size();    }    public Iterator getViewLinksIterator() {        return this.viewLinks.iterator();    }    public List getViewLinksCopy() {        return new ArrayList(this.viewLinks);    }    public void addViewLink(ModelViewLink viewLink) {        this.viewLinks.add(viewLink);    }        public String colNameString(List flds, String separator, String afterLast, boolean alias) {        StringBuffer returnString = new StringBuffer();        if (flds.size() < 1) {            return "";        }        Iterator fldsIt = flds.iterator();        while (fldsIt.hasNext()) {            ModelField field = (ModelField) fldsIt.next();            returnString.append(field.colName);            if (alias) {                ModelAlias modelAlias = this.getAlias(field.name);                if (modelAlias != null) {                    returnString.append(" AS " + modelAlias.getColAlias());                }            }            if (fldsIt.hasNext()) {                returnString.append(separator);            }        }        returnString.append(afterLast);        return returnString.toString();    }    protected ModelEntity aliasedModelEntity = new ModelEntity();    public ModelEntity getAliasedModelEntity() {        return this.aliasedModelEntity;    }    public ModelEntity getAliasedEntity(String entityAlias, ModelReader modelReader) {        ModelMemberEntity modelMemberEntity = (ModelMemberEntity) this.memberModelMemberEntities.get(entityAlias);        if (modelMemberEntity == null) {            Debug.logError("No member entity with alias " + entityAlias + " found in view-entity " + this.getEntityName() + "; this view-entity will NOT be usable...", module);            return null;        }        String aliasedEntityName = modelMemberEntity.getEntityName();        ModelEntity aliasedEntity = modelReader.getModelEntityNoCheck(aliasedEntityName);        if (aliasedEntity == null) {            Debug.logError("[ModelViewEntity.populateFields] ERROR: could not find ModelEntity for entity name: " + aliasedEntityName, module);            return null;        }                return aliasedEntity;    }        public ModelField getAliasedField(ModelEntity aliasedEntity, String field, ModelReader modelReader) {        ModelField aliasedField = aliasedEntity.getField(field);        if (aliasedEntity == null) {            Debug.logError("[ModelViewEntity.populateFields] ERROR: could not find ModelEntity for entity name: " + aliasedEntity.getEntityName(), module);            return null;        }        return aliasedField;    }        public void populateFields(ModelReader modelReader) {        populateFieldsBasic(modelReader);        populateReverseLinks();    }        public void populateFieldsBasic(ModelReader modelReader) {        if (this.memberModelEntities == null) {            this.memberModelEntities = new HashMap();        }        Iterator meIter = memberModelMemberEntities.entrySet().iterator();        while (meIter.hasNext()) {

⌨️ 快捷键说明

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