mirror of https://github.com/apache/openjpa.git
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:
parent
8c929e6e10
commit
ac939f7b5f
|
@ -166,6 +166,20 @@ public final class SQLBuffer
|
||||||
_userIndex.add(newIndex);
|
_userIndex.add(newIndex);
|
||||||
_userIndex.add(userParam);
|
_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ import javax.persistence.ManyToOne;
|
||||||
public class CD extends Merchandise {
|
public class CD extends Merchandise {
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
|
private int status;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private Singer singer;
|
private Singer singer;
|
||||||
|
|
||||||
|
@ -55,4 +57,12 @@ public class CD extends Merchandise {
|
||||||
this.singer = singer;
|
this.singer = singer;
|
||||||
singer.addCd(this);
|
singer.addCd(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -702,6 +702,43 @@ public class TestPreparedQueryCache extends TestCase {
|
||||||
assertNotNull(book2.getAuthors());
|
assertNotNull(book2.getAuthors());
|
||||||
assertFalse(book2.getAuthors().isEmpty());
|
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() {
|
PreparedQueryCache getPreparedQueryCache() {
|
||||||
return emf.getConfiguration().getQuerySQLCacheInstance();
|
return emf.getConfiguration().getQuerySQLCacheInstance();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue