cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r562877 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ main/jjtree/org/apache/cayenne/ejbql/ test/java/org/apache/cayenne/access/ test/resources/dml/
Date Sun, 05 Aug 2007 14:56:12 GMT
Author: aadamchik
Date: Sun Aug  5 07:56:11 2007
New Revision: 562877

URL: http://svn.apache.org/viewvc?view=rev&rev=562877
Log:
CAY-841  EJBQL Support for LIKE/ESCAPE and IN conditions
(LIKE/ESCAPE support)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java?view=diff&rev=562877&r1=562876&r2=562877
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
Sun Aug  5 07:56:11 2007
@@ -82,12 +82,12 @@
         context.append(" EXISTS");
         return true;
     }
-    
+
     public boolean visitAll(EJBQLExpression expression) {
         context.append(" ALL");
         return true;
     }
-    
+
     public boolean visitAny(EJBQLExpression expression) {
         context.append(" ANY");
         return true;
@@ -300,9 +300,10 @@
         return true;
     }
 
-    public boolean visitPatternValue(EJBQLExpression expression) {
-        // TODO: andrus 3/25/2007 - implement me
-        return true;
+    public boolean visitEscapeCharacter(EJBQLExpression expression) {
+        // note that EscapeChar text is already wrapped in single quotes
+        context.append(" ESCAPE ").append(expression.getText());
+        return false;
     }
 
     public boolean visitIsNull(EJBQLExpression expression, int finishedChildIndex) {
@@ -344,7 +345,7 @@
         }
         return true;
     }
-    
+
     public boolean visitSubselect(EJBQLExpression expression) {
         context.append(" (");
         expression.visit(new EJBQLSelectTranslator(context));

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt?view=diff&rev=562877&r1=562876&r2=562877
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
Sun Aug  5 07:56:11 2007
@@ -1193,7 +1193,7 @@
 void pattern_value() #PatternValue : { }
 {
 	input_parameter() | string_literal()
-	[(<ESCAPE> escape_character() #EscapeCharacter)]
+	[(<ESCAPE> escape_character())]
 }
 
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java?view=auto&rev=562877
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLConditionsTest.java
Sun Aug  5 07:56:11 2007
@@ -0,0 +1,95 @@
+/*****************************************************************
+ *   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.access;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.cayenne.DataObjectUtils;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.unit.CayenneCase;
+
+public class DataContextEJBQLConditionsTest extends CayenneCase {
+    
+    protected void setUp() throws Exception {
+        deleteTestData();
+    }
+
+    public void testLike1() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'A%C'";
+
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        List objects = createDataContext().performQuery(query);
+        assertEquals(1, objects.size());
+
+        Set ids = new HashSet();
+        Iterator it = objects.iterator();
+        while (it.hasNext()) {
+            Object id = DataObjectUtils.pkForObject((Persistent) it.next());
+            ids.add(id);
+        }
+
+        assertTrue(ids.contains(new Integer(33001)));
+    }
+    
+    public void testLike2() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE '_DDDD'";
+
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        List objects = createDataContext().performQuery(query);
+        assertEquals(3, objects.size());
+
+        Set ids = new HashSet();
+        Iterator it = objects.iterator();
+        while (it.hasNext()) {
+            Object id = DataObjectUtils.pkForObject((Persistent) it.next());
+            ids.add(id);
+        }
+
+        assertTrue(ids.contains(new Integer(33002)));
+        assertTrue(ids.contains(new Integer(33003)));
+        assertTrue(ids.contains(new Integer(33005)));
+    }
+    
+    public void testLikeEscape() throws Exception {
+        createTestData("prepare");
+
+        String ejbql = "SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'X_DDDD' ESCAPE
'X'";
+
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+        List objects = createDataContext().performQuery(query);
+        assertEquals(1, objects.size());
+
+        Set ids = new HashSet();
+        Iterator it = objects.iterator();
+        while (it.hasNext()) {
+            Object id = DataObjectUtils.pkForObject((Persistent) it.next());
+            ids.add(id);
+        }
+
+        assertTrue(ids.contains(new Integer(33005)));
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml?view=auto&rev=562877
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/access.DataContextEJBQLConditionsTest.xml
Sun Aug  5 07:56:11 2007
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans default-lazy-init="true">
+
+	<bean id="P1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33001, 'ABAAC', 3000)
+			</value>
+		</constructor-arg>
+	</bean>
+
+	<bean id="P2" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33002, 'ADDDD', 4000)
+			</value>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="P3" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33003, 'BDDDD', 5000)
+			</value>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="P4" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33004, 'BBDDDD', 5000)
+			</value>
+		</constructor-arg>
+	</bean>
+	
+	<bean id="P5" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+		<constructor-arg type="java.lang.Class">
+			<value>org.apache.art.Painting</value>
+		</constructor-arg>
+		<constructor-arg>
+			<value>
+				INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
+				VALUES (33005, '_DDDD', 5000)
+			</value>
+		</constructor-arg>
+	</bean>
+
+
+	<!-- ======================================= -->
+	<!-- Data Sets -->
+	<!-- ======================================= -->
+
+	<bean id="prepare" class="java.util.ArrayList">
+		<constructor-arg>
+			<list>
+				<ref bean="P1" />
+				<ref bean="P2" />
+				<ref bean="P3" />
+				<ref bean="P4" />
+				<ref bean="P5" />
+			</list>
+		</constructor-arg>
+	</bean>
+</beans>
\ No newline at end of file



Mime
View raw message