cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r549746 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/access/jdbc/
Date Fri, 22 Jun 2007 07:50:28 GMT
Author: aadamchik
Date: Fri Jun 22 00:50:24 2007
New Revision: 549746

URL: http://svn.apache.org/viewvc?view=rev&rev=549746
Log:
CAY-452 EJB QL Cayenne Query
1. = NULL handling

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/test/java/org/apache/cayenne/access/DataContextEJBQLIsNullTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java

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=549746&r1=549745&r2=549746
==============================================================================
--- 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
Fri Jun 22 00:50:24 2007
@@ -355,6 +355,11 @@
             }
         }
 
-        context.append(" #bind($").append(boundName).append(")");
+        if (object != null) {
+            context.append(" #bind($").append(boundName).append(")");
+        }
+        else {
+            context.append(" NULL");
+        }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLIsNullTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLIsNullTest.java?view=diff&rev=549746&r1=549745&r2=549746
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLIsNullTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLIsNullTest.java
Fri Jun 22 00:50:24 2007
@@ -26,6 +26,19 @@
 import org.apache.cayenne.unit.CayenneCase;
 
 public class DataContextEJBQLIsNullTest extends CayenneCase {
+    
+    public void testCompareToNull() throws Exception {
+        deleteTestData();
+        createTestData("prepare");
+
+        String ejbql1 = "SELECT p FROM Painting p WHERE p.estimatedPrice = :x";
+        EJBQLQuery query1 = new EJBQLQuery(ejbql1);
+        query1.setParameter("x", null);
+
+        // unlike SelectQuery or SQLTemplate, EJBQL nulls are handled just like SQL.
+        List results = createDataContext().performQuery(query1);
+        assertEquals(0, results.size());
+    }
 
     public void testIsNull() throws Exception {
         deleteTestData();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java?view=diff&rev=549746&r1=549745&r2=549746
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslatorTest.java
Fri Jun 22 00:50:24 2007
@@ -19,6 +19,8 @@
 package org.apache.cayenne.access.jdbc;
 
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.cayenne.ejbql.EJBQLCompiledExpression;
 import org.apache.cayenne.ejbql.EJBQLParser;
@@ -29,13 +31,15 @@
 public class EJBQLSelectTranslatorTest extends CayenneCase {
 
     private SQLTemplate translateSelect(String ejbql) {
+        return translateSelect(ejbql, Collections.EMPTY_MAP);
+    }
+
+    private SQLTemplate translateSelect(String ejbql, Map parameters) {
         EJBQLParser parser = EJBQLParserFactory.getParser();
         EJBQLCompiledExpression select = parser.compile(ejbql, getDomain()
                 .getEntityResolver());
 
-        EJBQLTranslationContext tr = new EJBQLTranslationContext(
-                select,
-                Collections.EMPTY_MAP);
+        EJBQLTranslationContext tr = new EJBQLTranslationContext(select, parameters);
         select.getExpression().visit(new EJBQLSelectTranslator(tr));
         return tr.getQuery();
     }
@@ -213,7 +217,12 @@
     }
 
     public void testSelectPositionalParameters() {
-        SQLTemplate query = translateSelect("select a from Artist a where a.artistName =
?1 or a.artistName = ?2");
+        Map params = new HashMap();
+        params.put(new Integer(1), "X");
+        params.put(new Integer(2), "Y");
+        SQLTemplate query = translateSelect(
+                "select a from Artist a where a.artistName = ?1 or a.artistName = ?2",
+                params);
         String sql = query.getDefaultTemplate();
 
         assertTrue(sql, sql.startsWith("SELECT "));



Mime
View raw message