You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by ht...@apache.org on 2015/09/10 03:45:56 UTC
svn commit: r1702143 - in /openjpa/branches/2.2.x:
openjpa-kernel/src/main/java/org/apache/openjpa/datacache/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/
Author: hthomann
Date: Thu Sep 10 01:45:56 2015
New Revision: 1702143
URL: http://svn.apache.org/r1702143
Log:
OPENJPA-2586: Fix to return proper relationship data when QueryCache and FetchPlans are used.
Added:
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/QCEntityM2O.java
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/TestQueryCacheWithDataCache.java
Modified:
openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java?rev=1702143&r1=1702142&r2=1702143&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java (original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/QueryCacheStoreQuery.java Thu Sep 10 01:45:56 2015
@@ -342,6 +342,13 @@ public class QueryCacheStoreQuery
// Create a new FetchConfiguration that will be used to ensure that any JOIN FETCHed fields are loaded
StoreContext store = q.getContext().getStoreContext();
FetchConfiguration cacheFc = store.pushFetchConfiguration();
+
+ // OPENJPA-2586: If the FetchConfig for this executor contains fields,
+ // then add them to the new FetchConfig.
+ if (!_fc.getFields().isEmpty()) {
+ cacheFc.addFields(_fc.getFields());
+ }
+
for (QueryExpressions qe : _ex.getQueryExpressions()) {
for (String fetchFields : qe.fetchPaths) {
cacheFc.addField(fetchFields);
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/QCEntityM2O.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/QCEntityM2O.java?rev=1702143&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/QCEntityM2O.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/QCEntityM2O.java Thu Sep 10 01:45:56 2015
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.querycache;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+
+@Entity
+public class QCEntityM2O {
+ @Id
+ @Column(name = "PK")
+ private String pk;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ private QCEntity qc;
+
+ public QCEntityM2O(String pk) {
+ this.pk = pk;
+ }
+
+ public String getPk() {
+ return pk;
+ }
+
+ public void setPk(String pk) {
+ this.pk = pk;
+ }
+
+ public void setQc(QCEntity qc) {
+ this.qc = qc;
+ }
+
+ public QCEntity getQc() {
+ return qc;
+ }
+}
Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/TestQueryCacheWithDataCache.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/TestQueryCacheWithDataCache.java?rev=1702143&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/TestQueryCacheWithDataCache.java (added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/querycache/TestQueryCacheWithDataCache.java Thu Sep 10 01:45:56 2015
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.querycache;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.apache.openjpa.persistence.querycache.QCEntityM2O;
+import org.apache.openjpa.persistence.querycache.QCEntity;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestQueryCacheWithDataCache extends SingleEMFTestCase {
+
+ public void setUp() {
+ super.setUp(DROP_TABLES, QCEntityM2O.class, QCEntity.class, "openjpa.DataCache", "true",
+ "openjpa.RemoteCommitProvider", "sjvm", "openjpa.QueryCache", "true");
+ }
+
+ /*
+ * Test for OPENJPA-2586
+ */
+ public void testWithFetchPlan() {
+ populate();
+
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ doQueryWithFetchPlan(em);
+ em.getTransaction().commit();
+ em.close();
+
+ em = emf.createEntityManager();
+ em.getTransaction().begin();
+ doQueryWithFetchPlan(em);
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void doQueryWithFetchPlan(EntityManager em) {
+ String jpql = "Select e1 from QCEntityM2O e1";
+
+ Query q = em.createQuery(jpql);
+ FetchPlan fetchPlan = q.unwrap(OpenJPAQuery.class).getFetchPlan();
+ fetchPlan.addField(QCEntityM2O.class, "qc");
+ List<QCEntityM2O> results = (List<QCEntityM2O>) q.getResultList();
+
+ em.clear();
+
+ assertTrue("No results returned!", !results.isEmpty());
+ for (QCEntityM2O e1 : results) {
+ assertNotNull("A 'QCEntity' should have been returned!", e1.getQc());
+ }
+ }
+
+ public void populate() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ QCEntityM2O e1 = new QCEntityM2O("aQCEntityM2O");
+ QCEntity e2 = new QCEntity("aQCEntityM2O", "test", 2L);
+ e1.setQc(e2);
+
+ em.persist(e1);
+ em.persist(e2);
+
+ em.getTransaction().commit();
+ em.close();
+ }
+}