cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r901614 - in /cayenne/main/branches/STABLE-3.0: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/ fr...
Date Thu, 21 Jan 2010 09:30:48 GMT
Author: andrey
Date: Thu Jan 21 09:29:25 2010
New Revision: 901614

URL: http://svn.apache.org/viewvc?rev=901614&view=rev
Log:
CAY-1369 EJBQL Fix likeIgnoreCase issues

Added:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
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/exp/parser/ASTLikeIgnoreCase.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.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=901614&r1=901613&r2=901614&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 Thu Jan
21 09:29:25 2010
@@ -29,6 +29,7 @@
 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
+CAY-1369 EJBQL: Fix likeIgnoreCase issues
 
 ----------------------------------
 Release: 3.0 RC 1

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCase.java?rev=901614&r1=901613&r2=901614&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCase.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCase.java
Thu Jan 21 09:29:25 2010
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import java.io.PrintWriter;
+
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.util.ConversionUtil;
 
@@ -74,4 +76,27 @@
     public int getType() {
         return Expression.LIKE_IGNORE_CASE;
     }
+    
+    @Override
+    protected String getEJBQLExpressionOperator(int index) {
+        return "like";
+    }
+    
+    @Override
+    protected void encodeChildAsEJBQL(PrintWriter pw, String rootId, int index) {
+        if (index > 0) {
+            pw.print(' ');
+            pw.print(getEJBQLExpressionOperator(index));
+            pw.print(' ');
+        }
+
+        if (children[index] == null) {
+            pw.print("null");
+        }
+        else {
+            pw.print("upper(");
+            ((SimpleNode) children[index]).encodeAsEJBQL(pw, rootId);
+            pw.print(")");
+        }
+    }
 }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java?rev=901614&r1=901613&r2=901614&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
Thu Jan 21 09:29:25 2010
@@ -354,18 +354,7 @@
 
         if ((children != null) && (children.length > 0)) {
             for (int i = 0; i < children.length; ++i) {
-                if (i > 0) {
-                    pw.print(' ');
-                    pw.print(getEJBQLExpressionOperator(i));
-                    pw.print(' ');
-                }
-
-                if (children[i] == null) {
-                    pw.print("null");
-                }
-                else {
-                    ((SimpleNode) children[i]).encodeAsEJBQL(pw, rootId);
-                }
+                encodeChildAsEJBQL(pw, rootId, i);
             }
         }
 
@@ -373,4 +362,22 @@
             pw.print(')');
         }
     }
+    
+    /**
+     * Encodes child of this node with specified index to EJBQL
+     */
+    protected void encodeChildAsEJBQL(PrintWriter pw, String rootId, int index) {
+        if (index > 0) {
+            pw.print(' ');
+            pw.print(getEJBQLExpressionOperator(index));
+            pw.print(' ');
+        }
+
+        if (children[index] == null) {
+            pw.print("null");
+        }
+        else {
+            ((SimpleNode) children[index]).encodeAsEJBQL(pw, rootId);
+        }
+    }
 }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt?rev=901614&r1=901613&r2=901614&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
Thu Jan 21 09:29:25 2010
@@ -1208,7 +1208,7 @@
 
 void pattern_value() #PatternValue : { }
 {
-	input_parameter() | string_literal()
+	string_expression()
 	[(<ESCAPE> escape_character())]
 }
 

Added: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java?rev=901614&view=auto
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
(added)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/parser/ASTLikeIgnoreCaseTest.java
Thu Jan 21 09:29:25 2010
@@ -0,0 +1,31 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.exp.parser;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+
+public class ASTLikeIgnoreCaseTest extends TestCase {
+    public void testToEJBQL() {
+        Expression like = ExpressionFactory.likeIgnoreCaseExp("a", "%b%");
+        assertEquals(like.toEJBQL("p"), "upper(p.a) like upper('%b%')");
+    }
+}

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.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/EJBQLQueryTest.java?rev=901614&r1=901613&r2=901614&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/EJBQLQueryTest.java
Thu Jan 21 09:29:25 2010
@@ -297,4 +297,19 @@
     
         context.performQuery(query);
     }
+    
+    public void testLikeIgnoreCase() throws Exception {
+        deleteTestData();
+        
+        ObjectContext context = createDataContext();
+        
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("testLikeIgnoreCase");
+        context.commitChanges();
+        
+        EJBQLQuery query = new EJBQLQuery("select a from Artist a where upper(a.artistName)
" +
+        		"like upper('%likeignore%')");
+    
+        assertEquals(context.performQuery(query).size(), 1);
+    }
 }



Mime
View raw message