cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r805390 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/exp/parser/ASTIn.java test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
Date Tue, 18 Aug 2009 12:44:20 GMT
Author: andrey
Date: Tue Aug 18 12:44:20 2009
New Revision: 805390

URL: http://svn.apache.org/viewvc?rev=805390&view=rev
Log:
CAY-1254 filtering an inExp(a, b) does not work when the path (a) refers to a collection of
objects (based on patch by √ėyvind Harboe)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTIn.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTIn.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTIn.java?rev=805390&r1=805389&r2=805390&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTIn.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTIn.java
Tue Aug 18 12:44:20 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import java.util.Collection;
+
 import org.apache.cayenne.exp.Expression;
 import org.apache.commons.collections.Transformer;
 
@@ -62,11 +64,23 @@
         if (objects == null) {
             return Boolean.FALSE;
         }
-
+    
         int size = objects.length;
         for (int i = 0; i < size; i++) {
-            if (objects[i] != null && ASTEqual.evaluateAtomic(o1, objects[i])) {
-                return Boolean.TRUE;
+            if (objects[i] != null) {
+                if (o1 instanceof Collection) {
+                	/* handle the case where we have a collection of objects */
+                	for (Object obj : (Collection) o1) {
+                    	if (ASTEqual.evaluateAtomic(obj, objects[i])) {
+                            return Boolean.TRUE;
+                    	}
+                	}
+                }
+                else {
+                	if (ASTEqual.evaluateAtomic(o1, objects[i])) {
+                        return Boolean.TRUE;
+                	}
+                }
             }
         }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java?rev=805390&r1=805389&r2=805390&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
Tue Aug 18 12:44:20 2009
@@ -279,4 +279,21 @@
         assertEquals(query.getQualifier(), 
                 ExpressionFactory.matchAnyExp(Arrays.asList(a1, a3)));
     }
+    
+    public void testIn() {
+        ObjectContext dc = createDataContext();
+        
+        Artist a1 = dc.newObject(Artist.class);
+        a1.setArtistName("a1");
+        Painting p1 = dc.newObject(Painting.class);
+        p1.setPaintingTitle("p1");
+        Painting p2 = dc.newObject(Painting.class);
+        p2.setPaintingTitle("p2");
+        a1.addToPaintingArray(p1);
+        a1.addToPaintingArray(p2);
+        dc.commitChanges();
+        
+        Expression in = ExpressionFactory.inExp("paintingArray", p1);
+        assertTrue(in.match(a1));
+    }
 }



Mime
View raw message