cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r516394 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/wocompat/ test/java/org/apache/cayenne/wocompat/ test/resources/inheritance.eomodeld/
Date Fri, 09 Mar 2007 12:34:15 GMT
Author: aadamchik
Date: Fri Mar  9 04:34:12 2007
New Revision: 516394

URL: http://svn.apache.org/viewvc?view=rev&rev=516394
Log:
CAY-764 Exception when importing an EOModel with single table inheritance
(3.0 fix, with tests)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/HelperFlatEntity.plist
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableJoin.plist
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/wocompat/EOModelProcessor.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/wocompat/EOModelProcessorInheritanceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableConcreteEntityOne.plist
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/XSingleTableAbstractEntity.plist
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/index.eomodeld

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/wocompat/EOModelProcessor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/wocompat/EOModelProcessor.java?view=diff&rev=516394&r1=516393&r2=516394
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/wocompat/EOModelProcessor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/wocompat/EOModelProcessor.java
Fri Mar  9 04:34:12 2007
@@ -30,14 +30,9 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.Predicate;
-import org.apache.commons.collections.PredicateUtils;
-import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.dba.TypesMapping;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.parser.ASTDbPath;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
@@ -49,6 +44,9 @@
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.util.ResourceLocator;
 import org.apache.cayenne.wocompat.parser.Parser;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.PredicateUtils;
 
 /**
  * Class for converting stored Apple EOModel mapping files to Cayenne DataMaps.
@@ -650,50 +648,43 @@
             ObjRelationship flatRel = new ObjRelationship();
             flatRel.setName((String) relMap.get("name"));
             flatRel.setSourceEntity(e);
-            e.addRelationship(flatRel);
-
-            DbEntity dbEntity = e.getDbEntity();
-            if (dbEntity == null) {
-                // not ready to handle inheritance from abstract entities...
-                continue;
-            }
+            flatRel.setDbRelationshipPath(targetPath);
 
-            // determine DB relationship mapping...
-            Expression exp = new ASTDbPath(targetPath);
-            Iterator path = dbEntity.resolvePathComponents(exp);
-
-            DbRelationship firstRel = null;
-            DbRelationship lastRel = null;
-            while (path.hasNext()) {
-                lastRel = (DbRelationship) path.next();
-                flatRel.addDbRelationship(lastRel);
+            // find target entity
+            Map entityInfo = info;
+            StringTokenizer toks = new StringTokenizer(targetPath, ".");
+            while (toks.hasMoreTokens() && entityInfo != null) {
+                String pathComponent = toks.nextToken();
+
+                // get relationship info and reset entityInfo, so that we could use
+                // entityInfo state as an indicator of valid flat relationship enpoint
+                // outside the loop
+                Collection relationshipInfo = (Collection) entityInfo
+                        .get("relationships");
+                entityInfo = null;
 
-                if (firstRel == null) {
-                    firstRel = lastRel;
+                if (relationshipInfo == null) {
+                    break;
                 }
-            }
 
-            if ((firstRel != null) && (lastRel != null)) {
-                Collection potentialTargets = e.getDataMap().getMappedEntities(
-                        (DbEntity) lastRel.getTargetEntity());
-
-                // sanity check
-                if (potentialTargets.size() != 1) {
-                    throw new CayenneRuntimeException(
-                            "One and only one entity should be mapped"
-                                    + " to "
-                                    + lastRel.getTargetEntity().getName()
-                                    + ". Instead found : "
-                                    + potentialTargets.size());
+                Iterator rit = relationshipInfo.iterator();
+                while (rit.hasNext()) {
+                    Map pathRelationship = (Map) rit.next();
+                    if (pathComponent.equals(pathRelationship.get("name"))) {
+                        String targetName = (String) pathRelationship.get("destination");
+                        entityInfo = helper.entityPListMap(targetName);
+                        break;
+                    }
                 }
-
-                flatRel.setTargetEntity((ObjEntity) potentialTargets.iterator().next());
             }
-            else {
-                throw new CayenneRuntimeException("relationship in the path was null!");
+            
+            if(entityInfo != null) {
+                flatRel.setTargetEntityName((String) entityInfo.get("name"));
             }
-        }
+            
 
+            e.addRelationship(flatRel);
+        }
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/wocompat/EOModelProcessorInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/wocompat/EOModelProcessorInheritanceTest.java?view=diff&rev=516394&r1=516393&r2=516394
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/wocompat/EOModelProcessorInheritanceTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/wocompat/EOModelProcessorInheritanceTest.java
Fri Mar  9 04:34:12 2007
@@ -21,6 +21,7 @@
 
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.unit.BasicCase;
 
 /**
@@ -52,5 +53,17 @@
         assertEquals("CONCRETE_ENTITY_ONE", concreteE.getDbEntityName());
         assertEquals("ConcreteEntityClass", concreteE.getClassName());
         assertEquals("AbstractEntityClass", concreteE.getSuperClassName());
+    }
+    
+    public void testLoadFlattenedRelationship() throws Exception {
+        DataMap map = processor.loadEOModel("inheritance.eomodeld");
+
+        ObjEntity e1 = map.getObjEntity("HelperFlatEntity");
+        assertNotNull(e1);
+        
+        ObjRelationship fr = (ObjRelationship) e1.getRelationship("singleTables");
+        assertNotNull(fr);
+        assertEquals("singleTableJoins.toSingleTable", fr.getDbRelationshipPath());
+        assertEquals("SingleTableConcreteEntityOne", fr.getTargetEntityName());
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/HelperFlatEntity.plist
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/HelperFlatEntity.plist?view=auto&rev=516394
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/HelperFlatEntity.plist
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/HelperFlatEntity.plist
Fri Mar  9 04:34:12 2007
@@ -0,0 +1,37 @@
+{
+    attributes = (
+        {
+            columnName = PK; 
+            externalType = int; 
+            internalInfo = {"_nameInObjectStore" = "FLAT_PK"; }; 
+            name = pk; 
+            valueClassName = NSNumber; 
+            valueType = i; 
+        }
+    ); 
+    attributesUsedForLocking = (pk); 
+    className = HelperFlatEntityClass; 
+    classProperties = (singleTables); 
+    externalName = "HELPER_FLAT_ENTITY"; 
+    fetchSpecificationDictionary = {}; 
+    name = HelperFlatEntity; 
+    primaryKeyAttributes = (pk); 
+    relationships = (
+        {
+            deleteRule = EODeleteRuleCascade; 
+            destination = SingleTableJoin; 
+            isToMany = Y; 
+            joinSemantic = EOInnerJoin; 
+            joins = ({destinationAttribute = helperFlatPk; sourceAttribute = pk; }); 
+            name = singleTableJoins; 
+            ownsDestination = Y; 
+            propagatesPrimaryKey = Y; 
+        }, 
+        {
+            definition = "singleTableJoins.toSingleTable"; 
+            internalInfo = {"_nameInObjectStore" = "singleTableJoins_toSingleTable"; }; 
+            joinSemantic = EOInnerJoin; 
+            name = singleTables; 
+        }
+    ); 
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableConcreteEntityOne.plist
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableConcreteEntityOne.plist?view=diff&rev=516394&r1=516393&r2=516394
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableConcreteEntityOne.plist
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableConcreteEntityOne.plist
Fri Mar  9 04:34:12 2007
@@ -1,15 +1,6 @@
 {
     attributes = (
         {
-            allowsNull = Y; 
-            columnName = NAME; 
-            externalType = char; 
-            name = name; 
-            serverTimeZone = "America/New_York"; 
-            valueClassName = NSString; 
-            width = 200; 
-        }, 
-        {
             columnName = "HELPER_ENTITY_ID"; 
             externalType = int; 
             internalInfo = {"_nameInObjectStore" = PK; }; 
@@ -19,6 +10,15 @@
             valueType = i; 
         }, 
         {
+            allowsNull = Y; 
+            columnName = NAME; 
+            externalType = char; 
+            name = name; 
+            serverTimeZone = "America/New_York"; 
+            valueClassName = NSString; 
+            width = 200; 
+        }, 
+        {
             columnName = PK; 
             externalType = int; 
             name = pk; 
@@ -35,6 +35,16 @@
     parent = XSingleTableAbstractEntity; 
     primaryKeyAttributes = (pk); 
     relationships = (
+        {
+            deleteRule = EODeleteRuleCascade; 
+            destination = SingleTableJoin; 
+            isToMany = Y; 
+            joinSemantic = EOInnerJoin; 
+            joins = ({destinationAttribute = singleTablePk; sourceAttribute = pk; }); 
+            name = singleTableJoins; 
+            ownsDestination = Y; 
+            propagatesPrimaryKey = Y; 
+        }, 
         {
             deleteRule = EODeleteRuleCascade; 
             destination = HelperEntity; 

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableJoin.plist
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableJoin.plist?view=auto&rev=516394
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableJoin.plist
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/SingleTableJoin.plist
Fri Mar  9 04:34:12 2007
@@ -0,0 +1,40 @@
+{
+    attributes = (
+        {
+            columnName = "SINGLE_TABLE_PK"; 
+            externalType = int; 
+            name = singleTablePk; 
+            valueClassName = NSNumber; 
+            valueType = i; 
+        }, 
+        {
+            columnName = "HELPER_FLAT_PK"; 
+            externalType = int; 
+            internalInfo = {"_nameInObjectStore" = "FLAT_PK"; }; 
+            name = helperFlatPk; 
+            valueClassName = NSNumber; 
+            valueType = i; 
+        }
+    ); 
+    attributesUsedForLocking = (singleTablePk, helperFlatPk); 
+    externalName = "SINGLE_TABLE_JOIN"; 
+    fetchSpecificationDictionary = {}; 
+    name = SingleTableJoin; 
+    primaryKeyAttributes = (singleTablePk, helperFlatPk); 
+    relationships = (
+        {
+            destination = HelperFlatEntity; 
+            isToMany = N; 
+            joinSemantic = EOInnerJoin; 
+            joins = ({destinationAttribute = pk; sourceAttribute = helperFlatPk; }); 
+            name = toHelperFlatEntity; 
+        }, 
+        {
+            destination = SingleTableConcreteEntityOne; 
+            isToMany = N; 
+            joinSemantic = EOInnerJoin; 
+            joins = ({destinationAttribute = pk; sourceAttribute = singleTablePk; }); 
+            name = toSingleTable; 
+        }
+    ); 
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/XSingleTableAbstractEntity.plist
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/XSingleTableAbstractEntity.plist?view=diff&rev=516394&r1=516393&r2=516394
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/XSingleTableAbstractEntity.plist
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/XSingleTableAbstractEntity.plist
Fri Mar  9 04:34:12 2007
@@ -1,19 +1,19 @@
 {
     attributes = (
         {
+            columnName = "HELPER_ENTITY_ID"; 
+            externalType = int; 
+            name = helperEntityID; 
+            valueClassName = NSNumber; 
+            valueType = i; 
+        }, 
+        {
             allowsNull = Y; 
             columnName = NAME; 
             externalType = char; 
             name = name; 
             valueClassName = NSString; 
             width = 200; 
-        }, 
-        {
-            columnName = "HELPER_ENTITY_ID"; 
-            externalType = int; 
-            name = helperEntityID; 
-            valueClassName = NSNumber; 
-            valueType = i; 
         }, 
         {
             columnName = PK; 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/index.eomodeld
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/index.eomodeld?view=diff&rev=516394&r1=516393&r2=516394
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/index.eomodeld
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/inheritance.eomodeld/index.eomodeld
Fri Mar  9 04:34:12 2007
@@ -10,6 +10,7 @@
         }, 
         {className = DetailEntityClass; name = DetailEntity; }, 
         {className = HelperEntityClass; name = HelperEntity; }, 
+        {className = HelperFlatEntityClass; name = HelperFlatEntity; }, 
         {
             className = SingeTableConcreteEntityOneClass; 
             name = SingleTableConcreteEntityOne; 
@@ -20,6 +21,7 @@
             name = SingleTableConcreteEntityTwo; 
             parent = XSingleTableAbstractEntity; 
         }, 
+        {className = EOGenericRecord; name = SingleTableJoin; }, 
         {
             className = SingleTableAbstractEntityClass; 
             name = XSingleTableAbstractEntity; 



Mime
View raw message