mirror of https://github.com/apache/openjpa.git
OPENJPA-1580: disable query cache when pagination is involved.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@925048 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15c64cb8f4
commit
13e3c48cae
|
@ -178,10 +178,14 @@ public class PreparedQueryImpl implements PreparedQuery {
|
|||
SQLBuffer buffer = selector.getSQL();
|
||||
if (buffer == null)
|
||||
return new PreparedQueryCacheImpl.StrongExclusion(_id, _loc.get("exclude-no-sql", _id).getMessage());;
|
||||
boolean useFieldStrategy = isUsingFieldStrategy();
|
||||
if (useFieldStrategy)
|
||||
if (isUsingFieldStrategy())
|
||||
return new PreparedQueryCacheImpl.StrongExclusion(_id,
|
||||
_loc.get("exclude-user-strategy", _id).getMessage());;
|
||||
|
||||
if (isPaginated())
|
||||
return new PreparedQueryCacheImpl.StrongExclusion(_id,
|
||||
_loc.get("exclude-pagination", _id).getMessage());;
|
||||
|
||||
setTargetQuery(buffer.getSQL());
|
||||
setParameters(buffer.getParameters());
|
||||
setUserParameterPositions(buffer.getUserParameters());
|
||||
|
@ -259,6 +263,14 @@ public class PreparedQueryImpl implements PreparedQuery {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean isPaginated() {
|
||||
if (select instanceof SelectImpl) {
|
||||
if (((SelectImpl)select).getStartIndex() != 0 ||
|
||||
((SelectImpl)select).getEndIndex() != Long.MAX_VALUE)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private boolean isUsingFieldStrategy() {
|
||||
for (int i = 0; i < _exps.length; i++) {
|
||||
if (isUsingFieldStrategy(_exps[i])) {
|
||||
|
|
|
@ -169,3 +169,5 @@ exclude-externalized-param: Query "{0}" is not cached because some parameterized
|
|||
field values are externalized.
|
||||
exclude-user-strategy: This query "{0}" is not cached because some parameterized \
|
||||
field value depends on user-defined field strategy.
|
||||
exclude-pagination: This query "{0}" involves pagination and is not cached.
|
||||
|
|
@ -974,7 +974,27 @@ public class TestPreparedQueryCache extends TestCase {
|
|||
em.getTransaction().rollback();
|
||||
}
|
||||
|
||||
public void testRangeIsExcluded() {
|
||||
List<Company> l = null;
|
||||
|
||||
l = getAllCompaniesPaged(0, 1);
|
||||
assertEquals(1, l.size());
|
||||
assertEquals("acme.org", l.get(0).getName());
|
||||
l = getAllCompaniesPaged(1, 1);
|
||||
assertEquals(1, l.size());
|
||||
assertEquals("BEA", l.get(0).getName());
|
||||
l = getAllCompaniesPaged(2, 1);
|
||||
assertEquals(1, l.size());
|
||||
assertEquals("IBM", l.get(0).getName());
|
||||
}
|
||||
|
||||
public List<Company> getAllCompaniesPaged(int start, int max) {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
Query q = em.createQuery("select p from Company p order by p.name");
|
||||
q.setFirstResult(start);
|
||||
q.setMaxResults(max);
|
||||
return (List<Company>) q.getResultList();
|
||||
}
|
||||
|
||||
PreparedQueryCache getPreparedQueryCache() {
|
||||
return emf.getConfiguration().getQuerySQLCacheInstance();
|
||||
|
|
Loading…
Reference in New Issue