📄 modelviewentity.java
字号:
} } } public String getEntityAlias() { return this.entityAlias; } public String getPrefix() { return this.prefix; } public boolean shouldExclude(String fieldName) { if (this.fieldsToExclude == null) { return false; } else { return this.fieldsToExclude.contains(fieldName); } } } public static class ModelAlias implements Serializable { protected String entityAlias = ""; protected String name = ""; protected String field = ""; protected String colAlias = ""; // this is a Boolean object for a tri-state: null, true or false protected Boolean isPk = null; protected boolean groupBy = false; // is specified this alias is a calculated value; can be: min, max, sum, avg, count, count-distinct protected String function = null; protected boolean isFromAliasAll = false; protected ComplexAliasMember complexAliasMember = null; protected ModelAlias() {} public ModelAlias(Element aliasElement) { this.entityAlias = UtilXml.checkEmpty(aliasElement.getAttribute("entity-alias")); this.name = UtilXml.checkEmpty(aliasElement.getAttribute("name")); this.field = UtilXml.checkEmpty(aliasElement.getAttribute("field"), this.name); this.colAlias = UtilXml.checkEmpty(aliasElement.getAttribute("col-alias"), ModelUtil.javaNameToDbName(UtilXml.checkEmpty(this.name))); String primKeyValue = UtilXml.checkEmpty(aliasElement.getAttribute("prim-key")); if (UtilValidate.isNotEmpty(primKeyValue)) { this.isPk = new Boolean("true".equals(primKeyValue)); } else { this.isPk = null; } this.groupBy = "true".equals(UtilXml.checkEmpty(aliasElement.getAttribute("group-by"))); this.function = UtilXml.checkEmpty(aliasElement.getAttribute("function")); Element complexAliasElement = UtilXml.firstChildElement(aliasElement, "complex-alias"); if (complexAliasElement != null) { complexAliasMember = new ComplexAlias(complexAliasElement); } } public ModelAlias(String entityAlias, String name, String field, String colAlias, Boolean isPk, Boolean groupBy, String function) { this.entityAlias = entityAlias; this.name = name; this.field = UtilXml.checkEmpty(field, this.name); this.colAlias = UtilXml.checkEmpty(colAlias, ModelUtil.javaNameToDbName(UtilXml.checkEmpty(this.name))); this.isPk = isPk; if (groupBy != null) { this.groupBy = groupBy.booleanValue(); } else { this.groupBy = false; } this.function = function; } public void setComplexAliasMember(ComplexAliasMember complexAliasMember) { this.complexAliasMember = complexAliasMember; } public boolean isComplexAlias() { return complexAliasMember != null; } public void makeAliasColName(StringBuffer colNameBuffer, StringBuffer fieldTypeBuffer, ModelViewEntity modelViewEntity, ModelReader modelReader) { if (complexAliasMember != null) { complexAliasMember.makeAliasColName(colNameBuffer, fieldTypeBuffer, modelViewEntity, modelReader); } } public String getEntityAlias() { return this.entityAlias; } public String getName() { return this.name; } public String getColAlias() { return this.colAlias; } public String getField() { return this.field; } public Boolean getIsPk() { return this.isPk; } public boolean getGroupBy() { return this.groupBy; } public String getFunction() { return this.function; } public boolean getIsFromAliasAll() { return this.isFromAliasAll; } } public static interface ComplexAliasMember extends Serializable { public void makeAliasColName(StringBuffer colNameBuffer, StringBuffer fieldTypeBuffer, ModelViewEntity modelViewEntity, ModelReader modelReader); } public static class ComplexAlias implements ComplexAliasMember { protected List complexAliasMembers = new LinkedList(); protected String operator; public ComplexAlias(String operator) { this.operator = operator; } public ComplexAlias(Element complexAliasElement) { this.operator = complexAliasElement.getAttribute("operator"); // handle all complex-alias and complex-alias-field sub-elements List subElements = UtilXml.childElementList(complexAliasElement); Iterator subElementIter = subElements.iterator(); while (subElementIter.hasNext()) { Element subElement = (Element) subElementIter.next(); String nodeName = subElement.getNodeName(); if ("complex-alias".equals(nodeName)) { this.addComplexAliasMember(new ComplexAlias(subElement)); } else if ("complex-alias-field".equals(nodeName)) { this.addComplexAliasMember(new ComplexAliasField(subElement)); } } } public void addComplexAliasMember(ComplexAliasMember complexAliasMember) { this.complexAliasMembers.add(complexAliasMember); } public void makeAliasColName(StringBuffer colNameBuffer, StringBuffer fieldTypeBuffer, ModelViewEntity modelViewEntity, ModelReader modelReader) { if (complexAliasMembers.size() == 0) { return; } else if (complexAliasMembers.size() == 1) { ComplexAliasMember complexAliasMember = (ComplexAliasMember) complexAliasMembers.iterator().next(); complexAliasMember.makeAliasColName(colNameBuffer, fieldTypeBuffer, modelViewEntity, modelReader); } else { colNameBuffer.append('('); Iterator complexAliasMemberIter = complexAliasMembers.iterator(); while (complexAliasMemberIter.hasNext()) { ComplexAliasMember complexAliasMember = (ComplexAliasMember) complexAliasMemberIter.next(); complexAliasMember.makeAliasColName(colNameBuffer, fieldTypeBuffer, modelViewEntity, modelReader); if (complexAliasMemberIter.hasNext()) { colNameBuffer.append(' '); colNameBuffer.append(this.operator); colNameBuffer.append(' '); } } colNameBuffer.append(')'); } } } public static class ComplexAliasField implements ComplexAliasMember { protected String entityAlias = ""; protected String field = ""; protected String function = null; public ComplexAliasField(String entityAlias , String field) { this.entityAlias = entityAlias; this.field = field; } public ComplexAliasField(String entityAlias , String field, String function) { this.entityAlias = entityAlias; this.field = field; this.function = function; } public ComplexAliasField(Element complexAliasFieldElement) { this.entityAlias = complexAliasFieldElement.getAttribute("entity-alias"); this.field = complexAliasFieldElement.getAttribute("field"); this.function = complexAliasFieldElement.getAttribute("function"); } public void makeAliasColName(StringBuffer colNameBuffer, StringBuffer fieldTypeBuffer, ModelViewEntity modelViewEntity, ModelReader modelReader) { ModelEntity modelEntity = modelViewEntity.getAliasedEntity(entityAlias, modelReader); ModelField modelField = modelViewEntity.getAliasedField(modelEntity, field, modelReader); String colName = entityAlias + "." + modelField.getColName(); if (UtilValidate.isNotEmpty(function)) { String prefix = (String) functionPrefixMap.get(function); if (prefix == null) { Debug.logWarning("Specified alias function [" + function + "] not valid; must be: min, max, sum, avg, count or count-distinct; using a column name with no function function", module); } else { colName = prefix + colName + ")"; } } colNameBuffer.append(colName); //set fieldTypeBuffer if not already set if (fieldTypeBuffer.length() == 0) { fieldTypeBuffer.append(modelField.type); } } } public static class ModelViewLink implements Serializable { protected String entityAlias = ""; protected String relEntityAlias = ""; protected boolean relOptional = false; protected List keyMaps = new ArrayList(); protected ModelViewLink() {} public ModelViewLink(Element viewLinkElement) { this.entityAlias = UtilXml.checkEmpty(viewLinkElement.getAttribute("entity-alias")); this.relEntityAlias = UtilXml.checkEmpty(viewLinkElement.getAttribute("rel-entity-alias")); // if anything but true will be false; ie defaults to false this.relOptional = "true".equals(viewLinkElement.getAttribute("rel-optional")); NodeList keyMapList = viewLinkElement.getElementsByTagName("key-map"); for (int j = 0; j < keyMapList.getLength(); j++) { Element keyMapElement = (Element) keyMapList.item(j); ModelKeyMap keyMap = new ModelKeyMap(keyMapElement); if (keyMap != null) keyMaps.add(keyMap); } } public ModelViewLink(String entityAlias, String relEntityAlias, Boolean relOptional, List keyMaps) { this.entityAlias = entityAlias; this.relEntityAlias = relEntityAlias; if (relOptional != null) { this.relOptional = relOptional.booleanValue(); } this.keyMaps.addAll(keyMaps); } public String getEntityAlias() { return this.entityAlias; } public String getRelEntityAlias() { return this.relEntityAlias; } public boolean isRelOptional() { return this.relOptional; } public ModelKeyMap getKeyMap(int index) { return (ModelKeyMap) this.keyMaps.get(index); } public int getKeyMapsSize() { return this.keyMaps.size(); } public Iterator getKeyMapsIterator() { return this.keyMaps.iterator(); } public List getKeyMapsCopy() { return new ArrayList(this.keyMaps); } } public class ModelConversion implements Serializable { protected String aliasName; protected ModelEntity fromModelEntity; protected Map fieldMap = new HashMap(); protected Set wildcards = new HashSet(); public ModelConversion(String aliasName, ModelEntity fromModelEntity) { this.aliasName = aliasName; this.fromModelEntity = fromModelEntity; Iterator it = getFieldsIterator(); while (it.hasNext()) { ModelField field = (ModelField) it.next(); wildcards.add(field.getName()); } } public int hashCode() { return fromModelEntity.hashCode(); } public boolean equals(Object obj) { if (!(obj instanceof ModelConversion)) return false; ModelConversion other = (ModelConversion) obj; return fromModelEntity.equals(other.fromModelEntity); } public void addConversion(String fromFieldName, String toFieldName) { wildcards.remove(toFieldName); fieldMap.put(fromFieldName, toFieldName); } public String toString() { //return fromModelEntity.getEntityName() + ":" + fieldMap + ":" + wildcards; return aliasName + "(" + fromModelEntity.getEntityName() + ")"; } public Map convert(Map values) { Map newValues = new HashMap(fieldMap.size() + wildcards.size()); Iterator it = fieldMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); newValues.put(entry.getValue(), values.get((String) entry.getKey())); } it = wildcards.iterator(); while (it.hasNext()) { newValues.put((String) it.next(), EntityOperator.WILDCARD); } return newValues; } public void addAllAliasConversions(List aliases, String fieldName) { if (aliases != null) { Iterator it3 = aliases.iterator(); while (it3.hasNext()) { addConversion(fieldName, (String) it3.next()); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -