cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r666081 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/exp/Expression.java main/java/org/apache/cayenne/exp/parser/ASTList.java test/java/org/apache/cayenne/exp/ExpressionTest.java
Date Tue, 10 Jun 2008 12:03:47 GMT
Author: aadamchik
Date: Tue Jun 10 05:03:47 2008
New Revision: 666081

URL: http://svn.apache.org/viewvc?rev=666081&view=rev
Log:
CAY-1073 Bug in Expression.toEJBQL with inExp/notInExp

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTList.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java?rev=666081&r1=666080&r2=666081&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
Tue Jun 10 05:03:47 2008
@@ -573,6 +573,9 @@
         return buffer.toString();
     }
 
+    /**
+     * @since 3.0
+     */
     public String toEJBQL(String rootId) {
         StringWriter buffer = new StringWriter();
         PrintWriter pw = new PrintWriter(buffer);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTList.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTList.java?rev=666081&r1=666080&r2=666081&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTList.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTList.java
Tue Jun 10 05:03:47 2008
@@ -113,6 +113,36 @@
 
         pw.print(')');
     }
+    
+    /**
+     * @since 3.0
+     */
+    @Override
+    public void encodeAsEJBQL(PrintWriter pw, String rootId) {
+        if (parent != null) {
+            pw.print("(");
+        }
+
+        if ((values != null) && (values.length > 0)) {
+            for (int i = 0; i < values.length; ++i) {
+                if (i > 0) {
+                    pw.print(getExpressionOperator(i));
+                    pw.print(' ');
+                }
+
+                if (values[i] == null) {
+                    pw.print("null");
+                }
+                else {
+                    SimpleNode.encodeScalarAsString(pw, values[i], '\'');
+                }
+            }
+        }
+
+        if (parent != null) {
+            pw.print(')');
+        }
+    }
 
     @Override
     public int getOperandCount() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java?rev=666081&r1=666080&r2=666081&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
Tue Jun 10 05:03:47 2008
@@ -34,17 +34,17 @@
         Expression e = Expression.fromString("216201000180L");
         assertEquals(new Long(216201000180L), e.evaluate(new Object()));
     }
-    
+
     public void testFromStringPath() {
         Expression e1 = Expression.fromString("object.path");
         assertEquals(Expression.OBJ_PATH, e1.getType());
-        
+
         Expression e2 = Expression.fromString("db:object.path");
         assertEquals(Expression.DB_PATH, e2.getType());
-        
+
         Expression e3 = Expression.fromString("object+.path");
         assertEquals(Expression.OBJ_PATH, e3.getType());
-        
+
         Expression e4 = Expression.fromString("db:object.path+");
         assertEquals(Expression.DB_PATH, e4.getType());
     }
@@ -91,4 +91,18 @@
 
         assertEquals("x.artistName.stuff = :name", ejbql);
     }
+
+    public void testEncodeAsEJBQL3_EncodeListOfParameters() {
+
+        Expression e = ExpressionFactory.inExp("artistName", "a", "b", "c");
+
+        StringWriter buffer = new StringWriter();
+        PrintWriter pw = new PrintWriter(buffer);
+        e.encodeAsEJBQL(pw, "x");
+        pw.close();
+        buffer.flush();
+        String ejbql = buffer.toString();
+
+        assertEquals("x.artistName in ('a', 'b', 'c')", ejbql);
+    }
 }



Mime
View raw message