cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1510030 - in /cayenne/main/trunk/framework/cayenne-core-unpublished/src: main/java/org/apache/cayenne/exp/Expression.java test/java/org/apache/cayenne/exp/ParametrizedExpressionTest.java
Date Sat, 03 Aug 2013 16:19:48 GMT
Author: aadamchik
Date: Sat Aug  3 16:19:48 2013
New Revision: 1510030

URL: http://svn.apache.org/r1510030
Log:
CAY-1856  Expression.expWithParameters does not work when parameters are placed in the inline
collection

Modified:
    cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
    cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/ParametrizedExpressionTest.java

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java?rev=1510030&r1=1510029&r2=1510030&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
(original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
Sat Aug  3 16:19:48 2013
@@ -325,6 +325,21 @@ public abstract class Expression impleme
 
             public Object transform(Object object) {
                 if (!(object instanceof ExpressionParameter)) {
+
+                    // mainly for the ASTList array child...
+                    if (object instanceof Object[]) {
+
+                        Object[] source = (Object[]) object;
+                        int len = source.length;
+                        Object[] target = new Object[len];
+
+                        for (int i = 0; i < len; i++) {
+                            target[i] = transform(source[i]);
+                        }
+                        
+                        return target;
+                    }
+
                     return object;
                 }
 

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/ParametrizedExpressionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/ParametrizedExpressionTest.java?rev=1510030&r1=1510029&r2=1510030&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/ParametrizedExpressionTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/ParametrizedExpressionTest.java
Sat Aug  3 16:19:48 2013
@@ -25,6 +25,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.DataObject;
 import org.apache.cayenne.exp.parser.ASTList;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
@@ -81,18 +83,41 @@ public class ParametrizedExpressionTest 
         Expression inExp = Expression.fromString("k1 in $test");
         Expression e1 = Expression.fromString("k1 in ('a', 'b')");
 
-        TstTraversalHandler.compareExps(e1,
-                inExp.expWithParameters(Collections.singletonMap("test", new Object[] { "a",
"b" })));
+        Expression transformed = inExp.expWithParameters(Collections.singletonMap("test",
new Object[] { "a", "b" }));
+        TstTraversalHandler.compareExps(e1, transformed);
+
+        // just in case manually check params
+        DataObject o1 = new CayenneDataObject();
+        o1.writePropertyDirectly("k1", "a");
+        assertTrue(transformed.match(o1));
+
+        DataObject o2 = new CayenneDataObject();
+        o2.writePropertyDirectly("k1", "x");
+        assertFalse(transformed.match(o2));
     }
 
     public void testInParameter_AsValues() throws Exception {
         Expression inExp = Expression.fromString("k1 in ($ap, $bp)");
-        Expression e1 = Expression.fromString("k1 in ('a', 'b')");
+        
+        String e1String = "k1 in (\"a\", \"b\")";
+        Expression e1 = Expression.fromString(e1String);
 
         Map<String, Object> params = new HashMap<String, Object>();
         params.put("ap", "a");
         params.put("bp", "b");
-        TstTraversalHandler.compareExps(e1, inExp.expWithParameters(params));
+        Expression transformed = inExp.expWithParameters(params);
+        TstTraversalHandler.compareExps(e1, transformed);
+        
+        assertEquals(e1String, transformed.toString());
+
+        // just in case manually check params
+        DataObject o1 = new CayenneDataObject();
+        o1.writePropertyDirectly("k1", "a");
+        assertTrue(transformed.match(o1));
+
+        DataObject o2 = new CayenneDataObject();
+        o2.writePropertyDirectly("k1", "x");
+        assertFalse(transformed.match(o2));
     }
 
     /**



Mime
View raw message