cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r901383 - in /cayenne/main/branches/STABLE-3.0: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/
Date Wed, 20 Jan 2010 21:21:30 GMT
Author: andrey
Date: Wed Jan 20 21:21:27 2010
New Revision: 901383

URL: http://svn.apache.org/viewvc?rev=901383&view=rev
Log:
CAY-1368 Left Join and Prefetches do not work together

Modified:
    cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.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=901383&r1=901382&r2=901383&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 Wed Jan
20 21:21:27 2010
@@ -28,6 +28,7 @@
 CAY-1355 Warning if rename Embeddable.
 CAY-1361 SelectQuery.aliasPathSplits does nothing
 CAY-1365 "= NULL" being used instead of "IS NULL" on an EJBQL expression..
+CAY-1368 Left Join and Prefetches do not work together
 
 ----------------------------------
 Release: 3.0 RC 1

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java?rev=901383&r1=901382&r2=901383&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java
Wed Jan 20 21:21:27 2010
@@ -22,6 +22,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -655,6 +656,11 @@
             transformed.setOperand(0, converted);
             return transformed;
         }
+        
+        private PathComponentIterator createPathIterator(String path) {
+            return new PathComponentIterator(DbEntity.this, path, 
+                    new HashMap<String, String>()); //TODO: do we need aliases here?
+        }
 
         String translatePath(String path) {
 
@@ -673,7 +679,7 @@
 
             // case (0)
             if (toMany) {
-                Iterator<CayenneMapEntry> pathIt = resolvePathComponents(path);
+                PathComponentIterator pathIt = createPathIterator(path);
                 Iterator<CayenneMapEntry> relationshipIt = resolvePathComponents(relationshipPath);
 
                 // for inserts from the both ends use LinkedList
@@ -687,8 +693,8 @@
 
                 while (pathIt.hasNext()) {
                     // components may be attributes or relationships
-                    CayenneMapEntry next = pathIt.next();
-                    appendPath(finalPath, next);
+                    PathComponent<Attribute, Relationship> component = pathIt.next();
+                    appendPath(finalPath, component);
                 }
 
                 return convertToPath(finalPath);
@@ -697,15 +703,15 @@
             if (path.equals(relationshipPath)) {
 
                 LinkedList<String> finalPath = new LinkedList<String>();
-                Iterator<CayenneMapEntry> it = resolvePathComponents(path);
+                PathComponentIterator pathIt = createPathIterator(path);
 
                 // just do one step back and one step forward to create correct joins...
                 // find last rel...
                 DbRelationship lastDBR = null;
 
-                while (it.hasNext()) {
+                while (pathIt.hasNext()) {
                     // relationship path components must be DbRelationships
-                    lastDBR = (DbRelationship) it.next();
+                    lastDBR = (DbRelationship) pathIt.next().getRelationship();
                 }
 
                 if (lastDBR != null) {
@@ -723,7 +729,7 @@
             }
 
             // case (3)
-            Iterator<CayenneMapEntry> pathIt = resolvePathComponents(path);
+            PathComponentIterator pathIt = createPathIterator(path);
             Iterator<CayenneMapEntry> relationshipIt = resolvePathComponents(relationshipPath);
 
             // for inserts from the both ends use LinkedList
@@ -734,14 +740,14 @@
                 DbRelationship nextDBR = (DbRelationship) relationshipIt.next();
 
                 // expression components may be attributes or relationships
-                CayenneMapEntry next = pathIt.next();
+                PathComponent<Attribute, Relationship> component = pathIt.next();
 
-                if (nextDBR != next) {
+                if (nextDBR != component.getRelationship()) {
                     // found split point
                     // consume the last iteration components,
                     // then break out to finish the iterators independently
                     prependReversedPath(finalPath, nextDBR);
-                    appendPath(finalPath, next);
+                    appendPath(finalPath, component);
                     break;
                 }
 
@@ -756,8 +762,8 @@
 
             while (pathIt.hasNext()) {
                 // components may be attributes or relationships
-                CayenneMapEntry next = pathIt.next();
-                appendPath(finalPath, next);
+                PathComponent<Attribute, Relationship> component = pathIt.next();
+                appendPath(finalPath, component);
             }
 
             return convertToPath(finalPath);
@@ -799,5 +805,18 @@
                 CayenneMapEntry pathComponent) {
             finalPath.addLast(pathComponent.getName());
         }
+        
+        private void appendPath(
+                LinkedList<String> finalPath,
+                PathComponent<Attribute, Relationship> pathComponent) {
+            String name = (pathComponent.getAttribute() != null ? 
+                pathComponent.getAttribute() :
+                pathComponent.getRelationship()).getName();
+            if (pathComponent.getJoinType() == JoinType.LEFT_OUTER) {
+                name += OUTER_JOIN_INDICATOR;
+            }
+            
+            finalPath.addLast(name);
+        }
     }
 }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=901383&r1=901382&r2=901383&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
Wed Jan 20 21:21:27 2010
@@ -23,6 +23,7 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -1079,36 +1080,43 @@
 
         DBPathConverter transformer = new DBPathConverter();
 
-        String dbPath = transformer.toDbPath(resolvePathComponents(relationshipPath));
+        String dbPath = transformer.toDbPath(createPathIterator(relationshipPath));
         Expression dbClone = expression.transform(transformer);
 
         return getDbEntity().translateToRelatedEntity(dbClone, dbPath);
     }
+    
+    private PathComponentIterator createPathIterator(String path) {
+        return new PathComponentIterator(ObjEntity.this, path, 
+                new HashMap<String, String>()); //TODO: do we need aliases here?
+    }
 
     final class DBPathConverter implements Transformer {
 
         // TODO: make it a public method - resolveDBPathComponents or something...
         // seems generally useful
-        String toDbPath(Iterator<CayenneMapEntry> objectPathComponents) {
+        
+        String toDbPath(PathComponentIterator objectPathComponents) {
             StringBuilder buf = new StringBuilder();
             while (objectPathComponents.hasNext()) {
-                Object component = objectPathComponents.next();
+                PathComponent<Attribute, Relationship> component = objectPathComponents.next();
 
                 Iterator<?> dbSubpath;
 
-                if (component instanceof ObjRelationship) {
-                    dbSubpath = ((ObjRelationship) component)
-                            .getDbRelationships()
-                            .iterator();
+                if (component.getAttribute() != null) {
+                    dbSubpath = ((ObjAttribute) component.getAttribute()).getDbPathIterator();
                 }
-                else if (component instanceof ObjAttribute) {
-                    dbSubpath = ((ObjAttribute) component).getDbPathIterator();
+                else if (component.getRelationship() != null) {
+                    dbSubpath = ((ObjRelationship) component.getRelationship())
+                        .getDbRelationships()
+                        .iterator();
                 }
                 else {
                     throw new CayenneRuntimeException("Unknown path component: "
                             + component);
                 }
 
+                boolean firstComponent = true;
                 while (dbSubpath.hasNext()) {
                     CayenneMapEntry subComponent = (CayenneMapEntry) dbSubpath.next();
                     if (buf.length() > 0) {
@@ -1116,6 +1124,10 @@
                     }
 
                     buf.append(subComponent.getName());
+                    if (firstComponent && component.getJoinType() == JoinType.LEFT_OUTER)
{
+                        buf.append(OUTER_JOIN_INDICATOR);
+                    }
+                    firstComponent = false;
                 }
             }
 
@@ -1136,7 +1148,7 @@
 
             // convert obj_path to db_path
 
-            String converted = toDbPath(resolvePathComponents(expression));
+            String converted = toDbPath(createPathIterator((String) expression.getOperand(0)));
             Expression exp = ExpressionFactory.expressionOfType(Expression.DB_PATH);
             exp.setOperand(0, converted);
             return exp;

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java?rev=901383&r1=901382&r2=901383&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
Wed Jan 20 21:21:27 2010
@@ -539,4 +539,18 @@
             connection.close();
         }
     }
+    
+    public void testLeftJoinAndPrefetchToMany() {
+        SelectQuery query = new SelectQuery(Artist.class, 
+            ExpressionFactory.matchExp("paintingArray+.toGallery", null));
+        query.addPrefetch("artistExhibitArray");
+        createDataContext().performQuery(query);
+    }
+    
+    public void testLeftJoinAndPrefetchToOne() {
+        SelectQuery query = new SelectQuery(Painting.class, 
+            ExpressionFactory.matchExp("toArtist+.artistName", null));
+        query.addPrefetch("toGallery");
+        createDataContext().performQuery(query);
+    }
 }



Mime
View raw message