openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r964967 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Date Fri, 16 Jul 2010 22:39:06 GMT
Author: faywang
Date: Fri Jul 16 22:39:06 2010
New Revision: 964967

URL: http://svn.apache.org/viewvc?rev=964967&view=rev
Log:
OPENJPA-1726: fix the locate and substring for Postgres as it only accepts integer as the
start index.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?rev=964967&r1=964966&r2=964967&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Fri Jul 16 22:39:06 2010
@@ -1287,7 +1287,12 @@ public class JPQLExpressionBuilder
                 if (node.children.length == 3) {
                     val1 = getValue(child(node, 0, 3));
                     val2 = getValue(child(node, 1, 3));
-                    val3 = getValue(child(node, 2, 3));
+                    JPQLNode child3 = child(node, 2, 3);
+                    if (child3.id == JJTINTEGERLITERAL)
+                        val3 = getIntegerValue(child3);
+                    else
+                        val3 = getValue(child3);
+                    
                 } else if (node.children.length == 2) {
                     val1 = getValue(child(node, 0, 2));
                     val2 = getValue(child(node, 1, 2));
@@ -1306,9 +1311,13 @@ public class JPQLExpressionBuilder
                 Value locatePath = getValue(firstChild(node));
                 Value locateSearch = getValue(secondChild(node));
                 Value locateFromIndex = null;
-                if (node.getChildCount() > 2) // optional start index arg
-                    locateFromIndex = getValue(thirdChild(node));
-
+                if (node.getChildCount() > 2) { // optional start index arg
+                    JPQLNode child3 = thirdChild(node);
+                    if (child3.id == JJTINTEGERLITERAL) {
+                        locateFromIndex = getIntegerValue(child3);
+                    } else
+                        locateFromIndex = getValue(child3);
+                }
                 setImplicitType(locatePath, TYPE_STRING);
                 setImplicitType(locateSearch, TYPE_STRING);
 
@@ -1405,6 +1414,16 @@ public class JPQLExpressionBuilder
         }
     }
     
+    private Value getIntegerValue(JPQLNode node) {
+        BigDecimal bigdec = new BigDecimal
+        (node.text.endsWith("l") || node.text.endsWith("L")
+            ? node.text.substring(0, node.text.length() - 1)
+            : node.text).
+        multiply(new BigDecimal(negative(node)));
+        return factory.newLiteral(Integer.valueOf(bigdec.intValue()),
+                Literal.TYPE_NUMBER);        
+    }
+    
     /**
      * Converts JPQL substring() function to OpenJPA ExpressionFactory 
      * substring() arguments.



Mime
View raw message