OPENJPA-1281: fix reparameter when PreparedQueryCache is on

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@810331 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2009-09-02 01:46:54 +00:00
parent 8c929e6e10
commit ac939f7b5f
3 changed files with 61 additions and 0 deletions

View File

@ -166,6 +166,20 @@ public final class SQLBuffer
_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;
}
}
}

View File

@ -28,6 +28,8 @@ import javax.persistence.ManyToOne;
public class CD extends Merchandise {
private String label;
private int status;
@ManyToOne
private Singer singer;
@ -55,4 +57,12 @@ public class CD extends Merchandise {
this.singer = singer;
singer.addCd(this);
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}

View File

@ -702,6 +702,43 @@ public class TestPreparedQueryCache extends TestCase {
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();
}