openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r886991 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestJPQLScalarExpressions.java
Date Thu, 03 Dec 2009 23:42:01 GMT
Author: faywang
Date: Thu Dec  3 23:42:00 2009
New Revision: 886991

URL: http://svn.apache.org/viewvc?rev=886991&view=rev
Log:
OPENJPA-1413: fix NPE when update using CASE expression on Derby

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestJPQLScalarExpressions.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java?rev=886991&r1=886990&r2=886991&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
Thu Dec  3 23:42:00 2009
@@ -106,7 +106,8 @@
         boolean val2Null = _val2 instanceof Const
             && ((Const) _val2).isSQLValueNull(sel, ctx, bstate.state2);
         appendTo(sel, ctx, bstate, buf, val1Null, val2Null);
-        sel.append(buf, state.joins);
+        if (sel != null)
+            sel.append(buf, state.joins);
     }
 
     public void selectColumns(Select sel, ExpContext ctx, ExpState state, 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestJPQLScalarExpressions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestJPQLScalarExpressions.java?rev=886991&r1=886990&r2=886991&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestJPQLScalarExpressions.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestJPQLScalarExpressions.java
Thu Dec  3 23:42:00 2009
@@ -249,22 +249,19 @@
         assertEquals("the name is not Jacob", "Jacob", result3[0]);
         assertEquals("the credit rating is not 'POOR'", "POOR", result3[1]);
 
-        /*
-        // this jpql fail with NPE in Derby. It works with DB2 
         String update2 = "update CompUser c set c.creditRating = " +
             " CASE WHEN c.name ='Jacob' THEN " +
-            "org.apache.openjpa.persistence.common.apps.CompUser$
-            CreditRating.POOR" + 
+            "org.apache.openjpa.persistence.common.apps.CompUser$CreditRating.POOR" + 
             " WHEN c.name = 'Ugo' THEN " + 
-            "org.apache.openjpa.persistence.common.apps.CompUser$
-            CreditRating.GOOD " +
+            "org.apache.openjpa.persistence.common.apps.CompUser$CreditRating.GOOD " +
             " ELSE " + 
-            "org.apache.openjpa.persistence.common.apps.CompUser$
-            CreditRating.EXCELLENT " +
+            "org.apache.openjpa.persistence.common.apps.CompUser$CreditRating.EXCELLENT "
+
             " END ";
-        */
+        int updateCount = em.createQuery(update2).executeUpdate();
+        assertEquals("the result is not 6", 6, updateCount);
         
-        String update2 = "update CompUser c set c.creditRating = " +
+        
+        String update3 = "update CompUser c set c.creditRating = " +
             " CASE WHEN c.age > 30 THEN " +
             "org.apache.openjpa.persistence.common.apps." +
             "CompUser$CreditRating.POOR" + 
@@ -275,7 +272,7 @@
             "org.apache.openjpa.persistence.common.apps." +
             "CompUser$CreditRating.EXCELLENT " +
             " END "; 
-        int updateCount = em.createQuery(update2).executeUpdate();
+        updateCount = em.createQuery(update3).executeUpdate();
         assertEquals("the result is not 6", 6, updateCount);
         
         String query4 = "select e.name, e.creditRating from CompUser e " + 
@@ -300,7 +297,7 @@
             ((org.apache.openjpa.persistence.common.apps.CompUser.CreditRating)
             result4[1]).name());
         
-        String update3 = "update CompUser c set c.creditRating = " +
+        String update4 = "update CompUser c set c.creditRating = " +
             " CASE c.age WHEN 35 THEN " +
             "org.apache.openjpa.persistence.common.apps." +
             "CompUser$CreditRating.POOR" + 
@@ -311,7 +308,7 @@
             "org.apache.openjpa.persistence.common.apps." +
             "CompUser$CreditRating.EXCELLENT " +
             " END "; 
-        result = em.createQuery(update3).executeUpdate();
+        result = em.createQuery(update4).executeUpdate();
         assertEquals("the result is not 6", 6, result);
 
         // Derby fails but DB2 works 



Mime
View raw message