openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r898936 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/
Date Wed, 13 Jan 2010 20:49:02 GMT
Author: faywang
Date: Wed Jan 13 20:49:01 2010
New Revision: 898936

URL: http://svn.apache.org/viewvc?rev=898936&view=rev
Log:
OPENJPA-1458: fix named parameter problem

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/OrderedMap.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestQueryParameterBinding.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=898936&r1=898935&r2=898936&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
Wed Jan 13 20:49:01 2010
@@ -1614,8 +1614,7 @@
                 throw parseException(EX_USER, "bad-positional-parameter",
                     new Object[]{ id }, null);
         } else {
-            // otherwise the index is just the current size of the parameters
-            index = parameterTypes.size()-1;
+            index = parameterTypes.indexOf(id);
         }
         Parameter param = isCollectionValued 
             ? factory.newCollectionValuedParameter(paramKey, TYPE_OBJECT) 

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/OrderedMap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/OrderedMap.java?rev=898936&r1=898935&r2=898936&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/OrderedMap.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/OrderedMap.java Wed
Jan 13 20:49:01 2010
@@ -52,7 +52,7 @@
     public int indexOf(Object key) {
         int i = 0;
         for (K k : _del.keySet()) {
-            if (key == k)
+            if (key.equals(k))
                 return i;
             i++;
         }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestQueryParameterBinding.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestQueryParameterBinding.java?rev=898936&r1=898935&r2=898936&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestQueryParameterBinding.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestQueryParameterBinding.java
Wed Jan 13 20:49:01 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.openjpa.persistence.jdbc.query;
 
+import java.util.List;
+
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
@@ -248,7 +250,20 @@
 		
 		fail(q);
 	}
-	
+
+    public void testRepeatedNamedParameters() {
+        String JPQL_POSITIONAL =
+            JPQL + "WHERE p.p1 in (select max(p.p1) from Binder p where p.p1=:p1 AND p.p2=:p2
AND p.p3=:p3) "
+            + "AND p.p1=:p1 AND p.p2=:p2 AND p.p3=:p3";
+        Query q = em.createQuery(JPQL_POSITIONAL);
+        q.setParameter("p1",  INT_VALUE);
+        q.setParameter("p2",  STR_VALUE);
+        q.setParameter("p3",  DBL_VALUE);
+        List list = q.getResultList();
+        assertEquals(1, list.size());
+    }
+
+    
     void assertSetParameterFails(Query q, String name, Object v) {
         try {
             q.setParameter(name, v);



Mime
View raw message