svn commit: r430913 - in /incubator/ofbiz/trunk/framework: entity/dtd/entitymodel.xsd entity/src/org/ofbiz/entity/model/ModelViewEntity.java example/entitydef/entitygroup.xml example/entitydef/entitymodel.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r430913 - in /incubator/ofbiz/trunk/framework: entity/dtd/entitymodel.xsd entity/src/org/ofbiz/entity/model/ModelViewEntity.java example/entitydef/entitygroup.xml example/entitydef/entitymodel.xml

jonesde
Author: jonesde
Date: Fri Aug 11 16:04:08 2006
New Revision: 430913

URL: http://svn.apache.org/viewvc?rev=430913&view=rev
Log:
Added example view-entity, including a complex-alias to test that; based on that in the Entity Engine fixed some stuff that is part of the caching code that was breaking things on startup; the conversion stuff that is part of the entity cache is now just disabled (and with a TODO in the code) for field aliases in a view entity that are complex aliases (ie made of multiple fields), to implement that more expression evaluation will have to be done

Modified:
    incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
    incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
    incubator/ofbiz/trunk/framework/example/entitydef/entitygroup.xml
    incubator/ofbiz/trunk/framework/example/entitydef/entitymodel.xml

Modified: incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd?rev=430913&r1=430912&r2=430913&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd (original)
+++ incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd Fri Aug 11 16:04:08 2006
@@ -289,7 +289,7 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.alias">
-        <xs:attribute type="xs:string" name="entity-alias" use="required"/>
+        <xs:attribute type="xs:string" name="entity-alias"/>
         <xs:attribute type="xs:string" name="name" use="required"/>
         <xs:attribute type="xs:string" name="field"/>
         <xs:attribute type="xs:string" name="col-alias"/>

Modified: incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java?rev=430913&r1=430912&r2=430913&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java (original)
+++ incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Fri Aug 11 16:04:08 2006
@@ -24,16 +24,16 @@
 package org.ofbiz.entity.model;
 
 import java.io.Serializable;
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilTimer;
 import org.ofbiz.base.util.UtilValidate;
@@ -45,17 +45,11 @@
 
 /**
  * This class extends ModelEntity and provides additional information appropriate to view entities
- *
- * @author     <a href="mailto:[hidden email]">David E. Jones</a>
- * @author     <a href="mailto:[hidden email]">Andy Zeneski</a>
- * @author     <a href="mailto:[hidden email]">Peter Moon</a>    
- * @version    $Rev$
- * @since      2.0
  */
 public class ModelViewEntity extends ModelEntity {
     public static final String module = ModelViewEntity.class.getName();
 
-    public static Map functionPrefixMap = new HashMap();
+    public static Map functionPrefixMap = FastMap.newInstance();
     static {
         functionPrefixMap.put("min", "MIN(");
         functionPrefixMap.put("max", "MAX(");
@@ -68,27 +62,27 @@
     }
 
     /** Contains member-entity alias name definitions: key is alias, value is ModelMemberEntity */
-    protected Map memberModelMemberEntities = new HashMap();
+    protected Map memberModelMemberEntities = FastMap.newInstance();
 
     /** A list of all ModelMemberEntity entries; this is mainly used to preserve the original order of member entities from the XML file */
-    protected List allModelMemberEntities = new LinkedList();
+    protected List allModelMemberEntities = FastList.newInstance();
 
     /** Contains member-entity ModelEntities: key is alias, value is ModelEntity; populated with fields */
     protected Map memberModelEntities = null;
 
     /** List of alias-alls which act as a shortcut for easily pulling over member entity fields */
-    protected List aliasAlls = new ArrayList();
+    protected List aliasAlls = FastList.newInstance();
 
     /** List of aliases with information in addition to what is in the standard field list */
-    protected List aliases = new ArrayList();
+    protected List aliases = FastList.newInstance();
 
     /** List of view links to define how entities are connected (or "joined") */
-    protected List viewLinks = new ArrayList();
+    protected List viewLinks = FastList.newInstance();
 
     /** A List of the Field objects for the View Entity, one for each GROUP BY field */
-    protected List groupBys = new ArrayList();
+    protected List groupBys = FastList.newInstance();
 
-    protected Map conversions = new HashMap();
+    protected Map conversions = FastMap.newInstance();
 
     public ModelViewEntity(ModelReader reader, Element entityElement, UtilTimer utilTimer, ModelInfo def) {
         super(reader, entityElement, def);
@@ -189,7 +183,7 @@
 
     public ModelEntity getMemberModelEntity(String alias) {
         if (this.memberModelEntities == null) {
-            this.memberModelEntities = new HashMap();
+            this.memberModelEntities = FastMap.newInstance();
             populateFields(this.getModelReader());
         }
         return (ModelEntity) this.memberModelEntities.get(alias);
@@ -243,11 +237,15 @@
     }
 
     public List getAliasesCopy() {
-        return new ArrayList(this.aliases);
+        List newList = FastList.newInstance();
+        newList.addAll(this.aliases);
+        return newList;
     }
 
     public List getGroupBysCopy() {
-        return new ArrayList(this.groupBys);
+        List newList = FastList.newInstance();
+        newList.addAll(this.groupBys);
+        return newList;
     }
 
     /** List of view links to define how entities are connected (or "joined") */
@@ -264,7 +262,9 @@
     }
 
     public List getViewLinksCopy() {
-        return new ArrayList(this.viewLinks);
+        List newList = FastList.newInstance();
+        newList.addAll(this.viewLinks);
+        return newList;
     }
 
     public void addViewLink(ModelViewLink viewLink) {
@@ -336,7 +336,7 @@
     
     public void populateFieldsBasic(ModelReader modelReader) {
         if (this.memberModelEntities == null) {
-            this.memberModelEntities = new HashMap();
+            this.memberModelEntities = FastMap.newInstance();
         }
 
         Iterator meIter = memberModelMemberEntities.entrySet().iterator();
@@ -438,13 +438,14 @@
     protected ModelConversion getOrCreateModelConversion(String aliasName) {
         ModelEntity member = getMemberModelEntity(aliasName);
         if (member == null) {
-            Debug.logWarning("No member found for aliasName - " + aliasName, module);
-            throw new RuntimeException("Cannot create View Entity");
+            String errMsg = "No member found for aliasName - " + aliasName;
+            Debug.logWarning(errMsg, module);
+            throw new RuntimeException("Cannot create View Entity: " + errMsg);
         }
         
-        Map aliasConversions = (HashMap) conversions.get(member.getEntityName());
+        Map aliasConversions = (Map) conversions.get(member.getEntityName());
         if (aliasConversions == null) {
-            aliasConversions = new HashMap();
+            aliasConversions = FastMap.newInstance();
             conversions.put(member.getEntityName(), aliasConversions);
         }
         ModelConversion conversion = (ModelConversion) aliasConversions.get(aliasName);
@@ -456,18 +457,21 @@
     }
 
     public void populateReverseLinks() {
-        Map containedModelFields = new HashMap();
+        Map containedModelFields = FastMap.newInstance();
         Iterator it = getAliasesIterator();
         while (it.hasNext()) {
             ModelViewEntity.ModelAlias alias = (ModelViewEntity.ModelAlias) it.next();
-            ModelEntity member = getMemberModelEntity(alias.getEntityAlias());
-            ModelConversion conversion = getOrCreateModelConversion(alias.getEntityAlias());
-            conversion.addConversion(alias.getField(), alias.getName());
-            ModelField field = (ModelField) member.getField(alias.getField());
+            if (alias.isComplexAlias()) {
+                // TODO: conversion for complex-alias needs to be implemented for cache and in-memory eval stuff to work correctly
+                Debug.logWarning("Conversion for complex-alias needs to be implemented for cache and in-memory eval stuff to work correctly, will not work for alias: " + alias.getName() + " of view-entity " + this.getEntityName(), module);
+            } else {
+                ModelConversion conversion = getOrCreateModelConversion(alias.getEntityAlias());
+                conversion.addConversion(alias.getField(), alias.getName());
+            }
 
-            List aliases = (List)containedModelFields.get(alias.getField());
+            List aliases = (List) containedModelFields.get(alias.getField());
             if (aliases == null) {
-                aliases = new ArrayList();
+                aliases = FastList.newInstance();
                 containedModelFields.put(alias.getField(), aliases);
             }
             aliases.add(alias.getName());
@@ -534,7 +538,7 @@
         Map foo = (Map) conversions.get(fromEntityName);
         if (foo == null) return null;
         Iterator it = foo.values().iterator();
-        List values = new ArrayList(foo.size());
+        List values = FastList.newInstance();
         while (it.hasNext()) {
             ModelConversion conversion = (ModelConversion) it.next();
             values.add(conversion.convert(data));
@@ -808,7 +812,7 @@
     }
     
     public static class ComplexAlias implements ComplexAliasMember {
-        protected List complexAliasMembers = new LinkedList();
+        protected List complexAliasMembers = FastList.newInstance();
         protected String operator;
         
         public ComplexAlias(String operator) {
@@ -908,7 +912,7 @@
         protected String entityAlias = "";
         protected String relEntityAlias = "";
         protected boolean relOptional = false;
-        protected List keyMaps = new ArrayList();
+        protected List keyMaps = FastList.newInstance();
 
         protected ModelViewLink() {}
 
@@ -961,14 +965,16 @@
         }
 
         public List getKeyMapsCopy() {
-            return new ArrayList(this.keyMaps);
+            List newList = FastList.newInstance();
+            newList.addAll(this.keyMaps);
+            return newList;
         }
     }
 
     public class ModelConversion implements Serializable {
         protected String aliasName;
         protected ModelEntity fromModelEntity;
-        protected Map fieldMap = new HashMap();
+        protected Map fieldMap = FastMap.newInstance();
         protected Set wildcards = new HashSet();
 
         public ModelConversion(String aliasName, ModelEntity fromModelEntity) {
@@ -1002,7 +1008,7 @@
         }
 
         public Map convert(Map values) {
-            Map newValues = new HashMap(fieldMap.size() + wildcards.size());
+            Map newValues = FastMap.newInstance();
             Iterator it = fieldMap.entrySet().iterator();
             while (it.hasNext()) {
                 Map.Entry entry = (Map.Entry) it.next();

Modified: incubator/ofbiz/trunk/framework/example/entitydef/entitygroup.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/example/entitydef/entitygroup.xml?rev=430913&r1=430912&r2=430913&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/example/entitydef/entitygroup.xml (original)
+++ incubator/ofbiz/trunk/framework/example/entitydef/entitygroup.xml Fri Aug 11 16:04:08 2006
@@ -24,6 +24,7 @@
     <entity-group group="org.ofbiz" entity="Example"/>
     <entity-group group="org.ofbiz" entity="ExampleItem"/>
     <entity-group group="org.ofbiz" entity="ExampleStatus"/>
+    <entity-group group="org.ofbiz" entity="ExampleStatusDetail"/>
     <entity-group group="org.ofbiz" entity="ExampleType"/>
 
     <!-- ========================================================= -->

Modified: incubator/ofbiz/trunk/framework/example/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/example/entitydef/entitymodel.xml?rev=430913&r1=430912&r2=430913&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/example/entitydef/entitymodel.xml (original)
+++ incubator/ofbiz/trunk/framework/example/entitydef/entitymodel.xml Fri Aug 11 16:04:08 2006
@@ -37,9 +37,7 @@
     <!-- org.ofbiz.example.example -->
     <!-- ========================================================= -->
     
-    <entity entity-name="Example"
-        package-name="org.ofbiz.example.example"
-        title="Example Entity">
+    <entity entity-name="Example" package-name="org.ofbiz.example.example" title="Example Entity">
         <field name="exampleId" type="id-ne"><!-- primary sequenced ID --></field>
         <field name="exampleTypeId" type="id-ne"></field>
         <field name="statusId" type="id-ne"></field>
@@ -57,9 +55,7 @@
             <key-map field-name="statusId"/>
         </relation>
     </entity>
-    <entity entity-name="ExampleItem"
-        package-name="org.ofbiz.example.example"
-        title="Example Item Entity">
+    <entity entity-name="ExampleItem" package-name="org.ofbiz.example.example" title="Example Item Entity">
         <field name="exampleId" type="id-ne"></field>
         <field name="exampleItemSeqId" type="id-ne"><!-- secondary sequenced ID --></field>
         <field name="description" type="description"></field>
@@ -71,9 +67,7 @@
             <key-map field-name="amountUomId" rel-field-name="uomId"/>
         </relation>
     </entity>
-    <entity entity-name="ExampleStatus"
-        package-name="org.ofbiz.example.example"
-        title="Example Status Entity">
+    <entity entity-name="ExampleStatus" package-name="org.ofbiz.example.example" title="Example Status Entity">
         <field name="exampleId" type="id-ne"></field>
         <field name="statusDate" type="date-time"></field>
         <field name="statusId" type="id-ne"></field>
@@ -86,9 +80,25 @@
             <key-map field-name="statusId"/>
         </relation>
     </entity>
-    <entity entity-name="ExampleType"
-        package-name="org.ofbiz.example.example"
-        title="Example Type Entity">
+    <view-entity entity-name="ExampleStatusDetail" package-name="org.ofbiz.example.example">
+        <member-entity entity-alias="EXPL" entity-name="Example"/>
+        <member-entity entity-alias="EXST" entity-name="ExampleStatus"/>
+        <alias-all entity-alias="EXPL">
+            <exclude field="statusId"/>
+        </alias-all>
+        <alias-all entity-alias="EXST"/>
+        <alias entity-alias="EXPL" name="currentStatusId" field="statusId"/>
+        <alias name="statusDelay">
+            <complex-alias operator="-">
+                <complex-alias-field entity-alias="EXST" field="statusDate"/>
+                <complex-alias-field entity-alias="EXPL" field="exampleDate"/>
+            </complex-alias>
+        </alias>
+        <view-link entity-alias="EXPL" rel-entity-alias="EXST">
+            <key-map field-name="exampleId"/>
+        </view-link>
+    </view-entity>
+    <entity entity-name="ExampleType" package-name="org.ofbiz.example.example" title="Example Type Entity">
         <field name="exampleTypeId" type="id-ne"></field>
         <field name="parentTypeId" type="id"></field>
         <field name="description" type="description"></field>