openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1376659 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps: Args.java DatastoreFunction.java UnaryOp.java
Date Thu, 23 Aug 2012 19:27:23 GMT
Author: jgrassel
Date: Thu Aug 23 19:27:22 2012
New Revision: 1376659

URL: http://svn.apache.org/viewvc?rev=1376659&view=rev
Log:
OPENJPA-2149: Criteria.function adds wrong casts to parameters making it unusable

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/DatastoreFunction.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java?rev=1376659&r1=1376658&r2=1376659&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java
Thu Aug 23 19:27:22 2012
@@ -171,11 +171,17 @@ public class Args
         return 0;
     }
 
-    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
-        SQLBuffer sql, int index) {
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index)
{
+        appendTo(sel, ctx, state, sql, index, null);
+    }
+    
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index,
String operator) {
         ArgsExpState astate = (ArgsExpState) state;
         for (int i = 0; i < _args.length; i++) {
             _args[i].appendTo(sel, ctx, astate.states[i], sql, index);
+            if( operator != null ) {
+                sql.addCastForParam(operator, _args[i]);
+            }
             if (i < _args.length-1)
                 sql.append(", ");
         }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/DatastoreFunction.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/DatastoreFunction.java?rev=1376659&r1=1376658&r2=1376659&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/DatastoreFunction.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/DatastoreFunction.java
Thu Aug 23 19:27:22 2012
@@ -46,16 +46,12 @@ public class DatastoreFunction extends U
     public void appendTo(Select sel, ExpContext ctx, ExpState state, 
         SQLBuffer sql, int index) {
         Args args = (Args) getValue();
-        if (!ctx.store.getDBDictionary().requiresCastForMathFunctions || args.getValues().length
== 1)
+        if (!ctx.store.getDBDictionary().requiresCastForMathFunctions || args.getValues().length
== 1) {
             super.appendTo(sel, ctx, state, sql, index);
-        else {
+        } else {
             sql.append(getOperator());
             sql.append("(");            
-            args.appendTo(sel, ctx, state, sql, 0);
-            Val[] vals = args.getVals();
-            for (int i = 1; i < vals.length; i++) {
-                sql.addCastForParam(getOperator(), vals[i]);
-            }
+            args.appendTo(sel, ctx, state, sql, 0, getOperator());
             sql.append(")");
         }            
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java?rev=1376659&r1=1376658&r2=1376659&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
Thu Aug 23 19:27:22 2012
@@ -139,7 +139,16 @@ abstract class UnaryOp
         sql.append(getOperator());
         sql.append(_noParen ? " " : "(");
         _val.appendTo(sel, ctx, state, sql, 0);
-        sql.addCastForParam(getOperator(), _val);
+       
+        // OPENJPA-2149: If _val (Val) is an 'Arg', we need to get the Val[]
+        // from it, and the single element it contains because the
+        // 'addCastForParam' method gets the 'type' from the Val it receives.
+        // In the case where _val is an Arg, when addCastForParam gets the
+        // type, it will be getting the type of the Val (an Object) rather
+        // the type of the Arg.
+        sql.addCastForParam(getOperator(),
+            (_val instanceof Args) ? (((Args) _val).getVals())[0]
+                                   : _val);
         if (!_noParen)
             sql.append(")");
     }



Mime
View raw message