cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r561944 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateItemTranslator.java test/java/org/apache/cayenne/access/DataContextEJBQLUpdateTest.java
Date Wed, 01 Aug 2007 20:49:27 GMT
Author: aadamchik
Date: Wed Aug  1 13:49:21 2007
New Revision: 561944

URL: http://svn.apache.org/viewvc?view=rev&rev=561944
Log:
CAY-837 EJBQL Update Statement Support
(update with NULL support)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateItemTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLUpdateTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateItemTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateItemTranslator.java?view=diff&rev=561944&r1=561943&r2=561944
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateItemTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateItemTranslator.java
Wed Aug  1 13:49:21 2007
@@ -75,7 +75,7 @@
                 multiColumnOperands = null;
             }
         }
-        
+
         return true;
     }
 
@@ -102,5 +102,16 @@
         // unlike super, Equals here has no children and is itself a child of UpdateItem
         context.append(" =");
         return false;
+    }
+
+    public boolean visitUpdateValue(EJBQLExpression expression) {
+
+        // a criteria for NULL is UpdateValue with no children
+        if (expression.getChildrenCount() == 0) {
+            context.append(" NULL");
+            return false;
+        }
+        
+        return true;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLUpdateTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLUpdateTest.java?view=diff&rev=561944&r1=561943&r2=561944
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLUpdateTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLUpdateTest.java
Wed Aug  1 13:49:21 2007
@@ -85,6 +85,31 @@
         notUpdated = DataObjectUtils.objectForQuery(context, check);
         assertEquals(new Long(0l), notUpdated);
     }
+    
+    public void testUpdateNoQualifierNull() throws Exception {
+        createTestData("prepare");
+
+        ObjectContext context = createDataContext();
+
+        EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p "
+                + "WHERE p.paintingTitle is NULL or p.estimatedPrice is not null");
+
+        Object notUpdated = DataObjectUtils.objectForQuery(context, check);
+        assertEquals(new Long(2l), notUpdated);
+
+        String ejbql = "UPDATE Painting AS p SET p.estimatedPrice = NULL";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        QueryResponse result = context.performGenericQuery(query);
+
+        int[] count = result.firstUpdateCount();
+        assertNotNull(count);
+        assertEquals(1, count.length);
+        assertEquals(2, count[0]);
+
+        notUpdated = DataObjectUtils.objectForQuery(context, check);
+        assertEquals(new Long(0l), notUpdated);
+    }
 
     public void testUpdateNoQualifierMultipleItems() throws Exception {
         createTestData("prepare");
@@ -235,4 +260,6 @@
         notUpdated = DataObjectUtils.objectForQuery(context, check);
         assertEquals(new Long(0l), notUpdated);
     }
+    
+    
 }



Mime
View raw message