openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r810331 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/
Date Wed, 02 Sep 2009 01:46:54 GMT
Author: faywang
Date: Wed Sep  2 01:46:54 2009
New Revision: 810331

URL: http://svn.apache.org/viewvc?rev=810331&view=rev
Log:
OPENJPA-1281: fix reparameter when PreparedQueryCache is on

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/CD.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java?rev=810331&r1=810330&r2=810331&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLBuffer.java Wed
Sep  2 01:46:54 2009
@@ -166,6 +166,20 @@
                 _userIndex.add(newIndex);
                 _userIndex.add(userParam);
             }
+        } else { 
+            if (_userIndex != null) {
+                List userIndex = new ArrayList();
+                for (int i = 0; i < _userIndex.size(); i+=2) {
+                    int oldIndex = ((Integer)_userIndex.get(i)).intValue();
+                    Object userParam = _userIndex.get(i+1);
+                    if (oldIndex >= paramIndex) 
+                        userIndex.add(oldIndex + paramIndex);
+                    else 
+                        userIndex.add(oldIndex);
+                    userIndex.add(userParam);
+                }
+                _userIndex = userIndex;
+            }
         }
     }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/CD.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/CD.java?rev=810331&r1=810330&r2=810331&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/CD.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/CD.java
Wed Sep  2 01:46:54 2009
@@ -28,6 +28,8 @@
 public class CD extends Merchandise {
     private String label;
     
+    private int status; 
+    
     @ManyToOne
     private Singer singer;
 
@@ -55,4 +57,12 @@
         this.singer = singer;
         singer.addCd(this);
     }
+    
+    public int getStatus() {
+        return status;
+    }
+    
+    public void setStatus(int status) {
+        this.status = status;
+    }     
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java?rev=810331&r1=810330&r2=810331&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/sqlcache/TestPreparedQueryCache.java
Wed Sep  2 01:46:54 2009
@@ -702,6 +702,43 @@
         assertNotNull(book2.getAuthors());
         assertFalse(book2.getAuthors().isEmpty());
     }
+
+    public void testQueryWithUserDefinedAndInternalParamtersInSubquery() {
+        String jpql = "Select a From Address a Where Not Exists ("
+            + "     Select s.id From Singer As s Where "
+            + "        s.address = a  And "
+            + "        Not ("
+            + "              (s.firstName = :firstName) "
+            + "              Or "
+            + "              ("
+            + "                  ("
+            + "                      exists (select c.id from CD c where c.singer = s and
c.status = 1) And "
+            + "                      s.lastName = :lastName"
+            + "                  ) "
+            + "                  Or "
+            + "                  ("
+            + "                      not exists (Select c.id from CD c where c.singer = s
and c.status = 2)"
+            + "                  )"
+            + "              )"
+            + "            )"
+            + "     )";
+        
+        Query jQ = em.createQuery(jpql);
+        jQ.setParameter("lastName", "LastName");
+        jQ.setParameter("firstName", "FirstName");
+        List jList = jQ.getResultList();
+        
+        Query jQ1 = em.createQuery(jpql);
+        jQ1.setParameter("lastName", "LastName1");
+        jQ1.setParameter("firstName", "FirstName1");
+        try {
+            List jList1 = jQ1.getResultList();
+        } catch (Exception e) {
+            fail("Fail to execute again - Parameters are messed up:" + e.getMessage());
+        }
+    }
+    
+    
     PreparedQueryCache getPreparedQueryCache() {
         return emf.getConfiguration().getQuerySQLCacheInstance();
     }



Mime
View raw message