cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r561511 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java test/java/org/apache/cayenne/access/DataContextEJBQLUpdateTest.java
Date Tue, 31 Jul 2007 20:46:46 GMT
Author: aadamchik
Date: Tue Jul 31 13:46:45 2007
New Revision: 561511

URL: http://svn.apache.org/viewvc?view=rev&rev=561511
Log:
CAY-837 EJBQL Update Statement Support
(decimal value handling)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.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/EJBQLUpdateTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java?view=diff&rev=561511&r1=561510&r2=561511
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java
Tue Jul 31 13:46:45 2007
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.access.jdbc;
 
+import java.math.BigDecimal;
+
 import org.apache.cayenne.ejbql.EJBQLBaseVisitor;
 import org.apache.cayenne.ejbql.EJBQLException;
 import org.apache.cayenne.ejbql.EJBQLExpression;
@@ -87,6 +89,9 @@
         return true;
     }
 
+    // TODO: andrus, 7/31/2007 - all literal processing (visitStringLiteral,
+    // visitIntegerLiteral, visitDecimalLiteral) is duplicated in
+    // EJBQLConditionalTranslator - may need to refactor
     public boolean visitStringLiteral(EJBQLExpression expression) {
         if (expression.getText() == null) {
             context.append("null");
@@ -96,10 +101,10 @@
             // quotes that are part of the string escaped.
             context.append(" #bind(").append(expression.getText()).append(" 'VARCHAR')");
         }
-        
+
         return true;
     }
-    
+
     public boolean visitIntegerLiteral(EJBQLExpression expression) {
         if (expression.getText() == null) {
             context.append("null");
@@ -116,6 +121,26 @@
 
             String var = context.bindParameter(value);
             context.append(" #bind($").append(var).append(" 'INTEGER')");
+        }
+        return true;
+    }
+
+    public boolean visitDecimalLiteral(EJBQLExpression expression) {
+        if (expression.getText() == null) {
+            context.append("null");
+        }
+        else {
+            Object value;
+
+            try {
+                value = new BigDecimal(expression.getText());
+            }
+            catch (NumberFormatException nfex) {
+                throw new EJBQLException("Invalid decimal: " + expression.getText());
+            }
+
+            String var = context.bindParameter(value);
+            context.append(" #bind($").append(var).append(" 'DECIMAL')");
         }
         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=561511&r1=561510&r2=561511
==============================================================================
--- 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
Tue Jul 31 13:46:45 2007
@@ -79,4 +79,29 @@
         notUpdated = DataObjectUtils.objectForQuery(context, check);
         assertEquals(new Long(0l), notUpdated);
     }
+    
+    public void testUpdateNoQualifierDecimal() throws Exception {
+        createTestData("prepare");
+
+        ObjectContext context = createDataContext();
+
+        EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p "
+                + "WHERE p.estimatedPrice is NULL or p.estimatedPrice <> 1.1");
+
+        Object notUpdated = DataObjectUtils.objectForQuery(context, check);
+        assertEquals(new Long(2l), notUpdated);
+
+        String ejbql = "UPDATE Painting AS p SET p.estimatedPrice = 1.1";
+        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);
+    }
 }



Mime
View raw message