cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r787173 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/trans/JoinStack.java test/java/org/apache/cayenne/access/trans/SelectTranslatorTest.java
Date Mon, 22 Jun 2009 09:03:42 GMT
Author: andrey
Date: Mon Jun 22 09:03:42 2009
New Revision: 787173

URL: http://svn.apache.org/viewvc?rev=787173&view=rev
Log:
CAY-1235 Implement qualifiers for DBEntities. Fixing left joins issue

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/SelectTranslatorTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java?rev=787173&r1=787172&r2=787173&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/JoinStack.java
Mon Jun 22 09:03:42 2009
@@ -31,6 +31,7 @@
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.JoinType;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.commons.collections.Transformer;
@@ -232,7 +233,18 @@
         JoinedDbEntityQualifierTransformer(JoinTreeNode node) {
             pathToRoot = "";
             while (node != null && node.getRelationship() != null) {
-                pathToRoot += node.getRelationship().getName() + ObjEntity.PATH_SEPARATOR;
+                pathToRoot += node.getRelationship().getName();
+                
+                /**
+                 * We must be in the same join as 'node',
+                 * otherwise incorrect join statement like 
+                 * JOIN t1 ... ON (t0.id=t1.id AND t2.qualifier=0) could be generated
+                 */
+                if (node.getJoinType() == JoinType.LEFT_OUTER) {
+                    pathToRoot += Entity.OUTER_JOIN_INDICATOR;
+                }
+                pathToRoot += ObjEntity.PATH_SEPARATOR;
+                
                 node = node.getParent();
             }
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/SelectTranslatorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/SelectTranslatorTest.java?rev=787173&r1=787172&r2=787173&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/SelectTranslatorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/SelectTranslatorTest.java
Mon Jun 22 09:03:42 2009
@@ -28,6 +28,7 @@
 import org.apache.art.ArtistExhibit;
 import org.apache.art.CompoundPainting;
 import org.apache.art.Painting;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.access.jdbc.ColumnDescriptor;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.exp.Expression;
@@ -77,6 +78,8 @@
      * Tests query creation with qualifier and ordering.
      */
     public void testDbEntityQualifier() throws Exception {
+        ObjectContext context = createDataContext();
+        
         SelectQuery q = new SelectQuery(Artist.class);
         final DbEntity entity = getNode().getEntityResolver().getDbEntity("ARTIST");
         final DbEntity middleEntity = getNode().getEntityResolver().getDbEntity("ARTIST_GROUP");
@@ -94,15 +97,24 @@
                     assertTrue(generatedSql.startsWith("SELECT "));
                     assertTrue(generatedSql.indexOf(" FROM ") > 0);
                     assertTrue(generatedSql.indexOf("ARTIST_NAME = ") > 0);
+                    System.out.println(generatedSql);
                 }
             };
     
             test.test(q);
+            context.performQuery(q);            
+            
+            //testing outer join!!
+            q = new SelectQuery(Painting.class);
+            q.addOrdering("toArtist+.artistName", true);
+            test.test(q);
+            context.performQuery(q);
             
             //testing quering from related table 
             q = new SelectQuery(Painting.class, 
                     ExpressionFactory.matchExp("toArtist.artistName", "foo"));
             test.test(q);
+            context.performQuery(q);
             
             //testing flattened rels
             q = new SelectQuery(Artist.class, ExpressionFactory.matchExp("groupArray.name",
"bar"));
@@ -112,6 +124,7 @@
                     assertTrue(transl.createSqlString().indexOf("GROUP_ID = ") > 0);
                 }
             }.test(q);
+            context.performQuery(q);
         }
         finally {
             entity.setQualifier(null);



Mime
View raw message