cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r516390 - /cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/wocompat/EOModelProcessor.java
Date Fri, 09 Mar 2007 12:31:41 GMT
Author: aadamchik
Date: Fri Mar  9 04:31:40 2007
New Revision: 516390

URL: http://svn.apache.org/viewvc?view=rev&rev=516390
Log:
CAY-764 Exception when importing an EOModel with single table inheritance - 2.0 fix

Modified:
    cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/wocompat/EOModelProcessor.java

Modified: cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/wocompat/EOModelProcessor.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/wocompat/EOModelProcessor.java?view=diff&rev=516390&r1=516389&r2=516390
==============================================================================
--- cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/wocompat/EOModelProcessor.java
(original)
+++ cayenne/main/branches/STABLE-2.0/cayenne/cayenne-java/src/cayenne/java/org/apache/cayenne/wocompat/EOModelProcessor.java
Fri Mar  9 04:31:40 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);
+        }
     }
 
     /**



Mime
View raw message