cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r928492 - in /cayenne/main/branches/STABLE-3.0: docs/doc/src/main/resources/RELEASE-NOTES.txt framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
Date Sun, 28 Mar 2010 20:29:56 GMT
Author: aadamchik
Date: Sun Mar 28 20:29:55 2010
New Revision: 928492

URL: http://svn.apache.org/viewvc?rev=928492&view=rev
Log:
CAY-1405  Exception when attempting to "Infer Relationships"

Modified:
    cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java

Modified: cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=928492&r1=928491&r2=928492&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt Sun Mar
28 20:29:55 2010
@@ -27,6 +27,7 @@ CAY-1397 ROP: Missing the COMMIT state w
 CAY-1400 lazyInitParentDomainName will become null when using Child Context
 CAY-1401 Cache group removed from modeler query
 CAY-1404 ClassCastException during ObjectDetachOperation
+CAY-1405 Exception when attempting to "Infer Relationships"
 CAY-1409 Pkgenerator is accessed needlessly for join tables with own database generated PK
 
 ----------------------------------

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java?rev=928492&r1=928491&r2=928492&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
Sun Mar 28 20:29:55 2010
@@ -20,8 +20,8 @@ package org.apache.cayenne.modeler.dialo
 
 import java.awt.Component;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -58,7 +58,6 @@ public class InferRelationshipsControlle
         this.dataMap = dataMap;
         this.entities = new ArrayList(dataMap.getDbEntities());
         this.selectedEntities = new HashSet();
-
     }
 
     public void setRelationships() {
@@ -73,25 +72,28 @@ public class InferRelationshipsControlle
     }
 
     public void createRelationships(DbEntity entity) {
-        Collection<DbAttribute> attr = entity.getAttributes();
 
-        for (DbAttribute attribute : attr) {
+        for (DbAttribute attribute : entity.getAttributes()) {
+
+            for (DbEntity targetEntity : entities) {
+                // TODO: should we handle relationships to self??
+                if (targetEntity == entity) {
+                    continue;
+                }
+
+                if (attribute.getName().equalsIgnoreCase(targetEntity.getName() + "_ID")
+                        && !attribute.isPrimaryKey()
+                        && !targetEntity.getAttributes().isEmpty()) {
 
-            for (DbEntity myEntity : entities) {
-                if ((attribute.getName().equalsIgnoreCase(myEntity.getName() + "_ID"))
-                        && (!attribute.isPrimaryKey())
-                        && (myEntity.getAttributes().size() != 0)
-                        && (myEntity != entity)) {
                     if (!attribute.isForeignKey()) {
                         InferRelationships myir = new InferRelationships();
                         myir.setSource(entity);
-                        myir.setTarget(myEntity);
+                        myir.setTarget(targetEntity);
                         ir.add(myir);
                     }
-                    createReversRelationship(myEntity, entity);
+                    createReversRelationship(targetEntity, entity);
                 }
             }
-
         }
     }
 
@@ -151,15 +153,35 @@ public class InferRelationshipsControlle
     }
 
     public void createJoin() {
-        for (InferRelationships myir : ir) {
-            DbAttribute temp = getJoinAttribute(myir.getSource(), myir.getTarget());
-            myir.setJoinSource(temp);
-            if (temp.isPrimaryKey()) {
+        Iterator<InferRelationships> it = ir.iterator();
+        while (it.hasNext()) {
+            InferRelationships myir = it.next();
+
+            DbAttribute src = getJoinAttribute(myir.getSource(), myir.getTarget());
+            if (src == null) {
+                // TODO: andrus 03/28/2010 this is pretty inefficient I guess... We should
+                // check for this condition earlier. See CAY-1405 for the map that caused
+                // this issue
+                it.remove();
+                continue;
+            }
+
+            DbAttribute target = getJoinAttribute(myir.getTarget(), myir.getSource());
+            if (target == null) {
+                // TODO: andrus 03/28/2010 this is pretty inefficient I guess... We should
+                // check for this condition earlier. See CAY-1405 for the map that caused
+                // this issue
+                it.remove();
+                continue;
+            }
+
+            myir.setJoinSource(src);
+            if (src.isPrimaryKey()) {
                 myir.setToMany(true);
             }
-            myir.setJoinTarget(getJoinAttribute(myir.getTarget(), myir.getSource()));
-        }
 
+            myir.setJoinTarget(target);
+        }
     }
 
     public void createName() {



Mime
View raw message