Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.entity.model. (OFBIZ-9719) Thanks Julian Leichert for reporting and providing the patch. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1817559 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -94,32 +94,32 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
/** Model fields in the order they were defined. This list duplicates the values in fieldsMap, but
|
||||
* we must keep the list in its original sequence for SQL DISTINCT operations to work properly. */
|
||||
private final List<ModelField> fieldsList = new ArrayList<ModelField>();
|
||||
private final List<ModelField> fieldsList = new ArrayList<>();
|
||||
|
||||
private final Map<String, ModelField> fieldsMap = new HashMap<String, ModelField>();
|
||||
private final Map<String, ModelField> fieldsMap = new HashMap<>();
|
||||
|
||||
private final ArrayList<String> pkFieldNames = new ArrayList<String>();
|
||||
private final ArrayList<String> pkFieldNames = new ArrayList<>();
|
||||
|
||||
/** A List of the Field objects for the Entity, one for each Primary Key */
|
||||
private final ArrayList<ModelField> pks = new ArrayList<ModelField>();
|
||||
private final ArrayList<ModelField> pks = new ArrayList<>();
|
||||
|
||||
/** A List of the Field objects for the Entity, one for each NON Primary Key */
|
||||
private final ArrayList<ModelField> nopks = new ArrayList<ModelField>();
|
||||
private final ArrayList<ModelField> nopks = new ArrayList<>();
|
||||
|
||||
/** relations defining relationships between this entity and other entities */
|
||||
protected CopyOnWriteArrayList<ModelRelation> relations = new CopyOnWriteArrayList<ModelRelation>();
|
||||
protected CopyOnWriteArrayList<ModelRelation> relations = new CopyOnWriteArrayList<>();
|
||||
|
||||
/** indexes on fields/columns in this entity */
|
||||
private CopyOnWriteArrayList<ModelIndex> indexes = new CopyOnWriteArrayList<ModelIndex>();
|
||||
private CopyOnWriteArrayList<ModelIndex> indexes = new CopyOnWriteArrayList<>();
|
||||
|
||||
/** The reference of the dependentOn entity model */
|
||||
protected ModelEntity specializationOfModelEntity = null;
|
||||
|
||||
/** The list of entities that are specialization of on this entity */
|
||||
protected Map<String, ModelEntity> specializedEntities = new HashMap<String, ModelEntity>();
|
||||
protected Map<String, ModelEntity> specializedEntities = new HashMap<>();
|
||||
|
||||
/** map of ModelViewEntities that references this model */
|
||||
private final Set<String> viewEntities = new HashSet<String>();
|
||||
private final Set<String> viewEntities = new HashSet<>();
|
||||
|
||||
/** An indicator to specify if this entity requires locking for updates */
|
||||
protected boolean doLock = false;
|
||||
@@ -232,7 +232,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
this.modelReader = null;
|
||||
this.modelInfo = ModelInfo.DEFAULT;
|
||||
this.tableName = tableName;
|
||||
int dotIndex = this.tableName.indexOf(".");
|
||||
int dotIndex = this.tableName.indexOf('.');
|
||||
if (dotIndex >= 0) {
|
||||
this.tableName = this.tableName.substring(dotIndex + 1);
|
||||
}
|
||||
@@ -274,24 +274,24 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
}
|
||||
|
||||
protected void populateRelated(ModelReader reader, Element entityElement) {
|
||||
List<ModelRelation> tempList = new ArrayList<ModelRelation>(this.relations);
|
||||
List<ModelRelation> tempList = new ArrayList<>(this.relations);
|
||||
for (Element relationElement: UtilXml.childElementList(entityElement, "relation")) {
|
||||
ModelRelation relation = reader.createRelation(this, relationElement);
|
||||
if (relation != null) {
|
||||
tempList.add(relation);
|
||||
}
|
||||
}
|
||||
this.relations = new CopyOnWriteArrayList<ModelRelation>(tempList);
|
||||
this.relations = new CopyOnWriteArrayList<>(tempList);
|
||||
}
|
||||
|
||||
|
||||
protected void populateIndexes(Element entityElement) {
|
||||
List<ModelIndex> tempList = new ArrayList<ModelIndex>(this.indexes);
|
||||
List<ModelIndex> tempList = new ArrayList<>(this.indexes);
|
||||
for (Element indexElement: UtilXml.childElementList(entityElement, "index")) {
|
||||
ModelIndex index = ModelIndex.create(this, indexElement);
|
||||
tempList.add(index);
|
||||
}
|
||||
this.indexes = new CopyOnWriteArrayList<ModelIndex>(tempList);
|
||||
this.indexes = new CopyOnWriteArrayList<>(tempList);
|
||||
}
|
||||
|
||||
public boolean containsAllPkFieldNames(Set<String> fieldNames) {
|
||||
@@ -310,19 +310,19 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
if (extendEntityElement.hasAttribute("enable-lock")) {
|
||||
this.doLock = UtilXml.checkBoolean(extendEntityElement.getAttribute("enable-lock"), false);
|
||||
}
|
||||
|
||||
|
||||
if (extendEntityElement.hasAttribute("no-auto-stamp")) {
|
||||
this.noAutoStamp = UtilXml.checkBoolean(extendEntityElement.getAttribute("no-auto-stamp"), false);
|
||||
}
|
||||
|
||||
|
||||
if (extendEntityElement.hasAttribute("auto-clear-cache")) {
|
||||
this.autoClearCache = UtilXml.checkBoolean(extendEntityElement.getAttribute("auto-clear-cache"), false);
|
||||
}
|
||||
|
||||
|
||||
if (extendEntityElement.hasAttribute("never-cache")) {
|
||||
this.neverCache = UtilXml.checkBoolean(extendEntityElement.getAttribute("never-cache"), false);
|
||||
}
|
||||
|
||||
|
||||
if (extendEntityElement.hasAttribute("sequence-bank-size")) {
|
||||
String sequenceBankSizeStr = UtilXml.checkEmpty(extendEntityElement.getAttribute("sequence-bank-size"));
|
||||
if (UtilValidate.isNotEmpty(sequenceBankSizeStr)) {
|
||||
@@ -333,7 +333,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Element fieldElement : UtilXml.childElementList(extendEntityElement, "field")) {
|
||||
ModelField newField = ModelField.create(this, fieldElement, false);
|
||||
ModelField existingField = this.getField(newField.getName());
|
||||
@@ -457,7 +457,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
public void setNeverCache(boolean neverCache) {
|
||||
this.neverCache = neverCache;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An indicator to specific if this entity should ignore automatic DB checks.
|
||||
* This should be set when the entity is mapped to a database view to prevent
|
||||
@@ -466,11 +466,11 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
public boolean getNeverCheck() {
|
||||
return neverCheck;
|
||||
}
|
||||
|
||||
|
||||
public void setNeverCheck(boolean neverCheck) {
|
||||
this.neverCheck = neverCheck;
|
||||
}
|
||||
|
||||
|
||||
public boolean getAutoClearCache() {
|
||||
return this.autoClearCache;
|
||||
}
|
||||
@@ -557,7 +557,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
public List<ModelField> getPkFields() {
|
||||
synchronized (fieldsLock) {
|
||||
return new ArrayList<ModelField>(this.pks);
|
||||
return new ArrayList<>(this.pks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,7 +586,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
public List<ModelField> getNopksCopy() {
|
||||
synchronized (fieldsLock) {
|
||||
return new ArrayList<ModelField>(this.nopks);
|
||||
return new ArrayList<>(this.nopks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,14 +598,14 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
public Iterator<ModelField> getFieldsIterator() {
|
||||
synchronized (fieldsLock) {
|
||||
List<ModelField> newList = new ArrayList<ModelField>(this.fieldsList);
|
||||
List<ModelField> newList = new ArrayList<>(this.fieldsList);
|
||||
return newList.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ModelField> getFieldsUnmodifiable() {
|
||||
synchronized (fieldsLock) {
|
||||
List<ModelField> newList = new ArrayList<ModelField>(this.fieldsList);
|
||||
List<ModelField> newList = new ArrayList<>(this.fieldsList);
|
||||
return Collections.unmodifiableList(newList);
|
||||
}
|
||||
}
|
||||
@@ -661,13 +661,13 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
public List<String> getAllFieldNames() {
|
||||
synchronized (fieldsLock) {
|
||||
return new ArrayList<String>(this.fieldsMap.keySet());
|
||||
return new ArrayList<>(this.fieldsMap.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getPkFieldNames() {
|
||||
synchronized (fieldsLock) {
|
||||
return new ArrayList<String>(pkFieldNames);
|
||||
return new ArrayList<>(pkFieldNames);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -676,7 +676,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
}
|
||||
|
||||
private List<String> getFieldNamesFromFieldVector(List<ModelField> modelFields) {
|
||||
List<String> nameList = new ArrayList<String>(modelFields.size());
|
||||
List<String> nameList = new ArrayList<>(modelFields.size());
|
||||
for (ModelField field: modelFields) {
|
||||
nameList.add(field.getName());
|
||||
}
|
||||
@@ -687,7 +687,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
* @return field names list, managed by entity-engine
|
||||
*/
|
||||
public List<String> getAutomaticFieldNames() {
|
||||
List<String> nameList = new LinkedList<String>();
|
||||
List<String> nameList = new LinkedList<>();
|
||||
if (! this.noAutoStamp) {
|
||||
nameList.add(STAMP_FIELD);
|
||||
nameList.add(STAMP_TX_FIELD);
|
||||
@@ -722,7 +722,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
}
|
||||
|
||||
public List<ModelRelation> getRelationsList(boolean includeOne, boolean includeOneNoFk, boolean includeMany) {
|
||||
List<ModelRelation> relationsList = new LinkedList<ModelRelation>();
|
||||
List<ModelRelation> relationsList = new LinkedList<>();
|
||||
Iterator<ModelRelation> allIter = this.getRelationsIterator();
|
||||
while (allIter.hasNext()) {
|
||||
ModelRelation modelRelation = allIter.next();
|
||||
@@ -797,7 +797,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
public Iterator<String> getViewConvertorsIterator() {
|
||||
synchronized (viewEntities) {
|
||||
return new HashSet<String>(this.viewEntities).iterator();
|
||||
return new HashSet<>(this.viewEntities).iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1463,7 +1463,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
if (this.getNeverCache()) {
|
||||
root.setAttribute("never-cache", "true");
|
||||
}
|
||||
|
||||
|
||||
if (this.getNeverCheck()) {
|
||||
root.setAttribute("never-check", "true");
|
||||
}
|
||||
@@ -1499,7 +1499,7 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
// append field elements
|
||||
Iterator<ModelField> fieldIter = this.getFieldsIterator();
|
||||
while (fieldIter != null && fieldIter.hasNext()) {
|
||||
while (fieldIter.hasNext()) {
|
||||
ModelField field = fieldIter.next();
|
||||
if (!field.getIsAutoCreatedInternal()) {
|
||||
root.appendChild(field.toXmlElement(document));
|
||||
@@ -1517,14 +1517,14 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
|
||||
// append relation elements
|
||||
Iterator<ModelRelation> relIter = this.getRelationsIterator();
|
||||
while (relIter != null && relIter.hasNext()) {
|
||||
while (relIter.hasNext()) {
|
||||
ModelRelation rel = relIter.next();
|
||||
root.appendChild(rel.toXmlElement(document));
|
||||
}
|
||||
|
||||
// append index elements
|
||||
Iterator<ModelIndex> idxIter = this.getIndexesIterator();
|
||||
while (idxIter != null && idxIter.hasNext()) {
|
||||
while (idxIter.hasNext()) {
|
||||
ModelIndex idx = idxIter.next();
|
||||
root.appendChild(idx.toXmlElement(document));
|
||||
|
||||
@@ -1562,14 +1562,14 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
final boolean useRelationshipNames = false;
|
||||
ModelFieldTypeReader modelFieldTypeReader = ModelFieldTypeReader.getModelFieldTypeReader(helperName);
|
||||
|
||||
Map<String, Object> topLevelMap = new HashMap<String, Object>();
|
||||
Map<String, Object> topLevelMap = new HashMap<>();
|
||||
|
||||
topLevelMap.put("name", this.getEntityName());
|
||||
topLevelMap.put("externalName", this.getTableName(helperName));
|
||||
topLevelMap.put("className", "EOGenericRecord");
|
||||
|
||||
// for classProperties add field names AND relationship names to get a nice, complete chart
|
||||
List<String> classPropertiesList = new LinkedList<String>();
|
||||
List<String> classPropertiesList = new LinkedList<>();
|
||||
topLevelMap.put("classProperties", classPropertiesList);
|
||||
for (ModelField field: this.fieldsList) {
|
||||
if (field.getIsAutoCreatedInternal()) continue;
|
||||
@@ -1587,14 +1587,14 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
}
|
||||
|
||||
// attributes
|
||||
List<Map<String, Object>> attributesList = new LinkedList<Map<String, Object>>();
|
||||
List<Map<String, Object>> attributesList = new LinkedList<>();
|
||||
topLevelMap.put("attributes", attributesList);
|
||||
for (ModelField field: this.fieldsList) {
|
||||
if (field.getIsAutoCreatedInternal()) continue;
|
||||
|
||||
ModelFieldType fieldType = modelFieldTypeReader.getModelFieldType(field.getType());
|
||||
|
||||
Map<String, Object> attributeMap = new HashMap<String, Object>();
|
||||
Map<String, Object> attributeMap = new HashMap<>();
|
||||
attributesList.add(attributeMap);
|
||||
|
||||
if (field.getIsPk()) {
|
||||
@@ -1606,15 +1606,15 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
attributeMap.put("valueClassName", fieldType.getJavaType());
|
||||
|
||||
String sqlType = fieldType.getSqlType();
|
||||
if (sqlType.indexOf("(") >= 0) {
|
||||
attributeMap.put("externalType", sqlType.substring(0, sqlType.indexOf("(")));
|
||||
if (sqlType.indexOf('(') >= 0) {
|
||||
attributeMap.put("externalType", sqlType.substring(0, sqlType.indexOf('(')));
|
||||
// since there is a field length set that
|
||||
String widthStr = sqlType.substring(sqlType.indexOf("(") + 1, sqlType.indexOf(")"));
|
||||
String widthStr = sqlType.substring(sqlType.indexOf('(') + 1, sqlType.indexOf(')'));
|
||||
// if there is a comma split by it for width,precision
|
||||
if (widthStr.indexOf(",") >= 0) {
|
||||
attributeMap.put("width", widthStr.substring(0, widthStr.indexOf(",")));
|
||||
if (widthStr.indexOf(',') >= 0) {
|
||||
attributeMap.put("width", widthStr.substring(0, widthStr.indexOf(',')));
|
||||
// since there is a field precision set that
|
||||
attributeMap.put("precision", widthStr.substring(widthStr.indexOf(",") + 1));
|
||||
attributeMap.put("precision", widthStr.substring(widthStr.indexOf(',') + 1));
|
||||
} else {
|
||||
attributeMap.put("width", widthStr);
|
||||
}
|
||||
@@ -1624,19 +1624,19 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
}
|
||||
|
||||
// primaryKeyAttributes
|
||||
List<String> primaryKeyAttributesList = new LinkedList<String>();
|
||||
List<String> primaryKeyAttributesList = new LinkedList<>();
|
||||
topLevelMap.put("primaryKeyAttributes", primaryKeyAttributesList);
|
||||
for (ModelField pkField : getPkFields()) {
|
||||
primaryKeyAttributesList.add(pkField.getName());
|
||||
}
|
||||
|
||||
// relationships
|
||||
List<Map<String, Object>> relationshipsMapList = new LinkedList<Map<String, Object>>();
|
||||
List<Map<String, Object>> relationshipsMapList = new LinkedList<>();
|
||||
for (ModelRelation relationship: this.relations) {
|
||||
if (entityNameIncludeSet.contains(relationship.getRelEntityName())) {
|
||||
ModelEntity relEntity = entityModelReader.getModelEntity(relationship.getRelEntityName());
|
||||
|
||||
Map<String, Object> relationshipMap = new HashMap<String, Object>();
|
||||
Map<String, Object> relationshipMap = new HashMap<>();
|
||||
relationshipsMapList.add(relationshipMap);
|
||||
|
||||
if (useRelationshipNames || relationship.isAutoRelation()) {
|
||||
@@ -1655,10 +1655,10 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {
|
||||
relationshipMap.put("joinSemantic", "EOInnerJoin");
|
||||
|
||||
|
||||
List<Map<String, Object>> joinsMapList = new LinkedList<Map<String, Object>>();
|
||||
List<Map<String, Object>> joinsMapList = new LinkedList<>();
|
||||
relationshipMap.put("joins", joinsMapList);
|
||||
for (ModelKeyMap keyMap: relationship.getKeyMaps()) {
|
||||
Map<String, Object> joinsMap = new HashMap<String, Object>();
|
||||
Map<String, Object> joinsMap = new HashMap<>();
|
||||
joinsMapList.add(joinsMap);
|
||||
|
||||
ModelField thisField = this.getField(keyMap.getFieldName());
|
||||
|
||||
+16
-15
@@ -23,6 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
@@ -43,7 +44,7 @@ public class ModelEntityChecker {
|
||||
public static void checkEntities(Delegator delegator, List<String> warningList) throws GenericEntityException {
|
||||
ModelReader reader = delegator.getModelReader();
|
||||
|
||||
Set<String> reservedWords = new HashSet<String>();
|
||||
Set<String> reservedWords = new HashSet<>();
|
||||
if (Debug.infoOn()) {
|
||||
Debug.logInfo("[initReservedWords] array length = " + rwArray.length, module);
|
||||
}
|
||||
@@ -51,13 +52,13 @@ public class ModelEntityChecker {
|
||||
reservedWords.add(rwArray[i]);
|
||||
}
|
||||
|
||||
Map<String, Set<String>> packages = new HashMap<String, Set<String>>();
|
||||
Set<String> packageNames = new TreeSet<String>();
|
||||
Set<String> tableNames = new HashSet<String>();
|
||||
Map<String, Set<String>> packages = new HashMap<>();
|
||||
Set<String> packageNames = new TreeSet<>();
|
||||
Set<String> tableNames = new HashSet<>();
|
||||
|
||||
//put the entityNames TreeSets in a HashMap by packageName
|
||||
Collection<String> ec = reader.getEntityNames();
|
||||
Set<String> entityNames = new HashSet<String>(ec);
|
||||
Set<String> entityNames = new HashSet<>(ec);
|
||||
for (String eName: ec) {
|
||||
ModelEntity ent = reader.getModelEntity(eName);
|
||||
|
||||
@@ -68,15 +69,15 @@ public class ModelEntityChecker {
|
||||
|
||||
Set<String> entities = packages.get(ent.getPackageName());
|
||||
if (entities == null) {
|
||||
entities = new TreeSet<String>();
|
||||
entities = new TreeSet<>();
|
||||
packages.put(ent.getPackageName(), entities);
|
||||
packageNames.add(ent.getPackageName());
|
||||
}
|
||||
entities.add(eName);
|
||||
}
|
||||
|
||||
Set<String> fkNames = new HashSet<String>();
|
||||
Set<String> indexNames = new HashSet<String>();
|
||||
Set<String> fkNames = new HashSet<>();
|
||||
Set<String> indexNames = new HashSet<>();
|
||||
|
||||
for (String pName: packageNames) {
|
||||
Set<String> entities = packages.get(pName);
|
||||
@@ -95,16 +96,16 @@ public class ModelEntityChecker {
|
||||
if (entity.getPlainTableName() != null && entity.getPlainTableName().length() > 30) {
|
||||
warningList.add("[TableNameGT30] Table name [" + entity.getPlainTableName() + "] of entity " + entity.getEntityName() + " is longer than 30 characters.");
|
||||
}
|
||||
if (entity.getPlainTableName() != null && reservedWords.contains(entity.getPlainTableName().toUpperCase())) {
|
||||
if (entity.getPlainTableName() != null && reservedWords.contains(entity.getPlainTableName().toUpperCase(Locale.getDefault()))) {
|
||||
warningList.add("[TableNameRW] Table name [" + entity.getPlainTableName() + "] of entity " + entity.getEntityName() + " is a reserved word.");
|
||||
}
|
||||
|
||||
|
||||
// don't check columns/relations/keys when never-check is set to "true"
|
||||
if (entity.getNeverCheck()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Set<String> ufields = new HashSet<String>();
|
||||
|
||||
Set<String> ufields = new HashSet<>();
|
||||
Iterator<ModelField> fieldIter = entity.getFieldsIterator();
|
||||
while (fieldIter.hasNext()) {
|
||||
ModelField field = fieldIter.next();
|
||||
@@ -121,7 +122,7 @@ public class ModelEntityChecker {
|
||||
if (field.getColName().length() == 0) {
|
||||
warningList.add("[FieldNameEQ0] Column name for field name \"" + field.getName() + "\" of entity " + entity.getEntityName() + " is empty (zero length).");
|
||||
}
|
||||
if (reservedWords.contains(field.getColName().toUpperCase()))
|
||||
if (reservedWords.contains(field.getColName().toUpperCase(Locale.getDefault())))
|
||||
warningList.add("[FieldNameRW] Column name " + field.getColName() + " of entity " + entity.getEntityName() + " is a reserved word.");
|
||||
if (type == null) {
|
||||
StringBuilder warningMsg = new StringBuilder();
|
||||
@@ -167,7 +168,7 @@ public class ModelEntityChecker {
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> relations = new HashSet<String>();
|
||||
Set<String> relations = new HashSet<>();
|
||||
for (int r = 0; r < entity.getRelationsSize(); r++) {
|
||||
ModelRelation relation = entity.getRelation(r);
|
||||
|
||||
@@ -285,7 +286,7 @@ public class ModelEntityChecker {
|
||||
}
|
||||
}
|
||||
|
||||
public static final String[] rwArray = { "ABORT", "ABS", "ABSOLUTE",
|
||||
protected static final String[] rwArray = { "ABORT", "ABS", "ABSOLUTE",
|
||||
"ACCEPT", "ACCES", "ACCESS", "ACS", "ACTION", "ACTIVATE", "ADD", "ADDFORM",
|
||||
"ADMIN", "AFTER", "AGGREGATE", "ALIAS", "ALL", "ALLOCATE", "ALTER",
|
||||
"ANALYZE", "AND", "ANDFILENAME", "ANY", "ANYFINISH", "APPEND",
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.ofbiz.base.lang.ThreadSafe;
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.UtilXml;
|
||||
import org.apache.ofbiz.entity.jdbc.DatabaseUtil;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -147,11 +147,7 @@ public final class ModelField extends ModelChild {
|
||||
if (isPk) {
|
||||
isNotNull = true;
|
||||
}
|
||||
EncryptMethod encrypt = EncryptMethod.valueOf(fieldElement.getAttribute("encrypt").toUpperCase());
|
||||
if (encrypt == null) {
|
||||
Debug.logWarning("invalid encrypt value: %s", module, fieldElement.getAttribute("encrypt"));
|
||||
encrypt = EncryptMethod.FALSE;
|
||||
}
|
||||
EncryptMethod encrypt = EncryptMethod.valueOf(fieldElement.getAttribute("encrypt").toUpperCase(Locale.getDefault()));
|
||||
boolean enableAuditLog = "true".equals(fieldElement.getAttribute("enable-audit-log"));
|
||||
List<String>validators = Collections.emptyList();
|
||||
List<? extends Element> elementList = UtilXml.childElementList(fieldElement, "validate");
|
||||
@@ -177,7 +173,7 @@ public final class ModelField extends ModelChild {
|
||||
String name = ModelUtil.dbNameToVarName(colName);
|
||||
String type = ModelUtil.induceFieldType(ccInfo.typeName, ccInfo.columnSize, ccInfo.decimalDigits, modelFieldTypeReader);
|
||||
boolean isPk = ccInfo.isPk;
|
||||
boolean isNotNull = "NO".equals(ccInfo.isNullable.toUpperCase());
|
||||
boolean isNotNull = "NO".equals(ccInfo.isNullable.toUpperCase(Locale.getDefault()));
|
||||
String description = "";
|
||||
String colValue = "";
|
||||
String fieldSet = "";
|
||||
@@ -303,7 +299,7 @@ public final class ModelField extends ModelChild {
|
||||
}
|
||||
root.setAttribute("type", this.getType());
|
||||
if (this.getEncryptMethod().isEncrypted()) {
|
||||
root.setAttribute("encrypt", this.getEncryptMethod().toString().toLowerCase());
|
||||
root.setAttribute("encrypt", this.getEncryptMethod().toString().toLowerCase(Locale.getDefault()));
|
||||
}
|
||||
if (this.getIsNotNull()) {
|
||||
root.setAttribute("not-null", "true");
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package org.apache.ofbiz.entity.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.ofbiz.base.util.UtilXml;
|
||||
import org.apache.ofbiz.entity.jdbc.JdbcValueHandler;
|
||||
@@ -90,18 +91,18 @@ public class ModelFieldType implements Serializable {
|
||||
* @return max length of a String representing the Field value
|
||||
*/
|
||||
public int stringLength() {
|
||||
String sqlTypeUpperCase = sqlType.toUpperCase();
|
||||
String sqlTypeUpperCase = sqlType.toUpperCase(Locale.getDefault());
|
||||
if (sqlTypeUpperCase.indexOf("VARCHAR") >= 0) {
|
||||
if (sqlTypeUpperCase.indexOf("(") > 0 && sqlTypeUpperCase.indexOf(")") > 0) {
|
||||
String length = sqlTypeUpperCase.substring(sqlTypeUpperCase.indexOf("(") + 1, sqlTypeUpperCase.indexOf(")"));
|
||||
if (sqlTypeUpperCase.indexOf('(') > 0 && sqlTypeUpperCase.indexOf(')') > 0) {
|
||||
String length = sqlTypeUpperCase.substring(sqlTypeUpperCase.indexOf('(') + 1, sqlTypeUpperCase.indexOf(')'));
|
||||
|
||||
return Integer.parseInt(length);
|
||||
} else {
|
||||
return 255;
|
||||
}
|
||||
} else if (sqlTypeUpperCase.indexOf("CHAR") >= 0) {
|
||||
if (sqlTypeUpperCase.indexOf("(") > 0 && sqlTypeUpperCase.indexOf(")") > 0) {
|
||||
String length = sqlTypeUpperCase.substring(sqlTypeUpperCase.indexOf("(") + 1, sqlTypeUpperCase.indexOf(")"));
|
||||
if (sqlTypeUpperCase.indexOf('(') > 0 && sqlTypeUpperCase.indexOf(')') > 0) {
|
||||
String length = sqlTypeUpperCase.substring(sqlTypeUpperCase.indexOf('(') + 1, sqlTypeUpperCase.indexOf(')'));
|
||||
|
||||
return Integer.parseInt(length);
|
||||
} else {
|
||||
|
||||
@@ -55,11 +55,11 @@ public class ModelGroupReader implements Serializable {
|
||||
public static final String module = ModelGroupReader.class.getName();
|
||||
private static final UtilCache<String, ModelGroupReader> readers = UtilCache.createUtilCache("entity.ModelGroupReader", 0, 0);
|
||||
|
||||
private Map<String, String> groupCache = null;
|
||||
private volatile Map<String, String> groupCache = null;
|
||||
private Set<String> groupNames = null;
|
||||
|
||||
public String modelName;
|
||||
public List<ResourceHandler> entityGroupResourceHandlers = new LinkedList<ResourceHandler>();
|
||||
public List<ResourceHandler> entityGroupResourceHandlers = new LinkedList<>();
|
||||
|
||||
public static ModelGroupReader getModelGroupReader(String delegatorName) throws GenericEntityConfException {
|
||||
DelegatorElement delegatorInfo = EntityConfig.getInstance().getDelegator(delegatorName);
|
||||
@@ -105,8 +105,8 @@ public class ModelGroupReader implements Serializable {
|
||||
// must check if null again as one of the blocked threads can still enter
|
||||
if (this.groupCache == null) {
|
||||
// now it's safe
|
||||
this.groupCache = new HashMap<String, String>();
|
||||
this.groupNames = new TreeSet<String>();
|
||||
this.groupCache = new HashMap<>();
|
||||
this.groupNames = new TreeSet<>();
|
||||
|
||||
UtilTimer utilTimer = new UtilTimer();
|
||||
// utilTimer.timerString("[ModelGroupReader.getGroupCache] Before getDocument");
|
||||
@@ -141,7 +141,6 @@ public class ModelGroupReader implements Serializable {
|
||||
String entityName = UtilXml.checkEmpty(curEntity.getAttribute("entity")).intern();
|
||||
String groupName = UtilXml.checkEmpty(curEntity.getAttribute("group")).intern();
|
||||
|
||||
if (groupName == null || entityName == null) continue;
|
||||
try {
|
||||
if (null == EntityConfig.getInstance().getDelegator(delegatorName).getGroupDataSource(groupName)) {
|
||||
Debug.logError("The declared group name " + groupName + " has no corresponding group-map in entityengine.xml: ", module);
|
||||
@@ -202,7 +201,7 @@ public class ModelGroupReader implements Serializable {
|
||||
}
|
||||
getGroupCache(delegatorBaseName);
|
||||
if (this.groupNames == null) return null;
|
||||
Set<String> newSet = new HashSet<String>();
|
||||
Set<String> newSet = new HashSet<>();
|
||||
try {
|
||||
newSet.add(EntityConfig.getInstance().getDelegator(delegatorBaseName).getDefaultGroupName());
|
||||
} catch (GenericEntityConfException e) {
|
||||
@@ -218,7 +217,7 @@ public class ModelGroupReader implements Serializable {
|
||||
*/
|
||||
public Set<String> getEntityNamesByGroup(String delegatorBaseName, String groupName) {
|
||||
Map<String, String> gc = getGroupCache(delegatorBaseName);
|
||||
Set<String> enames = new HashSet<String>();
|
||||
Set<String> enames = new HashSet<>();
|
||||
|
||||
if (UtilValidate.isEmpty(groupName)) return enames;
|
||||
if (UtilValidate.isEmpty(gc)) return enames;
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.apache.ofbiz.entity.model;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.ofbiz.base.lang.ThreadSafe;
|
||||
import org.apache.ofbiz.base.util.UtilValidate;
|
||||
@@ -73,11 +74,12 @@ public final class ModelIndex extends ModelChild {
|
||||
List<Field>fields = Collections.emptyList();
|
||||
List<? extends Element> elementList = UtilXml.childElementList(indexElement, "index-field");
|
||||
if (!elementList.isEmpty()) {
|
||||
fields = new ArrayList<Field>(elementList.size());
|
||||
fields = new ArrayList<>(elementList.size());
|
||||
for (Element indexFieldElement : elementList) {
|
||||
String fieldName = indexFieldElement.getAttribute("name").intern();
|
||||
String function = indexFieldElement.getAttribute("function").intern();
|
||||
fields.add(new Field(fieldName, UtilValidate.isNotEmpty(function) ? Function.valueOf(function.toUpperCase()) : null));
|
||||
fields.add(new Field(fieldName, UtilValidate.isNotEmpty(function) ? Function.valueOf(function
|
||||
.toUpperCase(Locale.getDefault())) : null));
|
||||
}
|
||||
fields = Collections.unmodifiableList(fields);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ModelReader implements Serializable {
|
||||
public static final String module = ModelReader.class.getName();
|
||||
private static final UtilCache<String, ModelReader> readers = UtilCache.createUtilCache("entity.ModelReader", 0, 0);
|
||||
|
||||
protected Map<String, ModelEntity> entityCache = null;
|
||||
protected volatile Map<String, ModelEntity> entityCache = null;
|
||||
|
||||
protected int numEntities = 0;
|
||||
protected int numViewEntities = 0;
|
||||
@@ -73,10 +73,16 @@ public class ModelReader implements Serializable {
|
||||
/** collection of filenames for entity definitions */
|
||||
protected Collection<ResourceHandler> entityResourceHandlers;
|
||||
|
||||
/** contains a collection of entity names for each ResourceHandler, populated as they are loaded */
|
||||
/**
|
||||
* contains a collection of entity names for each ResourceHandler, populated as
|
||||
* they are loaded
|
||||
*/
|
||||
protected Map<ResourceHandler, Collection<String>> resourceHandlerEntities;
|
||||
|
||||
/** for each entity contains a map to the ResourceHandler that the entity came from */
|
||||
/**
|
||||
* for each entity contains a map to the ResourceHandler that the entity came
|
||||
* from
|
||||
*/
|
||||
protected Map<String, ResourceHandler> entityResourceHandlerMap;
|
||||
|
||||
public static ModelReader getModelReader(String delegatorName) throws GenericEntityException {
|
||||
@@ -100,9 +106,9 @@ public class ModelReader implements Serializable {
|
||||
|
||||
private ModelReader(String modelName) throws GenericEntityException {
|
||||
this.modelName = modelName;
|
||||
entityResourceHandlers = new LinkedList<ResourceHandler>();
|
||||
resourceHandlerEntities = new HashMap<ResourceHandler, Collection<String>>();
|
||||
entityResourceHandlerMap = new HashMap<String, ResourceHandler>();
|
||||
entityResourceHandlers = new LinkedList<>();
|
||||
resourceHandlerEntities = new HashMap<>();
|
||||
entityResourceHandlerMap = new HashMap<>();
|
||||
|
||||
EntityModelReader entityModelReaderInfo = EntityConfig.getInstance().getEntityModelReader(modelName);
|
||||
|
||||
@@ -110,21 +116,26 @@ public class ModelReader implements Serializable {
|
||||
throw new GenericEntityConfException("Cound not find an entity-model-reader with the name " + modelName);
|
||||
}
|
||||
|
||||
// get all of the main resource model stuff, ie specified in the entityengine.xml file
|
||||
// get all of the main resource model stuff, ie specified in the
|
||||
// entityengine.xml file
|
||||
for (Resource resourceElement : entityModelReaderInfo.getResourceList()) {
|
||||
ResourceHandler handler = new MainResourceHandler(EntityConfig.ENTITY_ENGINE_XML_FILENAME, resourceElement.getLoader(), resourceElement.getLocation());
|
||||
ResourceHandler handler = new MainResourceHandler(EntityConfig.ENTITY_ENGINE_XML_FILENAME, resourceElement
|
||||
.getLoader(), resourceElement.getLocation());
|
||||
entityResourceHandlers.add(handler);
|
||||
}
|
||||
|
||||
// get all of the component resource model stuff, ie specified in each ofbiz-component.xml file
|
||||
for (ComponentConfig.EntityResourceInfo componentResourceInfo: ComponentConfig.getAllEntityResourceInfos("model")) {
|
||||
// get all of the component resource model stuff, ie specified in each
|
||||
// ofbiz-component.xml file
|
||||
for (ComponentConfig.EntityResourceInfo componentResourceInfo : ComponentConfig.getAllEntityResourceInfos(
|
||||
"model")) {
|
||||
if (modelName.equals(componentResourceInfo.readerName)) {
|
||||
entityResourceHandlers.add(componentResourceInfo.createResourceHandler());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ModelEntity buildEntity(ResourceHandler entityResourceHandler, Element curEntityElement, int i, ModelInfo def) throws GenericEntityException {
|
||||
private ModelEntity buildEntity(ResourceHandler entityResourceHandler, Element curEntityElement, int i,
|
||||
ModelInfo def) throws GenericEntityException {
|
||||
boolean isEntity = "entity".equals(curEntityElement.getNodeName());
|
||||
String entityName = UtilXml.checkEmpty(curEntityElement.getAttribute("entity-name")).intern();
|
||||
boolean redefinedEntity = "true".equals(curEntityElement.getAttribute("redefinition"));
|
||||
@@ -133,7 +144,7 @@ public class ModelReader implements Serializable {
|
||||
Collection<String> resourceHandlerEntityNames = resourceHandlerEntities.get(entityResourceHandler);
|
||||
|
||||
if (resourceHandlerEntityNames == null) {
|
||||
resourceHandlerEntityNames = new LinkedList<String>();
|
||||
resourceHandlerEntityNames = new LinkedList<>();
|
||||
resourceHandlerEntities.put(entityResourceHandler, resourceHandlerEntityNames);
|
||||
}
|
||||
resourceHandlerEntityNames.add(entityName);
|
||||
@@ -141,17 +152,17 @@ public class ModelReader implements Serializable {
|
||||
// check to see if entity with same name has already been read
|
||||
if (entityCache.containsKey(entityName) && !redefinedEntity) {
|
||||
Debug.logWarning("Entity " + entityName +
|
||||
" is defined more than once, most recent will over-write " +
|
||||
"previous definition(s)", module);
|
||||
" is defined more than once, most recent will over-write " +
|
||||
"previous definition(s)", module);
|
||||
Debug.logWarning("Entity " + entityName + " was found in " +
|
||||
entityResourceHandler + ", but was already defined in " +
|
||||
entityResourceHandlerMap.get(entityName).toString(), module);
|
||||
entityResourceHandler + ", but was already defined in " +
|
||||
entityResourceHandlerMap.get(entityName).toString(), module);
|
||||
}
|
||||
|
||||
// add entityName, entityFileName pair to entityResourceHandlerMap map
|
||||
entityResourceHandlerMap.put(entityName, entityResourceHandler);
|
||||
|
||||
// utilTimer.timerString(" After entityEntityName -- " + i + " --");
|
||||
// utilTimer.timerString(" After entityEntityName -- " + i + " --");
|
||||
// ModelEntity entity = createModelEntity(curEntity, utilTimer);
|
||||
|
||||
ModelEntity modelEntity = null;
|
||||
@@ -168,18 +179,20 @@ public class ModelReader implements Serializable {
|
||||
Debug.logError(e, "Could not get resource URL", module);
|
||||
}
|
||||
|
||||
// utilTimer.timerString(" After createModelEntity -- " + i + " --");
|
||||
// utilTimer.timerString(" After createModelEntity -- " + i + " --");
|
||||
if (modelEntity != null) {
|
||||
modelEntity.setLocation(resourceLocation);
|
||||
// utilTimer.timerString(" After entityCache.put -- " + i + " --");
|
||||
// utilTimer.timerString(" After entityCache.put -- " + i + " --");
|
||||
if (isEntity) {
|
||||
if (Debug.verboseOn()) Debug.logVerbose("-- [Entity]: #" + i + ": " + entityName, module);
|
||||
if (Debug.verboseOn())
|
||||
Debug.logVerbose("-- [Entity]: #" + i + ": " + entityName, module);
|
||||
} else {
|
||||
if (Debug.verboseOn()) Debug.logVerbose("-- [ViewEntity]: #" + i + ": " + entityName, module);
|
||||
if (Debug.verboseOn())
|
||||
Debug.logVerbose("-- [ViewEntity]: #" + i + ": " + entityName, module);
|
||||
}
|
||||
} else {
|
||||
Debug.logWarning("-- -- ENTITYGEN ERROR:getModelEntity: Could not create " +
|
||||
"entity for entityName: " + entityName, module);
|
||||
"entity for entityName: " + entityName, module);
|
||||
}
|
||||
return modelEntity;
|
||||
}
|
||||
@@ -195,13 +208,13 @@ public class ModelReader implements Serializable {
|
||||
numRelations = 0;
|
||||
numAutoRelations = 0;
|
||||
|
||||
entityCache = new HashMap<String, ModelEntity>();
|
||||
List<ModelViewEntity> tempViewEntityList = new LinkedList<ModelViewEntity>();
|
||||
List<Element> tempExtendEntityElementList = new LinkedList<Element>();
|
||||
entityCache = new HashMap<>();
|
||||
List<ModelViewEntity> tempViewEntityList = new LinkedList<>();
|
||||
List<Element> tempExtendEntityElementList = new LinkedList<>();
|
||||
|
||||
UtilTimer utilTimer = new UtilTimer();
|
||||
|
||||
for (ResourceHandler entityResourceHandler: entityResourceHandlers) {
|
||||
for (ResourceHandler entityResourceHandler : entityResourceHandlers) {
|
||||
|
||||
// utilTimer.timerString("Before getDocument in file " + entityFileName);
|
||||
Document document = null;
|
||||
@@ -212,10 +225,12 @@ public class ModelReader implements Serializable {
|
||||
throw new GenericEntityConfException("Error getting document from resource handler", e);
|
||||
}
|
||||
if (document == null) {
|
||||
throw new GenericEntityConfException("Could not get document for " + entityResourceHandler.toString());
|
||||
throw new GenericEntityConfException("Could not get document for " + entityResourceHandler
|
||||
.toString());
|
||||
}
|
||||
|
||||
// utilTimer.timerString("Before getDocumentElement in " + entityResourceHandler.toString());
|
||||
// utilTimer.timerString("Before getDocumentElement in " +
|
||||
// entityResourceHandler.toString());
|
||||
Element docElement = document.getDocumentElement();
|
||||
|
||||
if (docElement == null) {
|
||||
@@ -236,8 +251,10 @@ public class ModelReader implements Serializable {
|
||||
|
||||
if ((isEntity || isViewEntity) && curChild.getNodeType() == Node.ELEMENT_NODE) {
|
||||
i++;
|
||||
ModelEntity modelEntity = buildEntity(entityResourceHandler, (Element) curChild, i, def);
|
||||
// put the view entity in a list to get ready for the second pass to populate fields...
|
||||
ModelEntity modelEntity = buildEntity(entityResourceHandler, (Element) curChild, i,
|
||||
def);
|
||||
// put the view entity in a list to get ready for the second pass to populate
|
||||
// fields...
|
||||
if (isViewEntity) {
|
||||
tempViewEntityList.add((ModelViewEntity) modelEntity);
|
||||
} else {
|
||||
@@ -250,14 +267,17 @@ public class ModelReader implements Serializable {
|
||||
} else {
|
||||
Debug.logWarning("No child nodes found.", module);
|
||||
}
|
||||
utilTimer.timerString("Finished " + entityResourceHandler.toString() + " - Total Entities: " + i + " FINISHED");
|
||||
utilTimer.timerString("Finished " + entityResourceHandler.toString() + " - Total Entities: " + i
|
||||
+ " FINISHED");
|
||||
}
|
||||
|
||||
// all entity elements in, now go through extend-entity elements and add their stuff
|
||||
for (Element extendEntityElement: tempExtendEntityElementList) {
|
||||
// all entity elements in, now go through extend-entity elements and add their
|
||||
// stuff
|
||||
for (Element extendEntityElement : tempExtendEntityElementList) {
|
||||
String entityName = UtilXml.checkEmpty(extendEntityElement.getAttribute("entity-name"));
|
||||
ModelEntity modelEntity = entityCache.get(entityName);
|
||||
if (modelEntity == null) throw new GenericEntityConfException("Entity to extend does not exist: " + entityName);
|
||||
if (modelEntity == null)
|
||||
throw new GenericEntityConfException("Entity to extend does not exist: " + entityName);
|
||||
modelEntity.addExtendEntity(this, extendEntityElement);
|
||||
}
|
||||
|
||||
@@ -266,17 +286,16 @@ public class ModelReader implements Serializable {
|
||||
while (!tempViewEntityList.isEmpty()) {
|
||||
int startSize = tempViewEntityList.size();
|
||||
Iterator<ModelViewEntity> mveIt = tempViewEntityList.iterator();
|
||||
TEMP_VIEW_LOOP:
|
||||
while (mveIt.hasNext()) {
|
||||
TEMP_VIEW_LOOP: while (mveIt.hasNext()) {
|
||||
ModelViewEntity curViewEntity = mveIt.next();
|
||||
for (ModelViewEntity.ModelMemberEntity mve: curViewEntity.getAllModelMemberEntities()) {
|
||||
for (ModelViewEntity.ModelMemberEntity mve : curViewEntity.getAllModelMemberEntities()) {
|
||||
if (!entityCache.containsKey(mve.getEntityName())) {
|
||||
continue TEMP_VIEW_LOOP;
|
||||
}
|
||||
}
|
||||
mveIt.remove();
|
||||
curViewEntity.populateFields(this);
|
||||
for (ModelViewEntity.ModelMemberEntity mve: curViewEntity.getAllModelMemberEntities()) {
|
||||
for (ModelViewEntity.ModelMemberEntity mve : curViewEntity.getAllModelMemberEntities()) {
|
||||
ModelEntity me = entityCache.get(mve.getEntityName());
|
||||
me.addViewEntity(curViewEntity);
|
||||
}
|
||||
@@ -291,13 +310,14 @@ TEMP_VIEW_LOOP:
|
||||
}
|
||||
if (!tempViewEntityList.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder("View entities reference non-existant members:\n");
|
||||
Set<String> allViews = new HashSet<String>();
|
||||
for (ModelViewEntity curViewEntity: tempViewEntityList) {
|
||||
Set<String> allViews = new HashSet<>();
|
||||
for (ModelViewEntity curViewEntity : tempViewEntityList) {
|
||||
allViews.add(curViewEntity.getEntityName());
|
||||
}
|
||||
for (ModelViewEntity curViewEntity: tempViewEntityList) {
|
||||
Set<String> perViewMissingEntities = new HashSet<String>();
|
||||
Iterator<ModelViewEntity.ModelMemberEntity> mmeIt = curViewEntity.getAllModelMemberEntities().iterator();
|
||||
for (ModelViewEntity curViewEntity : tempViewEntityList) {
|
||||
Set<String> perViewMissingEntities = new HashSet<>();
|
||||
Iterator<ModelViewEntity.ModelMemberEntity> mmeIt = curViewEntity
|
||||
.getAllModelMemberEntities().iterator();
|
||||
while (mmeIt.hasNext()) {
|
||||
ModelViewEntity.ModelMemberEntity mme = mmeIt.next();
|
||||
String memberEntityName = mme.getEntityName();
|
||||
@@ -310,8 +330,9 @@ TEMP_VIEW_LOOP:
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String perViewMissingEntity: perViewMissingEntities) {
|
||||
sb.append("\t[").append(curViewEntity.getEntityName()).append("] missing member entity [").append(perViewMissingEntity).append("]\n");
|
||||
for (String perViewMissingEntity : perViewMissingEntities) {
|
||||
sb.append("\t[").append(curViewEntity.getEntityName()).append(
|
||||
"] missing member entity [").append(perViewMissingEntity).append("]\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -319,101 +340,116 @@ TEMP_VIEW_LOOP:
|
||||
}
|
||||
|
||||
// auto-create relationships
|
||||
Set<String> orderedMessages = new TreeSet<String>();
|
||||
for (String curEntityName: new TreeSet<String>(this.getEntityNames())) {
|
||||
Set<String> orderedMessages = new TreeSet<>();
|
||||
for (String curEntityName : new TreeSet<>(this.getEntityNames())) {
|
||||
ModelEntity curModelEntity = this.getModelEntity(curEntityName);
|
||||
if (curModelEntity instanceof ModelViewEntity) {
|
||||
// for view-entities auto-create relationships for all member-entity relationships that have all corresponding fields in the view-entity
|
||||
// for view-entities auto-create relationships for all member-entity
|
||||
// relationships that have all corresponding fields in the view-entity
|
||||
|
||||
} else {
|
||||
// for entities auto-create many relationships for all type one relationships
|
||||
|
||||
// just in case we add a new relation to the same entity, keep in a separate list and add them at the end
|
||||
List<ModelRelation> newSameEntityRelations = new LinkedList<ModelRelation>();
|
||||
// just in case we add a new relation to the same entity, keep in a separate
|
||||
// list and add them at the end
|
||||
List<ModelRelation> newSameEntityRelations = new LinkedList<>();
|
||||
|
||||
Iterator<ModelRelation> relationsIter = curModelEntity.getRelationsIterator();
|
||||
while (relationsIter.hasNext()) {
|
||||
ModelRelation modelRelation = relationsIter.next();
|
||||
if (("one".equals(modelRelation.getType()) || "one-nofk".equals(modelRelation.getType())) && !modelRelation.isAutoRelation()) {
|
||||
if (("one".equals(modelRelation.getType()) || "one-nofk".equals(modelRelation
|
||||
.getType())) && !modelRelation.isAutoRelation()) {
|
||||
ModelEntity relatedEnt = null;
|
||||
try {
|
||||
relatedEnt = this.getModelEntity(modelRelation.getRelEntityName());
|
||||
} catch (GenericModelException e) {
|
||||
throw new GenericModelException("Error getting related entity [" + modelRelation.getRelEntityName() + "] definition from entity [" + curEntityName + "]", e);
|
||||
throw new GenericModelException("Error getting related entity [" + modelRelation
|
||||
.getRelEntityName() + "] definition from entity [" + curEntityName
|
||||
+ "]", e);
|
||||
}
|
||||
if (relatedEnt != null) {
|
||||
// create the new relationship even if one exists so we can show what we are looking for in the info message
|
||||
// don't do relationship to the same entity, unless title is "Parent", then do a "Child" automatically
|
||||
String title = modelRelation.getTitle();
|
||||
if (curModelEntity.getEntityName().equals(relatedEnt.getEntityName()) && "Parent".equals(title)) {
|
||||
title = "Child";
|
||||
}
|
||||
String description = "";
|
||||
String type = "";
|
||||
String relEntityName = curModelEntity.getEntityName();
|
||||
String fkName = "";
|
||||
ArrayList<ModelKeyMap> keyMaps = new ArrayList<ModelKeyMap>();
|
||||
boolean isAutoRelation = true;
|
||||
Set<String> curEntityKeyFields = new HashSet<String>();
|
||||
for (ModelKeyMap curkm : modelRelation.getKeyMaps()) {
|
||||
keyMaps.add(new ModelKeyMap(curkm.getRelFieldName(), curkm.getFieldName()));
|
||||
curEntityKeyFields.add(curkm.getFieldName());
|
||||
}
|
||||
keyMaps.trimToSize();
|
||||
// decide whether it should be one or many by seeing if the key map represents the complete pk of the relEntity
|
||||
if (curModelEntity.containsAllPkFieldNames(curEntityKeyFields)) {
|
||||
// always use one-nofk, we don't want auto-fks getting in for these automatic ones
|
||||
type = "one-nofk";
|
||||
// to keep it clean, remove any additional keys that aren't part of the PK
|
||||
List<String> curPkFieldNames = curModelEntity.getPkFieldNames();
|
||||
Iterator<ModelKeyMap> nrkmIter = keyMaps.iterator();
|
||||
while (nrkmIter.hasNext()) {
|
||||
ModelKeyMap nrkm =nrkmIter.next();
|
||||
String checkField = nrkm.getRelFieldName();
|
||||
if (!curPkFieldNames.contains(checkField)) {
|
||||
nrkmIter.remove();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
type= "many";
|
||||
}
|
||||
ModelRelation newRel = ModelRelation.create(relatedEnt, description, type, title, relEntityName, fkName, keyMaps, isAutoRelation);
|
||||
|
||||
ModelRelation existingRelation = relatedEnt.getRelation(title + curModelEntity.getEntityName());
|
||||
if (existingRelation == null) {
|
||||
numAutoRelations++;
|
||||
if (curModelEntity.getEntityName().equals(relatedEnt.getEntityName())) {
|
||||
newSameEntityRelations.add(newRel);
|
||||
} else {
|
||||
relatedEnt.addRelation(newRel);
|
||||
}
|
||||
} else {
|
||||
if (newRel.equals(existingRelation)) {
|
||||
// don't warn if the target title+entity = current title+entity
|
||||
if (Debug.infoOn() && !(title + curModelEntity.getEntityName()).equals(modelRelation.getTitle() + modelRelation.getRelEntityName())) {
|
||||
//String errorMsg = "Relation already exists to entity [] with title [" + targetTitle + "],from entity []";
|
||||
String message = "Entity [" + relatedEnt.getPackageName() + ":" + relatedEnt.getEntityName() + "] already has identical relationship to entity [" +
|
||||
curModelEntity.getEntityName() + "] title [" + title + "]; would auto-create: type [" +
|
||||
newRel.getType() + "] and fields [" + newRel.keyMapString(",", "") + "]";
|
||||
orderedMessages.add(message);
|
||||
}
|
||||
} else {
|
||||
String message = "Existing relationship with the same name, but different specs found from what would be auto-created for Entity [" + relatedEnt.getEntityName() + "] and relationship to entity [" +
|
||||
curModelEntity.getEntityName() + "] title [" + title + "]; would auto-create: type [" +
|
||||
newRel.getType() + "] and fields [" + newRel.keyMapString(",", "") + "]";
|
||||
Debug.logVerbose(message, module);
|
||||
// create the new relationship even if one exists so we can show what we are
|
||||
// looking for in the info message
|
||||
// don't do relationship to the same entity, unless title is "Parent", then do a
|
||||
// "Child" automatically
|
||||
String title = modelRelation.getTitle();
|
||||
if (curModelEntity.getEntityName().equals(relatedEnt.getEntityName()) && "Parent"
|
||||
.equals(title)) {
|
||||
title = "Child";
|
||||
}
|
||||
String description = "";
|
||||
String type = "";
|
||||
String relEntityName = curModelEntity.getEntityName();
|
||||
String fkName = "";
|
||||
ArrayList<ModelKeyMap> keyMaps = new ArrayList<>();
|
||||
boolean isAutoRelation = true;
|
||||
Set<String> curEntityKeyFields = new HashSet<>();
|
||||
for (ModelKeyMap curkm : modelRelation.getKeyMaps()) {
|
||||
keyMaps.add(new ModelKeyMap(curkm.getRelFieldName(), curkm.getFieldName()));
|
||||
curEntityKeyFields.add(curkm.getFieldName());
|
||||
}
|
||||
keyMaps.trimToSize();
|
||||
// decide whether it should be one or many by seeing if the key map represents
|
||||
// the complete pk of the relEntity
|
||||
if (curModelEntity.containsAllPkFieldNames(curEntityKeyFields)) {
|
||||
// always use one-nofk, we don't want auto-fks getting in for these automatic
|
||||
// ones
|
||||
type = "one-nofk";
|
||||
// to keep it clean, remove any additional keys that aren't part of the PK
|
||||
List<String> curPkFieldNames = curModelEntity.getPkFieldNames();
|
||||
Iterator<ModelKeyMap> nrkmIter = keyMaps.iterator();
|
||||
while (nrkmIter.hasNext()) {
|
||||
ModelKeyMap nrkm = nrkmIter.next();
|
||||
String checkField = nrkm.getRelFieldName();
|
||||
if (!curPkFieldNames.contains(checkField)) {
|
||||
nrkmIter.remove();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String errorMsg = "Could not find related entity ["
|
||||
+ modelRelation.getRelEntityName() + "], no reverse relation added.";
|
||||
Debug.logWarning(errorMsg, module);
|
||||
type = "many";
|
||||
}
|
||||
ModelRelation newRel = ModelRelation.create(relatedEnt, description, type, title,
|
||||
relEntityName, fkName, keyMaps, isAutoRelation);
|
||||
|
||||
ModelRelation existingRelation = relatedEnt.getRelation(title + curModelEntity
|
||||
.getEntityName());
|
||||
if (existingRelation == null) {
|
||||
numAutoRelations++;
|
||||
if (curModelEntity.getEntityName().equals(relatedEnt.getEntityName())) {
|
||||
newSameEntityRelations.add(newRel);
|
||||
} else {
|
||||
relatedEnt.addRelation(newRel);
|
||||
}
|
||||
} else {
|
||||
if (newRel.equals(existingRelation)) {
|
||||
// don't warn if the target title+entity = current title+entity
|
||||
if (Debug.infoOn() && !(title + curModelEntity.getEntityName()).equals(
|
||||
modelRelation.getTitle() + modelRelation.getRelEntityName())) {
|
||||
// String errorMsg = "Relation already exists to entity [] with title ["
|
||||
// + targetTitle + "],from entity []";
|
||||
String message = "Entity [" + relatedEnt.getPackageName() + ":"
|
||||
+ relatedEnt.getEntityName()
|
||||
+ "] already has identical relationship to entity [" +
|
||||
curModelEntity.getEntityName() + "] title [" + title
|
||||
+ "]; would auto-create: type [" +
|
||||
newRel.getType() + "] and fields [" + newRel.keyMapString(",",
|
||||
"") + "]";
|
||||
orderedMessages.add(message);
|
||||
}
|
||||
} else {
|
||||
String message = "Existing relationship with the same name, but different specs found from what would be auto-created for Entity ["
|
||||
+ relatedEnt.getEntityName() + "] and relationship to entity [" +
|
||||
curModelEntity.getEntityName() + "] title [" + title
|
||||
+ "]; would auto-create: type [" +
|
||||
newRel.getType() + "] and fields [" + newRel.keyMapString(",", "")
|
||||
+ "]";
|
||||
Debug.logVerbose(message, module);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newSameEntityRelations.size() > 0) {
|
||||
for (ModelRelation newRel: newSameEntityRelations) {
|
||||
for (ModelRelation newRel : newSameEntityRelations) {
|
||||
curModelEntity.addRelation(newRel);
|
||||
}
|
||||
}
|
||||
@@ -423,7 +459,9 @@ TEMP_VIEW_LOOP:
|
||||
for (String message : orderedMessages) {
|
||||
Debug.logInfo(message, module);
|
||||
}
|
||||
Debug.logInfo("Finished loading entities; #Entities=" + numEntities + " #ViewEntities=" + numViewEntities + " #Fields=" + numFields + " #Relationships=" + numRelations + " #AutoRelationships=" + numAutoRelations, module);
|
||||
Debug.logInfo("Finished loading entities; #Entities=" + numEntities + " #ViewEntities="
|
||||
+ numViewEntities + " #Fields=" + numFields + " #Relationships=" + numRelations
|
||||
+ " #AutoRelationships=" + numAutoRelations, module);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,13 +469,16 @@ TEMP_VIEW_LOOP:
|
||||
return entityCache;
|
||||
}
|
||||
|
||||
/** rebuilds the resourceHandlerEntities Map of Collections based on the current
|
||||
* entityResourceHandlerMap Map, must be done whenever a manual change is made to the
|
||||
* entityResourceHandlerMap Map after the initial load to make them consistent again.
|
||||
/**
|
||||
* rebuilds the resourceHandlerEntities Map of Collections based on the current
|
||||
* entityResourceHandlerMap Map, must be done whenever a manual change is made
|
||||
* to the entityResourceHandlerMap Map after the initial load to make them
|
||||
* consistent again.
|
||||
*/
|
||||
public void rebuildResourceHandlerEntities() {
|
||||
resourceHandlerEntities = new HashMap<ResourceHandler, Collection<String>>();
|
||||
Iterator<Map.Entry<String, ResourceHandler>> entityResourceIter = entityResourceHandlerMap.entrySet().iterator();
|
||||
resourceHandlerEntities = new HashMap<>();
|
||||
Iterator<Map.Entry<String, ResourceHandler>> entityResourceIter = entityResourceHandlerMap.entrySet()
|
||||
.iterator();
|
||||
|
||||
while (entityResourceIter.hasNext()) {
|
||||
Map.Entry<String, ResourceHandler> entry = entityResourceIter.next();
|
||||
@@ -445,7 +486,7 @@ TEMP_VIEW_LOOP:
|
||||
Collection<String> resourceHandlerEntityNames = resourceHandlerEntities.get(entry.getValue());
|
||||
|
||||
if (resourceHandlerEntityNames == null) {
|
||||
resourceHandlerEntityNames = new LinkedList<String>();
|
||||
resourceHandlerEntityNames = new LinkedList<>();
|
||||
resourceHandlerEntities.put(entry.getValue(), resourceHandlerEntityNames);
|
||||
}
|
||||
resourceHandlerEntityNames.add(entry.getKey());
|
||||
@@ -453,26 +494,34 @@ TEMP_VIEW_LOOP:
|
||||
}
|
||||
|
||||
public Iterator<ResourceHandler> getResourceHandlerEntitiesKeyIterator() {
|
||||
if (resourceHandlerEntities == null) return null;
|
||||
if (resourceHandlerEntities == null)
|
||||
return null;
|
||||
return resourceHandlerEntities.keySet().iterator();
|
||||
}
|
||||
|
||||
public Collection<String> getResourceHandlerEntities(ResourceHandler resourceHandler) {
|
||||
if (resourceHandlerEntities == null) return null;
|
||||
if (resourceHandlerEntities == null)
|
||||
return null;
|
||||
return resourceHandlerEntities.get(resourceHandler);
|
||||
}
|
||||
|
||||
public void addEntityToResourceHandler(String entityName, String loaderName, String location) {
|
||||
entityResourceHandlerMap.put(entityName, new MainResourceHandler(EntityConfig.ENTITY_ENGINE_XML_FILENAME, loaderName, location));
|
||||
entityResourceHandlerMap.put(entityName, new MainResourceHandler(EntityConfig.ENTITY_ENGINE_XML_FILENAME,
|
||||
loaderName, location));
|
||||
}
|
||||
|
||||
public ResourceHandler getEntityResourceHandler(String entityName) {
|
||||
return entityResourceHandlerMap.get(entityName);
|
||||
}
|
||||
|
||||
/** Gets an Entity object based on a definition from the specified XML Entity descriptor file.
|
||||
* @param entityName The entityName of the Entity definition to use.
|
||||
* @return An Entity object describing the specified entity of the specified descriptor file.
|
||||
/**
|
||||
* Gets an Entity object based on a definition from the specified XML Entity
|
||||
* descriptor file.
|
||||
*
|
||||
* @param entityName
|
||||
* The entityName of the Entity definition to use.
|
||||
* @return An Entity object describing the specified entity of the specified
|
||||
* descriptor file.
|
||||
*/
|
||||
public ModelEntity getModelEntity(String entityName) throws GenericEntityException {
|
||||
if (entityName == null) {
|
||||
@@ -505,7 +554,10 @@ TEMP_VIEW_LOOP:
|
||||
return modelEntity;
|
||||
}
|
||||
|
||||
/** Creates a Iterator with the entityName of each Entity defined in the specified XML Entity Descriptor file.
|
||||
/**
|
||||
* Creates a Iterator with the entityName of each Entity defined in the
|
||||
* specified XML Entity Descriptor file.
|
||||
*
|
||||
* @return A Iterator of entityName Strings
|
||||
*/
|
||||
public Iterator<String> getEntityNamesIterator() throws GenericEntityException {
|
||||
@@ -517,7 +569,10 @@ TEMP_VIEW_LOOP:
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a Set with the entityName of each Entity defined in the specified XML Entity Descriptor file.
|
||||
/**
|
||||
* Creates a Set with the entityName of each Entity defined in the specified XML
|
||||
* Entity Descriptor file.
|
||||
*
|
||||
* @return A Set of entityName Strings
|
||||
*/
|
||||
public Set<String> getEntityNames() throws GenericEntityException {
|
||||
@@ -529,10 +584,11 @@ TEMP_VIEW_LOOP:
|
||||
}
|
||||
|
||||
/** Get all entities, organized by package */
|
||||
public Map<String, TreeSet<String>> getEntitiesByPackage(Set<String> packageFilterSet, Set<String> entityFilterSet) throws GenericEntityException {
|
||||
Map<String, TreeSet<String>> entitiesByPackage = new HashMap<String, TreeSet<String>>();
|
||||
public Map<String, TreeSet<String>> getEntitiesByPackage(Set<String> packageFilterSet, Set<String> entityFilterSet)
|
||||
throws GenericEntityException {
|
||||
Map<String, TreeSet<String>> entitiesByPackage = new HashMap<>();
|
||||
|
||||
//put the entityNames TreeSets in a HashMap by packageName
|
||||
// put the entityNames TreeSets in a HashMap by packageName
|
||||
Iterator<String> ecIter = this.getEntityNames().iterator();
|
||||
while (ecIter.hasNext()) {
|
||||
String entityName = ecIter.next();
|
||||
@@ -542,24 +598,26 @@ TEMP_VIEW_LOOP:
|
||||
if (UtilValidate.isNotEmpty(packageFilterSet)) {
|
||||
// does it match any of these?
|
||||
boolean foundMatch = false;
|
||||
for (String packageFilter: packageFilterSet) {
|
||||
for (String packageFilter : packageFilterSet) {
|
||||
if (packageName.contains(packageFilter)) {
|
||||
foundMatch = true;
|
||||
}
|
||||
}
|
||||
if (!foundMatch) {
|
||||
//Debug.logInfo("Not including entity " + entityName + " becuase it is not in the package set: " + packageFilterSet, module);
|
||||
// Debug.logInfo("Not including entity " + entityName + " becuase it is not in
|
||||
// the package set: " + packageFilterSet, module);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (UtilValidate.isNotEmpty(entityFilterSet) && !entityFilterSet.contains(entityName)) {
|
||||
//Debug.logInfo("Not including entity " + entityName + " because it is not in the entity set: " + entityFilterSet, module);
|
||||
// Debug.logInfo("Not including entity " + entityName + " because it is not in
|
||||
// the entity set: " + entityFilterSet, module);
|
||||
continue;
|
||||
}
|
||||
|
||||
TreeSet<String> entities = entitiesByPackage.get(entity.getPackageName());
|
||||
if (entities == null) {
|
||||
entities = new TreeSet<String>();
|
||||
entities = new TreeSet<>();
|
||||
entitiesByPackage.put(entity.getPackageName(), entities);
|
||||
}
|
||||
entities.add(entityName);
|
||||
@@ -568,9 +626,12 @@ TEMP_VIEW_LOOP:
|
||||
return entitiesByPackage;
|
||||
}
|
||||
|
||||
/** Util method to validate an entity name; if no entity is found with the name,
|
||||
* characters are stripped from the beginning of the name until a valid entity name is found.
|
||||
* It is intended to be used to determine the entity name from a relation name.
|
||||
/**
|
||||
* Util method to validate an entity name; if no entity is found with the name,
|
||||
* characters are stripped from the beginning of the name until a valid entity
|
||||
* name is found. It is intended to be used to determine the entity name from a
|
||||
* relation name.
|
||||
*
|
||||
* @return A valid entityName or null
|
||||
*/
|
||||
public String validateEntityName(String entityName) throws GenericEntityException {
|
||||
@@ -581,18 +642,20 @@ TEMP_VIEW_LOOP:
|
||||
while (!allEntities.contains(entityName) && entityName.length() > 0) {
|
||||
entityName = entityName.substring(1);
|
||||
}
|
||||
return (entityName.length() > 0? entityName: null);
|
||||
return (entityName.length() > 0 ? entityName : null);
|
||||
}
|
||||
|
||||
ModelEntity createModelEntity(Element entityElement, UtilTimer utilTimer, ModelInfo def) {
|
||||
if (entityElement == null) return null;
|
||||
if (entityElement == null)
|
||||
return null;
|
||||
this.numEntities++;
|
||||
ModelEntity entity = new ModelEntity(this, entityElement, utilTimer, def);
|
||||
return entity;
|
||||
}
|
||||
|
||||
ModelEntity createModelViewEntity(Element entityElement, UtilTimer utilTimer, ModelInfo def) {
|
||||
if (entityElement == null) return null;
|
||||
if (entityElement == null)
|
||||
return null;
|
||||
this.numViewEntities++;
|
||||
ModelViewEntity entity = new ModelViewEntity(this, entityElement, utilTimer, def);
|
||||
return entity;
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.apache.ofbiz.entity.model;
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.ofbiz.base.util.StringUtil;
|
||||
import org.apache.ofbiz.base.util.UtilMisc;
|
||||
@@ -45,7 +46,7 @@ public final class ModelUtil {
|
||||
*/
|
||||
public static String upperFirstChar(String string) {
|
||||
if (string == null) return null;
|
||||
if (string.length() <= 1) return string.toLowerCase();
|
||||
if (string.length() <= 1) return string.toLowerCase(Locale.getDefault());
|
||||
StringBuilder sb = new StringBuilder(string);
|
||||
|
||||
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
|
||||
@@ -60,7 +61,7 @@ public final class ModelUtil {
|
||||
*/
|
||||
public static String lowerFirstChar(String string) {
|
||||
if (string == null) return null;
|
||||
if (string.length() <= 1) return string.toLowerCase();
|
||||
if (string.length() <= 1) return string.toLowerCase(Locale.getDefault());
|
||||
StringBuilder sb = new StringBuilder(string);
|
||||
|
||||
sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
|
||||
|
||||
@@ -56,8 +56,8 @@ import org.w3c.dom.NodeList;
|
||||
public class ModelViewEntity extends ModelEntity {
|
||||
public static final String module = ModelViewEntity.class.getName();
|
||||
|
||||
private static final Map<String, String> functionPrefixMap = new HashMap<String, String>();
|
||||
private static final Set<String> numericFunctionsSet = new HashSet<String>(); // names of functions that return a numeric type
|
||||
private static final Map<String, String> functionPrefixMap = new HashMap<>();
|
||||
private static final Set<String> numericFunctionsSet = new HashSet<>(); // names of functions that return a numeric type
|
||||
static {
|
||||
functionPrefixMap.put("min", "MIN(");
|
||||
functionPrefixMap.put("max", "MAX(");
|
||||
@@ -78,30 +78,30 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
/** Contains member-entity alias name definitions: key is alias, value is ModelMemberEntity */
|
||||
protected Map<String, ModelMemberEntity> memberModelMemberEntities = new HashMap<String, ModelMemberEntity>();
|
||||
protected Map<String, ModelMemberEntity> 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<ModelMemberEntity> allModelMemberEntities = new LinkedList<ModelMemberEntity>();
|
||||
protected List<ModelMemberEntity> allModelMemberEntities = new LinkedList<>();
|
||||
|
||||
/** Contains member-entity ModelEntities: key is alias, value is ModelEntity; populated with fields */
|
||||
protected Map<String, String> memberModelEntities = new HashMap<String, String>();
|
||||
protected Map<String, String> memberModelEntities = new HashMap<>();
|
||||
|
||||
/** List of alias-alls which act as a shortcut for easily pulling over member entity fields */
|
||||
protected List<ModelAliasAll> aliasAlls = new LinkedList<ModelAliasAll>();
|
||||
protected List<ModelAliasAll> aliasAlls = new LinkedList<>();
|
||||
|
||||
/** List of aliases with information in addition to what is in the standard field list */
|
||||
protected List<ModelAlias> aliases = new LinkedList<ModelAlias>();
|
||||
protected List<ModelAlias> aliases = new LinkedList<>();
|
||||
|
||||
/** List of view links to define how entities are connected (or "joined") */
|
||||
protected List<ModelViewLink> viewLinks = new LinkedList<ModelViewLink>();
|
||||
protected List<ModelViewLink> viewLinks = new LinkedList<>();
|
||||
|
||||
/** A List of the Field objects for the View Entity, one for each GROUP BY field */
|
||||
protected List<ModelField> groupBys = new LinkedList<ModelField>();
|
||||
protected List<ModelField> groupBys = new LinkedList<>();
|
||||
|
||||
/** List of field names to group by */
|
||||
protected List<String> groupByFields = new LinkedList<String>();
|
||||
protected List<String> groupByFields = new LinkedList<>();
|
||||
|
||||
protected Map<String, ModelConversion[]> conversions = new HashMap<String, ModelConversion[]>();
|
||||
protected Map<String, ModelConversion[]> conversions = new HashMap<>();
|
||||
|
||||
protected ViewEntityCondition viewEntityCondition = null;
|
||||
|
||||
@@ -256,7 +256,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public List<ModelAlias> getAliasesCopy() {
|
||||
List<ModelAlias> newList = new ArrayList<ModelAlias>(this.aliases);
|
||||
List<ModelAlias> newList = new ArrayList<>(this.aliases);
|
||||
return newList;
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public List<ModelField> getGroupBysCopy(List<ModelField> selectFields) {
|
||||
List<ModelField> newList = new ArrayList<ModelField>(this.groupBys.size());
|
||||
List<ModelField> newList = new ArrayList<>(this.groupBys.size());
|
||||
if (UtilValidate.isEmpty(selectFields)) {
|
||||
newList.addAll(this.groupBys);
|
||||
} else {
|
||||
@@ -296,7 +296,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public List<ModelViewLink> getViewLinksCopy() {
|
||||
List<ModelViewLink> newList = new ArrayList<ModelViewLink>(this.viewLinks);
|
||||
List<ModelViewLink> newList = new ArrayList<>(this.viewLinks);
|
||||
return newList;
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
|
||||
public void populateViewEntityConditionInformation(ModelFieldTypeReader modelFieldTypeReader, List<EntityCondition> whereConditions, List<EntityCondition> havingConditions, List<String> orderByList, List<String> entityAliasStack) {
|
||||
if (entityAliasStack == null) {
|
||||
entityAliasStack = new LinkedList<String>();
|
||||
entityAliasStack = new LinkedList<>();
|
||||
}
|
||||
|
||||
if (this.viewEntityCondition != null) {
|
||||
@@ -539,7 +539,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public void populateReverseLinks() {
|
||||
Map<String, List<String>> containedModelFields = new HashMap<String, List<String>>();
|
||||
Map<String, List<String>> containedModelFields = new HashMap<>();
|
||||
Iterator<ModelAlias> it = getAliasesIterator();
|
||||
while (it.hasNext()) {
|
||||
ModelViewEntity.ModelAlias alias = it.next();
|
||||
@@ -613,7 +613,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
public List<Map<String, Object>> convert(String fromEntityName, Map<String, ? extends Object> data) {
|
||||
ModelConversion[] conversions = this.conversions.get(fromEntityName);
|
||||
if (conversions == null) return null;
|
||||
List<Map<String, Object>> values = new LinkedList<Map<String, Object>>();
|
||||
List<Map<String, Object>> values = new LinkedList<>();
|
||||
for (ModelConversion conversion: conversions) {
|
||||
conversion.convert(values, data);
|
||||
}
|
||||
@@ -741,8 +741,8 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ModelMemberEntity implements Serializable {
|
||||
protected final String entityAlias;
|
||||
protected final String entityName;
|
||||
public final String entityAlias;
|
||||
public final String entityName;
|
||||
|
||||
public ModelMemberEntity(String entityAlias, String entityName) {
|
||||
this.entityAlias = entityAlias;
|
||||
@@ -759,13 +759,13 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ModelAliasAll implements Serializable, Iterable<String> {
|
||||
protected final String entityAlias;
|
||||
protected final String prefix;
|
||||
protected final Set<String> fieldsToExclude;
|
||||
protected final boolean groupBy;
|
||||
public final String entityAlias;
|
||||
public final String prefix;
|
||||
public final Set<String> fieldsToExclude;
|
||||
public final boolean groupBy;
|
||||
// is specified this alias is a calculated value; can be: min, max, sum, avg, count, count-distinct
|
||||
protected final String function;
|
||||
protected final String fieldSet;
|
||||
public final String function;
|
||||
public final String fieldSet;
|
||||
|
||||
@Deprecated
|
||||
public ModelAliasAll(String entityAlias, String prefix) {
|
||||
@@ -784,7 +784,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
this.function = function;
|
||||
this.fieldSet = fieldSet;
|
||||
if (UtilValidate.isNotEmpty(excludes)) {
|
||||
this.fieldsToExclude = new HashSet<String>(excludes.size());
|
||||
this.fieldsToExclude = new HashSet<>(excludes.size());
|
||||
this.fieldsToExclude.addAll(excludes);
|
||||
} else {
|
||||
this.fieldsToExclude = null;
|
||||
@@ -800,7 +800,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
|
||||
List<? extends Element> excludes = UtilXml.childElementList(aliasAllElement, "exclude");
|
||||
if (UtilValidate.isNotEmpty(excludes)) {
|
||||
this.fieldsToExclude = new HashSet<String>();
|
||||
this.fieldsToExclude = new HashSet<>();
|
||||
for (Element excludeElement: excludes) {
|
||||
this.fieldsToExclude.add(excludeElement.getAttribute("field").intern());
|
||||
}
|
||||
@@ -848,20 +848,20 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ModelAlias implements Serializable {
|
||||
protected final String entityAlias;
|
||||
protected final String name;
|
||||
protected final String field;
|
||||
protected final String colAlias;
|
||||
public final String entityAlias;
|
||||
public final String name;
|
||||
public final String field;
|
||||
public final String colAlias;
|
||||
// this is a Boolean object for a tri-state: null, true or false
|
||||
protected final Boolean isPk;
|
||||
protected final boolean groupBy;
|
||||
public final Boolean isPk;
|
||||
public final boolean groupBy;
|
||||
// is specified this alias is a calculated value; can be: min, max, sum, avg, count, count-distinct
|
||||
protected final String function;
|
||||
protected final String fieldSet;
|
||||
protected final boolean isFromAliasAll;
|
||||
protected ComplexAliasMember complexAliasMember;
|
||||
public final String function;
|
||||
public final String fieldSet;
|
||||
public final boolean isFromAliasAll;
|
||||
public ComplexAliasMember complexAliasMember;
|
||||
// The description for documentation purposes
|
||||
protected String description = "";
|
||||
public String description = "";
|
||||
|
||||
public ModelAlias(Element aliasElement) {
|
||||
this.entityAlias = UtilXml.checkEmpty(aliasElement.getAttribute("entity-alias")).intern();
|
||||
@@ -976,8 +976,8 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ComplexAlias implements ComplexAliasMember {
|
||||
protected final List<ComplexAliasMember> complexAliasMembers = new LinkedList<ComplexAliasMember>();
|
||||
protected final String operator;
|
||||
public final List<ComplexAliasMember> complexAliasMembers = new LinkedList<>();
|
||||
public final String operator;
|
||||
|
||||
public ComplexAlias(String operator) {
|
||||
this.operator = operator;
|
||||
@@ -1028,11 +1028,11 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ComplexAliasField implements ComplexAliasMember {
|
||||
protected final String entityAlias;
|
||||
protected final String field;
|
||||
protected final String defaultValue;
|
||||
protected final String function;
|
||||
protected final String value;
|
||||
public final String entityAlias;
|
||||
public final String field;
|
||||
public final String defaultValue;
|
||||
public final String function;
|
||||
public final String value;
|
||||
|
||||
public ComplexAliasField(Element complexAliasFieldElement) {
|
||||
this.entityAlias = complexAliasFieldElement.getAttribute("entity-alias").intern();
|
||||
@@ -1070,11 +1070,11 @@ public class ModelViewEntity extends ModelEntity {
|
||||
ModelEntity modelEntity = modelViewEntity.getAliasedEntity(entityAlias, modelReader);
|
||||
ModelField modelField = modelViewEntity.getAliasedField(modelEntity, field, modelReader);
|
||||
String colName = entityAlias + "." + modelField.getColName();
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(defaultValue)) {
|
||||
colName = "COALESCE(" + colName + "," + defaultValue + ")";
|
||||
}
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(function)) {
|
||||
String prefix = functionPrefixMap.get(function);
|
||||
if (prefix == null) {
|
||||
@@ -1083,7 +1083,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
colName = prefix + colName + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
colNameBuffer.append(colName);
|
||||
//set fieldTypeBuffer if not already set
|
||||
if (fieldTypeBuffer.length() == 0) {
|
||||
@@ -1094,11 +1094,11 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ModelViewLink implements Serializable, Iterable<ModelKeyMap> {
|
||||
protected final String entityAlias;
|
||||
protected final String relEntityAlias;
|
||||
protected final boolean relOptional;
|
||||
protected final List<ModelKeyMap> keyMaps = new LinkedList<ModelKeyMap>();
|
||||
protected final ViewEntityCondition viewEntityCondition;
|
||||
public final String entityAlias;
|
||||
public final String relEntityAlias;
|
||||
public final boolean relOptional;
|
||||
public final List<ModelKeyMap> keyMaps = new LinkedList<>();
|
||||
public final ViewEntityCondition viewEntityCondition;
|
||||
|
||||
public ModelViewLink(ModelViewEntity modelViewEntity, Element viewLinkElement) {
|
||||
this.entityAlias = UtilXml.checkEmpty(viewLinkElement.getAttribute("entity-alias")).intern();
|
||||
@@ -1107,11 +1107,12 @@ public class ModelViewEntity extends ModelEntity {
|
||||
this.relOptional = "true".equals(viewLinkElement.getAttribute("rel-optional"));
|
||||
|
||||
NodeList keyMapList = viewLinkElement.getElementsByTagName("key-map");
|
||||
for (int j = 0; j < keyMapList.getLength(); j++) {
|
||||
int keyMapLength = keyMapList.getLength();
|
||||
for (int j = 0; j < keyMapLength; j++) {
|
||||
Element keyMapElement = (Element) keyMapList.item(j);
|
||||
ModelKeyMap keyMap = new ModelKeyMap(keyMapElement);
|
||||
|
||||
if (keyMap != null) keyMaps.add(keyMap);
|
||||
keyMaps.add(keyMap);
|
||||
}
|
||||
|
||||
Element entityConditionElement = UtilXml.firstChildElement(viewLinkElement, "entity-condition");
|
||||
@@ -1177,7 +1178,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public List<ModelKeyMap> getKeyMapsCopy() {
|
||||
List<ModelKeyMap> newList = new ArrayList<ModelKeyMap>(this.keyMaps);
|
||||
List<ModelKeyMap> newList = new ArrayList<>(this.keyMaps);
|
||||
return newList;
|
||||
}
|
||||
|
||||
@@ -1187,10 +1188,10 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public final class ModelConversion implements Serializable {
|
||||
protected final String aliasName;
|
||||
protected final ModelEntity fromModelEntity;
|
||||
protected final Map<String, String> fieldMap = new HashMap<String, String>();
|
||||
protected final Set<String> wildcards = new HashSet<String>();
|
||||
public final String aliasName;
|
||||
public final ModelEntity fromModelEntity;
|
||||
public final Map<String, String> fieldMap = new HashMap<>();
|
||||
public final Set<String> wildcards = new HashSet<>();
|
||||
|
||||
public ModelConversion(String aliasName, ModelEntity fromModelEntity) {
|
||||
this.aliasName = aliasName;
|
||||
@@ -1226,7 +1227,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public void convert(List<Map<String, Object>> values, Map<String, ? extends Object> value) {
|
||||
Map<String, Object> newValue = new HashMap<String, Object>();
|
||||
Map<String, Object> newValue = new HashMap<>();
|
||||
for (Map.Entry<String, String> entry: fieldMap.entrySet()) {
|
||||
newValue.put(entry.getValue(), value.get(entry.getKey()));
|
||||
}
|
||||
@@ -1250,13 +1251,13 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ViewEntityCondition {
|
||||
protected final ModelViewEntity modelViewEntity;
|
||||
protected final ModelViewLink modelViewLink;
|
||||
protected final boolean filterByDate;
|
||||
protected final boolean distinct;
|
||||
protected final List<String> orderByList;
|
||||
protected final ViewCondition whereCondition;
|
||||
protected final ViewCondition havingCondition;
|
||||
public final ModelViewEntity modelViewEntity;
|
||||
public final ModelViewLink modelViewLink;
|
||||
public final boolean filterByDate;
|
||||
public final boolean distinct;
|
||||
public final List<String> orderByList;
|
||||
public final ViewCondition whereCondition;
|
||||
public final ViewCondition havingCondition;
|
||||
|
||||
// TODO: add programatic constructor
|
||||
public ViewEntityCondition(ModelViewEntity modelViewEntity, ModelViewLink modelViewLink, Element element) {
|
||||
@@ -1267,7 +1268,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
// process order-by
|
||||
List<? extends Element> orderByElementList = UtilXml.childElementList(element, "order-by");
|
||||
if (orderByElementList.size() > 0) {
|
||||
orderByList = new ArrayList<String>(orderByElementList.size());
|
||||
orderByList = new ArrayList<>(orderByElementList.size());
|
||||
for (Element orderByElement: orderByElementList) {
|
||||
orderByList.add(orderByElement.getAttribute("field-name"));
|
||||
}
|
||||
@@ -1299,7 +1300,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
|
||||
public EntityCondition getWhereCondition(ModelFieldTypeReader modelFieldTypeReader, List<String> entityAliasStack) {
|
||||
|
||||
List<EntityCondition> conditionList = new LinkedList<EntityCondition>();
|
||||
List<EntityCondition> conditionList = new LinkedList<>();
|
||||
if(this.filterByDate) {
|
||||
conditionList.add(EntityUtil.getFilterByDateExpr());
|
||||
}
|
||||
@@ -1324,14 +1325,14 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ViewConditionExpr implements ViewCondition {
|
||||
protected final ViewEntityCondition viewEntityCondition;
|
||||
protected final String entityAlias;
|
||||
protected final String fieldName;
|
||||
protected final EntityComparisonOperator<?, ?> operator;
|
||||
protected final String relEntityAlias;
|
||||
protected final String relFieldName;
|
||||
protected final Object value;
|
||||
protected final boolean ignoreCase;
|
||||
public final ViewEntityCondition viewEntityCondition;
|
||||
public final String entityAlias;
|
||||
public final String fieldName;
|
||||
public final EntityComparisonOperator<?, ?> operator;
|
||||
public final String relEntityAlias;
|
||||
public final String relFieldName;
|
||||
public final Object value;
|
||||
public final boolean ignoreCase;
|
||||
|
||||
// TODO: add programatic constructor
|
||||
public ViewConditionExpr(ViewEntityCondition viewEntityCondition, Element conditionExprElement) {
|
||||
@@ -1379,9 +1380,9 @@ public class ModelViewEntity extends ModelEntity {
|
||||
if ((this.operator == EntityOperator.IN || this.operator == EntityOperator.BETWEEN)
|
||||
&& value instanceof String) {
|
||||
String delim = null;
|
||||
if (((String)value).indexOf("|") >= 0) {
|
||||
if (((String) value).indexOf('|') >= 0) {
|
||||
delim = "|";
|
||||
} else if (((String)value).indexOf(",") >= 0) {
|
||||
} else if (((String) value).indexOf(',') >= 0) {
|
||||
delim = ",";
|
||||
}
|
||||
if (UtilValidate.isNotEmpty(delim)) {
|
||||
@@ -1399,7 +1400,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
if (!((this.operator == EntityOperator.IN || this.operator == EntityOperator.BETWEEN)
|
||||
&& value instanceof Collection<?>)) {
|
||||
// now to a type conversion for the target fieldName
|
||||
value = this.viewEntityCondition.modelViewEntity.convertFieldValue(lhsField, value, modelFieldTypeReader, new HashMap<String, Object>());
|
||||
value = this.viewEntityCondition.modelViewEntity.convertFieldValue(lhsField, value,modelFieldTypeReader, new HashMap<>());
|
||||
}
|
||||
|
||||
if (Debug.verboseOn()) Debug.logVerbose("[" + this.viewEntityCondition.modelViewEntity.getEntityName() + "]: Got value for fieldName [" + fieldName + "]: " + value, module);
|
||||
@@ -1439,7 +1440,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
if(this.viewEntityCondition.filterByDate) {
|
||||
List<EntityCondition> conditionList = new LinkedList<EntityCondition>();
|
||||
List<EntityCondition> conditionList = new LinkedList<>();
|
||||
conditionList.add(entityCondition);
|
||||
conditionList.add(EntityUtil.getFilterByDateExpr());
|
||||
return EntityCondition.makeCondition(conditionList, EntityOperator.AND);
|
||||
@@ -1451,9 +1452,9 @@ public class ModelViewEntity extends ModelEntity {
|
||||
}
|
||||
|
||||
public static final class ViewConditionList implements ViewCondition {
|
||||
protected final ViewEntityCondition viewEntityCondition;
|
||||
protected final List<ViewCondition> conditionList = new LinkedList<ViewCondition>();
|
||||
protected final EntityJoinOperator operator;
|
||||
public final ViewEntityCondition viewEntityCondition;
|
||||
public final List<ViewCondition> conditionList = new LinkedList<>();
|
||||
public final EntityJoinOperator operator;
|
||||
|
||||
public ViewConditionList(ViewEntityCondition viewEntityCondition, Element conditionListElement) {
|
||||
this.viewEntityCondition = viewEntityCondition;
|
||||
@@ -1497,7 +1498,7 @@ public class ModelViewEntity extends ModelEntity {
|
||||
return condition.createCondition(modelFieldTypeReader, entityAliasStack);
|
||||
}
|
||||
|
||||
List<EntityCondition> entityConditionList = new LinkedList<EntityCondition>();
|
||||
List<EntityCondition> entityConditionList = new LinkedList<>();
|
||||
for (ViewCondition curCondition: conditionList) {
|
||||
EntityCondition econd = curCondition.createCondition(modelFieldTypeReader, entityAliasStack);
|
||||
if (econd != null) {
|
||||
|
||||
Reference in New Issue
Block a user