openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fa...@apache.org
Subject svn commit: r881598 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/te...
Date Tue, 17 Nov 2009 22:59:01 GMT
Author: fancy
Date: Tue Nov 17 22:59:01 2009
New Revision: 881598

URL: http://svn.apache.org/viewvc?rev=881598&view=rev
Log:
OPENJPA-1388 JPQL named parameter using a reserved word (:vlaue) resulting in ArgumentException

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
    openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryParameters.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java?rev=881598&r1=881597&r2=881598&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java Tue
Nov 17 22:59:01 2009
@@ -1732,7 +1732,7 @@
         for (Object expected : paramTypes.keySet()) {
             if (!params.containsKey(expected))
             throw new UserException(_loc.get("unbound-params",
-                params.keySet()));
+                expected, params.keySet()));
         }
 
         Iterator itr = paramTypes.entrySet().iterator();

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=881598&r1=881597&r2=881598&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
Tue Nov 17 22:59:01 2009
@@ -1027,15 +1027,18 @@
                 return eval(firstChild(node));
 
             case JJTNAMEDINPUTPARAMETER:
-                return getParameter(node.text, false, false);
+                return getParameter(onlyChild(node).text, false, false);
 
             case JJTPOSITIONALINPUTPARAMETER:
                 return getParameter(node.text, true, false);
 
             case JJTCOLLECTIONPARAMETER:
                 JPQLNode child = onlyChild(node);
+                boolean positional = child.id == JJTPOSITIONALINPUTPARAMETER;
+                if (!positional)
+                    child = onlyChild(child);
                 return getParameter(child.text, 
-                    child.id == JJTPOSITIONALINPUTPARAMETER, true);
+                    positional, true);
 
             case JJTOR: // x OR y
                 return factory.or(getExpression(left(node)),

Modified: openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt?rev=881598&r1=881597&r2=881598&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt (original)
+++ openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt Tue
Nov 17 22:59:01 2009
@@ -1488,10 +1488,9 @@
 }
 
 
-void named_input_parameter() #NAMEDINPUTPARAMETER :
-{ Token t; }
+void named_input_parameter() #NAMEDINPUTPARAMETER : { }
 {
-	":" t = <IDENTIFIER> { jjtThis.setToken (t); }
+	":" path_component()
 }
 
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java?rev=881598&r1=881597&r2=881598&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/expressions/TestEntityTypeExpression.java
Tue Nov 17 22:59:01 2009
@@ -107,10 +107,10 @@
         user = rs.get(0);
         assertEquals("Famzy", user.getName());
 
-        query = "SELECT e FROM CompUser e where TYPE(e) in :params " +
+        query = "SELECT e FROM CompUser e where TYPE(e) in :value " +
                 "ORDER BY e.age";
         rs = em.createQuery(query).
-            setParameter("params", params).getResultList();
+            setParameter("value", params).getResultList();
         user = rs.get(0);
         assertEquals("Jacob", user.getName());
         
@@ -137,10 +137,10 @@
         type = ((Object[]) rs2.get(0))[1];
         assertEquals(type, FemaleUser.class);
         
-        query = "SELECT e FROM CompUser e where TYPE(e) = :typeName " +
+        query = "SELECT e FROM CompUser e where TYPE(e) = :type " +
             " ORDER BY e.name";
         rs =  em.createQuery(query).
-            setParameter("typeName", FemaleUser.class).getResultList();
+            setParameter("type", FemaleUser.class).getResultList();
         assertTrue(rs.size()==3);
         user = rs.get(0);
         assertEquals("Famzy", user.getName());

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryParameters.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryParameters.java?rev=881598&r1=881597&r2=881598&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryParameters.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryParameters.java
Tue Nov 17 22:59:01 2009
@@ -59,6 +59,24 @@
         // do not close the factory
     }
     
+    public void testNamedParameterUsingReservedWord() {
+        String jpql = "select e from simple e WHERE e.id=:key and e.name=:value";
+        Query q = em.createQuery(jpql)
+                    .setParameter("key", 100)
+                    .setParameter("value", "XYZ");
+        
+        assertEquals(2, q.getParameters().size());
+        Parameter<?> param1 = q.getParameter("key");
+        Parameter<?> param2 = q.getParameter("value");
+        
+        assertEquals(100, q.getParameterValue("key"));
+        assertEquals(100, q.getParameterValue(param1));
+        assertEquals("XYZ", q.getParameterValue("value"));
+        assertEquals("XYZ", q.getParameterValue(param2));
+        
+        q.getResultList();
+    }
+    
     public void testPositionalParameterInJPQLQuery() {
         String jpql = "select e from simple e WHERE e.id=?1 and e.name=?2";
         Query q = em.createQuery(jpql)



Mime
View raw message