svn commit: r431009 - in /incubator/ofbiz/trunk: applications/party/entitydef/ framework/common/entitydef/ framework/entity/dtd/ framework/entity/src/org/ofbiz/entity/model/ framework/security/entitydef/

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

svn commit: r431009 - in /incubator/ofbiz/trunk: applications/party/entitydef/ framework/common/entitydef/ framework/entity/dtd/ framework/entity/src/org/ofbiz/entity/model/ framework/security/entitydef/

jonesde
Author: jonesde
Date: Sat Aug 12 03:36:00 2006
New Revision: 431009

URL: http://svn.apache.org/viewvc?rev=431009&view=rev
Log:
Implemented extend-entity for entity definitions to support adding field, relation and index elements to an entity; this is now also used to support further separation of the framework from the applications

Modified:
    incubator/ofbiz/trunk/applications/party/entitydef/entitymodel.xml
    incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml
    incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
    incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
    incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java
    incubator/ofbiz/trunk/framework/security/entitydef/entitymodel.xml

Modified: incubator/ofbiz/trunk/applications/party/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/party/entitydef/entitymodel.xml?rev=431009&r1=431008&r2=431009&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/party/entitydef/entitymodel.xml (original)
+++ incubator/ofbiz/trunk/applications/party/entitydef/entitymodel.xml Sat Aug 12 03:36:00 2006
@@ -1906,5 +1906,28 @@
         <key-map field-name="partyId"/>
       </relation>
     </entity>
+    <extend-entity entity-name="CustomTimePeriod">
+        <field name="organizationPartyId" type="id"></field>
+        <relation type="one" fk-name="ORG_PRD_PARTY" title="Organization" rel-entity-name="Party">
+            <key-map field-name="organizationPartyId" rel-field-name="partyId"/>
+        </relation>
+    </extend-entity>
+    <extend-entity entity-name="UserLogin">
+        <field name="partyId" type="id"></field>
+        <relation type="one" fk-name="USER_PARTY" rel-entity-name="Party">
+            <key-map field-name="partyId"/>
+        </relation>
+        <relation type="one-nofk" rel-entity-name="Person">
+            <key-map field-name="partyId"/>
+        </relation>
+        <relation type="one-nofk" rel-entity-name="PartyGroup">
+            <key-map field-name="partyId"/>
+        </relation>
+    </extend-entity>
+    <extend-entity entity-name="UserLoginHistory">
+        <field name="partyId" type="id"></field>
+        <relation type="one" fk-name="USER_LH_PARTY" rel-entity-name="Party">
+            <key-map field-name="partyId"/>
+        </relation>
+    </extend-entity>
 </entitymodel>
-

Modified: incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml?rev=431009&r1=431008&r2=431009&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml (original)
+++ incubator/ofbiz/trunk/framework/common/entitydef/entitymodel.xml Sat Aug 12 03:36:00 2006
@@ -287,7 +287,6 @@
             title="Custom Time Period Entity">
       <field name="customTimePeriodId" type="id-ne"></field>
       <field name="parentPeriodId" type="id"></field>
-      <field name="organizationPartyId" type="id"></field>
       <field name="periodTypeId" type="id"></field>
       <field name="periodNum" type="numeric"></field>
       <field name="periodName" type="name"></field>
@@ -297,9 +296,6 @@
       <prim-key field="customTimePeriodId"/>
       <relation type="one" fk-name="ORG_PRD_PARPER" title="Parent" rel-entity-name="CustomTimePeriod">
         <key-map field-name="parentPeriodId" rel-field-name="customTimePeriodId"/>
-      </relation>
-      <relation type="one" fk-name="ORG_PRD_PARTY" title="Organization" rel-entity-name="Party">
-        <key-map field-name="organizationPartyId" rel-field-name="partyId"/>
       </relation>
       <relation type="one" fk-name="ORG_PRD_PERTYP" rel-entity-name="PeriodType">
         <key-map field-name="periodTypeId"/>

Modified: incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd?rev=431009&r1=431008&r2=431009&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd (original)
+++ incubator/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd Sat Aug 12 03:36:00 2006
@@ -36,6 +36,7 @@
                 <xs:choice minOccurs="0" maxOccurs="unbounded">
                     <xs:element ref="entity"/>
                     <xs:element ref="view-entity"/>
+                    <xs:element ref="extend-entity"/>
                 </xs:choice>
             </xs:sequence>
         </xs:complexType>
@@ -372,5 +373,19 @@
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
+    </xs:attributeGroup>
+
+    <xs:element name="extend-entity">
+        <xs:complexType>
+            <xs:sequence>
+                <xs:element minOccurs="0" maxOccurs="unbounded" ref="field"/>
+                <xs:element minOccurs="0" maxOccurs="unbounded" ref="relation"/>
+                <xs:element minOccurs="0" maxOccurs="unbounded" ref="index"/>
+            </xs:sequence>
+            <xs:attributeGroup ref="attlist.extend-entity"/>
+        </xs:complexType>
+    </xs:element>
+    <xs:attributeGroup name="attlist.extend-entity">
+        <xs:attribute type="xs:string" name="entity-name" use="required"/>
     </xs:attributeGroup>
 </xs:schema>

Modified: incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=431009&r1=431008&r2=431009&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original)
+++ incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Sat Aug 12 03:36:00 2006
@@ -139,9 +139,11 @@
         this.populateBasicInfo(entityElement);
 
         if (utilTimer != null) utilTimer.timerString("  createModelEntity: before fields");
-        NodeList fieldList = entityElement.getElementsByTagName("field");
-        for (int i = 0; i < fieldList.getLength(); i++) {
-            ModelField field = reader.createModelField((Element) fieldList.item(i));
+        List fieldElementList = UtilXml.childElementList(entityElement, "field");
+        Iterator fieldElementIter = fieldElementList.iterator();
+        while (fieldElementIter.hasNext()) {
+            Element fieldElement = (Element) fieldElementIter.next();
+            ModelField field = reader.createModelField(fieldElement);
             if (field != null) {
                 field.setModelEntity(this);
                 this.fields.add(field);
@@ -191,15 +193,17 @@
         }
 
         if (utilTimer != null) utilTimer.timerString("  createModelEntity: before prim-keys");
-        NodeList pkList = entityElement.getElementsByTagName("prim-key");
-        for (int i = 0; i < pkList.getLength(); i++) {
-            ModelField field = reader.findModelField(this, ((Element) pkList.item(i)).getAttribute("field"));
+        List pkElementList = UtilXml.childElementList(entityElement, "prim-key");
+        Iterator pkElementIter = pkElementList.iterator();
+        while (pkElementIter.hasNext()) {
+            Element pkElement = (Element) pkElementIter.next();
+            ModelField field = reader.findModelField(this, pkElement.getAttribute("field"));
             if (field != null) {
                 this.pks.add(field);
                 field.isPk = true;
             } else {
                 Debug.logError("[ModelReader.createModelEntity] ERROR: Could not find field \"" +
-                    ((Element) pkList.item(i)).getAttribute("field") + "\" specified in a prim-key", module);
+                        pkElement.getAttribute("field") + "\" specified in a prim-key", module);
             }
         }
 
@@ -246,29 +250,29 @@
         this.autoClearCache = UtilXml.checkBoolean(entityElement.getAttribute("auto-clear-cache"), true);
     }
 
+
     protected void populateRelated(ModelReader reader, Element entityElement) {
-        NodeList relationList = entityElement.getElementsByTagName("relation");
-        for (int i = 0; i < relationList.getLength(); i++) {
-            Element relationElement = (Element) relationList.item(i);
-            if (relationElement.getParentNode() == entityElement) {
-                ModelRelation relation = reader.createRelation(this, relationElement);
-                if (relation != null) {
-                    relation.setModelEntity(this);
-                    this.relations.add(relation);
-                }
+        List relationElementList = UtilXml.childElementList(entityElement, "relation");
+        Iterator relationElementIter = relationElementList.iterator();
+        while (relationElementIter.hasNext()) {
+            Element relationElement = (Element) relationElementIter.next();
+            ModelRelation relation = reader.createRelation(this, relationElement);
+            if (relation != null) {
+                relation.setModelEntity(this);
+                this.relations.add(relation);
             }
         }
     }
 
+
     protected void populateIndexes(Element entityElement) {
-        NodeList indexList = entityElement.getElementsByTagName("index");
-        for (int i = 0; i < indexList.getLength(); i++) {
-            Element indexElement = (Element) indexList.item(i);
-            if (indexElement.getParentNode() == entityElement) {
-                ModelIndex index = new ModelIndex(this, indexElement);
-                index.setModelEntity(this);
-                this.indexes.add(index);
-            }
+        List indexElementList = UtilXml.childElementList(entityElement, "index");
+        Iterator indexElementIter = indexElementList.iterator();
+        while (indexElementIter.hasNext()) {
+            Element indexElement = (Element) indexElementIter.next();
+            ModelIndex index = new ModelIndex(this, indexElement);
+            index.setModelEntity(this);
+            this.indexes.add(index);
         }
     }
 
@@ -283,8 +287,29 @@
         return true;
     }
 
+
+    public void addExtendEntity(ModelReader reader, Element extendEntityElement) {
+        List fieldElementList = UtilXml.childElementList(extendEntityElement, "field");
+        Iterator fieldElementIter = fieldElementList.iterator();
+        while (fieldElementIter.hasNext()) {
+            Element fieldElement = (Element) fieldElementIter.next();
+            // TODO: should we look for existing fields of the same name here? for now just add to list...
+            ModelField field = reader.createModelField(fieldElement);
+            if (field != null) {
+                field.setModelEntity(this);
+                this.fields.add(field);
+                // this will always be true for now as extend-entity fielsd are always nonpks
+                if (!field.isPk) this.nopks.add(field);
+            }
+        }
+        
+        this.populateRelated(reader, extendEntityElement);
+        this.populateIndexes(extendEntityElement);
+    }
+    
     // ===== GETTERS/SETTERS =====
 
+    
     public ModelReader getModelReader() {
         return modelReader;
     }

Modified: incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java?rev=431009&r1=431008&r2=431009&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java (original)
+++ incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelReader.java Sat Aug 12 03:36:00 2006
@@ -155,6 +155,7 @@
 
                     entityCache = FastMap.newInstance();
                     List tempViewEntityList = FastList.newInstance();
+                    List tempExtendEntityElementList = FastList.newInstance();
 
                     UtilTimer utilTimer = new UtilTimer();
                     
@@ -193,11 +194,12 @@
                             do {
                                 boolean isEntity = "entity".equals(curChild.getNodeName());
                                 boolean isViewEntity = "view-entity".equals(curChild.getNodeName());
+                                boolean isExtendEntity = "extend-entity".equals(curChild.getNodeName());
 
                                 if ((isEntity || isViewEntity) && curChild.getNodeType() == Node.ELEMENT_NODE) {
                                     i++;
-                                    Element curEntity = (Element) curChild;
-                                    String entityName = UtilXml.checkEmpty(curEntity.getAttribute("entity-name"));
+                                    Element curEntityElement = (Element) curChild;
+                                    String entityName = UtilXml.checkEmpty(curEntityElement.getAttribute("entity-name"));
 
                                     // add entityName to appropriate resourceHandlerEntities collection
                                     Collection resourceHandlerEntityNames = (Collection) resourceHandlerEntities.get(entityResourceHandler);
@@ -224,19 +226,18 @@
                                     // utilTimer.timerString("  After entityEntityName -- " + i + " --");
                                     // ModelEntity entity = createModelEntity(curEntity, utilTimer);
 
-                                    ModelEntity entity = null;
-
+                                    ModelEntity modelEntity = null;
                                     if (isEntity) {
-                                        entity = createModelEntity(curEntity, null, def);
+                                        modelEntity = createModelEntity(curEntityElement, null, def);
                                     } else {
-                                        entity = createModelViewEntity(curEntity, null, def);
+                                        modelEntity = createModelViewEntity(curEntityElement, null, def);
                                         // put the view entity in a list to get ready for the second pass to populate fields...
-                                        tempViewEntityList.add(entity);
+                                        tempViewEntityList.add(modelEntity);
                                     }
 
                                     // utilTimer.timerString("  After createModelEntity -- " + i + " --");
-                                    if (entity != null) {
-                                        entityCache.put(entityName, entity);
+                                    if (modelEntity != null) {
+                                        entityCache.put(entityName, modelEntity);
                                         // utilTimer.timerString("  After entityCache.put -- " + i + " --");
                                         if (isEntity) {
                                             if (Debug.verboseOn()) Debug.logVerbose("-- [Entity]: #" + i + ": " + entityName, module);
@@ -248,6 +249,8 @@
                                             "entity for entityName: " + entityName, module);
                                     }
 
+                                } else if (isExtendEntity && curChild.getNodeType() == Node.ELEMENT_NODE) {
+                                    tempExtendEntityElementList.add(curChild);
                                 }
                             } while ((curChild = curChild.getNextSibling()) != null);
                         } else {
@@ -255,15 +258,28 @@
                         }
                         utilTimer.timerString("Finished " + entityResourceHandler.toString() + " - Total Entities: " + i + " FINISHED");
                     }
+                    
+                    // all entity elements in, now go through extend-entity elements and add their stuff
+                    Iterator tempExtendEntityElementIter = tempExtendEntityElementList.iterator();
+                    while (tempExtendEntityElementIter.hasNext()) {
+                        Element extendEntityElement = (Element) tempExtendEntityElementIter.next();
+                        String entityName = UtilXml.checkEmpty(extendEntityElement.getAttribute("entity-name"));
+                        ModelEntity modelEntity = (ModelEntity) entityCache.get(entityName);
+                        modelEntity.addExtendEntity(this, extendEntityElement);
+                    }
 
                     // do a pass on all of the view entities now that all of the entities have
                     // loaded and populate the fields
-                    for (int velInd = 0; velInd < tempViewEntityList.size(); velInd++) {
-                        ModelViewEntity curViewEntity = (ModelViewEntity) tempViewEntityList.get(velInd);
+                    Iterator tempViewEntityIter = tempViewEntityList.iterator();
+                    while (tempViewEntityIter.hasNext()) {
+                        ModelViewEntity curViewEntity = (ModelViewEntity) tempViewEntityIter.next();
+                        
                         curViewEntity.populateFields(this);
                         List memberEntities = curViewEntity.getAllModelMemberEntities();
-                        for (int j = 0; j < memberEntities.size(); j++) {
-                            ModelViewEntity.ModelMemberEntity mve = (ModelViewEntity.ModelMemberEntity) memberEntities.get(j);
+                        Iterator memberEntityIter = memberEntities.iterator();
+                        while (memberEntityIter.hasNext()) {
+                            ModelViewEntity.ModelMemberEntity mve = (ModelViewEntity.ModelMemberEntity) memberEntityIter.next();
+                            
                             ModelEntity me = (ModelEntity) entityCache.get(mve.getEntityName());
                             if (me == null) throw new GenericEntityConfException("View " + curViewEntity.getEntityName() + " references non-existant entity: " + mve.getEntityName());
                             me.addViewEntity(curViewEntity);

Modified: incubator/ofbiz/trunk/framework/security/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/security/entitydef/entitymodel.xml?rev=431009&r1=431008&r2=431009&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/security/entitydef/entitymodel.xml (original)
+++ incubator/ofbiz/trunk/framework/security/entitydef/entitymodel.xml Sat Aug 12 03:36:00 2006
@@ -42,7 +42,6 @@
             package-name="org.ofbiz.security.login"
             title="User Login Entity">
       <field name="userLoginId" type="id-vlong-ne"></field>
-      <field name="partyId" type="id"></field>
       <field name="currentPassword" type="short-varchar"></field>
       <field name="passwordHint" type="description"></field>
       <field name="isSystem" type="indicator"></field>
@@ -53,15 +52,6 @@
       <field name="disabledDateTime" type="date-time"></field>
       <field name="successiveFailedLogins" type="numeric"></field>
       <prim-key field="userLoginId"/>
-      <relation type="one" fk-name="USER_PARTY" rel-entity-name="Party">
-        <key-map field-name="partyId"/>
-      </relation>
-      <relation type="one-nofk" rel-entity-name="Person">
-        <key-map field-name="partyId"/>
-      </relation>
-      <relation type="one-nofk" rel-entity-name="PartyGroup">
-        <key-map field-name="partyId"/>
-      </relation>
     </entity>
     <entity entity-name="UserLoginHistory"
             package-name="org.ofbiz.security.login"
@@ -71,7 +61,6 @@
       <field name="visitId" type="id"></field>
       <field name="fromDate" type="date-time"></field>
       <field name="thruDate" type="date-time"></field>
-      <field name="partyId" type="id"></field>
       <field name="passwordUsed" type="short-varchar" encrypt="true"></field>
       <field name="successfulLogin" type="indicator"></field>
       <prim-key field="userLoginId"/>
@@ -79,9 +68,6 @@
       <relation type="one" fk-name="USER_LH_USER" rel-entity-name="UserLogin">
         <key-map field-name="userLoginId"/>
       </relation>
-      <relation type="one" fk-name="USER_LH_PARTY" rel-entity-name="Party">
-        <key-map field-name="partyId"/>
-      </relation>
     </entity>
     <entity entity-name="UserLoginSession"
             package-name="org.ofbiz.security.login"
@@ -163,4 +149,3 @@
       </relation>
     </entity>    
 </entitymodel>
-