From 983b34b68e9b5cf2fb5b78744f6bb2fcb654389c Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Wed, 11 Nov 2009 20:40:18 +0000 Subject: [PATCH] OPENJPA-1380: queryCache is not refreshed for cross-join jpql. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@835054 13f79535-47bb-0310-9956-ffa450edef68 --- .../kernel/jpql/JPQLExpressionBuilder.java | 2 + .../datacache/TestBulkJPQLAndDataCache.java | 1 + .../datacache/TestQueryResultSize.java | 47 +++++++++++++++---- .../common/apps/META-INF/persistence.xml | 2 + 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java index 5ec18e919..b03c4b4ee 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java @@ -827,6 +827,8 @@ public class JPQLExpressionBuilder // which is the desired candidate if (ctx().schemaAlias == null) setCandidate(cmd, alias); + else + addAccessPath(cmd); return exp; } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java index 2cb703485..791776e63 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestBulkJPQLAndDataCache.java @@ -35,6 +35,7 @@ public class TestBulkJPQLAndDataCache public void setUp() throws Exception { setUp("openjpa.DataCache", "true", "openjpa.RemoteCommitProvider", "sjvm", + CLEAR_TABLES, AllFieldTypes.class, CascadeParent.class, CascadeChild.class); OpenJPAEntityManager em = emf.createEntityManager(); diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestQueryResultSize.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestQueryResultSize.java index a7f32319f..e6f1300e5 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestQueryResultSize.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestQueryResultSize.java @@ -19,20 +19,17 @@ package org.apache.openjpa.persistence.datacache; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; + import javax.persistence.EntityManagerFactory; -import org.apache.openjpa.datacache.*; -import javax.persistence.*; -import org.apache.openjpa.persistence.*; - - -import org.apache.openjpa.persistence.datacache.common.apps.CacheObjectE; -import org.apache.openjpa.persistence.common.utils.AbstractTestCase; +import org.apache.openjpa.datacache.ConcurrentQueryCache; import org.apache.openjpa.persistence.OpenJPAEntityManager; +import org.apache.openjpa.persistence.OpenJPAPersistence; import org.apache.openjpa.persistence.OpenJPAQuery; +import org.apache.openjpa.persistence.common.utils.AbstractTestCase; +import org.apache.openjpa.persistence.datacache.common.apps.CacheObjectE; public class TestQueryResultSize extends AbstractTestCase { @@ -47,6 +44,8 @@ public class TestQueryResultSize public void setUp() { System.out.println("****Deleted Records " + deleteAll(CacheObjectE.class)); + deleteAll(CascadeParent.class); + deleteAll(CascadeChild.class); Map propsMap = new HashMap(); propsMap.put("openjpa.DataCache", "true"); propsMap.put("openjpa.QueryCache", "true"); @@ -81,4 +80,36 @@ public class TestQueryResultSize pm.getEntityManagerFactory()).getQueryResultCache().getDelegate())). getCacheMap().size()); } + + public void testCrossJoinQueryCache() { + pm = (OpenJPAEntityManager) _pmf.createEntityManager(); + // create + startTx(pm); + CascadeParent p = new CascadeParent(); + p.setName("p1"); + CascadeChild c = new CascadeChild(); + c.setName("p1"); + p.setChild(c); + pm.persist(p); + endTx(pm); + + // query + String jpql = "select p.name, c.name from CascadeParent p, CascadeChild c where p.name = c.name " + + "and p.name = 'p1'"; + javax.persistence.Query query = pm.createQuery(jpql); + List result1 = query.getResultList(); + assertEquals(1, result1.size()); + + // update + startTx(pm); + c.setName("c1"); + endTx(pm); + + // query again + List result2 = query.getResultList(); + assertEquals(0, result2.size()); + endEm(pm); + } + + } diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/datacache/common/apps/META-INF/persistence.xml b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/datacache/common/apps/META-INF/persistence.xml index 13aabf04a..51f608321 100644 --- a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/datacache/common/apps/META-INF/persistence.xml +++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/datacache/common/apps/META-INF/persistence.xml @@ -22,6 +22,8 @@ org.apache.openjpa.persistence.PersistenceProviderImpl + org.apache.openjpa.persistence.datacache.CascadeChild + org.apache.openjpa.persistence.datacache.CascadeParent org.apache.openjpa.persistence.datacache.common.apps.AppIdCacheObject org.apache.openjpa.persistence.datacache.common.apps.AttachA org.apache.openjpa.persistence.datacache.common.apps.AttachB