📄 modelviewentity.java
字号:
/*
* $Id: ModelViewEntity.java,v 1.11 2003/12/17 19:29:08 jonesde Exp $
*
* Copyright (c) 2001, 2002 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.util.*;
import org.w3c.dom.*;
import org.ofbiz.base.util.*;
import org.ofbiz.entity.jdbc.*;
/**
* 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 $Revision: 1.11 $
* @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();
public ModelViewEntity(ModelReader reader, Element entityElement, Element docElement, UtilTimer utilTimer, Hashtable docElementValues) {
this.modelReader = reader;
if (utilTimer != null) utilTimer.timerString(" createModelViewEntity: before general/basic info");
this.populateBasicInfo(entityElement, docElement, docElementValues);
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
this.populateFields(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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -