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/01/28 16:28:40 UTC
svn commit: r1655360 - in /openjpa/trunk: ./
openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java
Author: hthomann
Date: Wed Jan 28 15:28:40 2015
New Revision: 1655360
URL: http://svn.apache.org/r1655360
Log:
OPENJPA-2536: FetchGroup is not returning lazy fields. Applied Rick Curtis' fix to trunk.
Modified:
openjpa/trunk/ (props changed)
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java
Propchange: openjpa/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 28 15:28:40 2015
@@ -1,6 +1,6 @@
/openjpa/branches/1.0.x:736493
/openjpa/branches/2.0.x:1504611
-/openjpa/branches/2.1.x:1415379,1415398,1485010,1513249,1517838,1530146,1533218,1533280,1539188,1569528,1575444,1591536,1636464
+/openjpa/branches/2.1.x:1415379,1415398,1485010,1513249,1517838,1530146,1533218,1533280,1539188,1569528,1575444,1591536,1636464,1655218
/openjpa/branches/2.2.1.x:1415367,1415413,1415425,1504719,1508186,1530347,1533222,1539193,1651808
/openjpa/branches/2.2.x:1384400,1415459-1415460,1415469,1485013,1530364,1533223,1580898,1580939,1591681,1631786
/openjpa/branches/2.3.x:1533462,1535560,1564121
Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=1655360&r1=1655359&r2=1655360&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java Wed Jan 28 15:28:40 2015
@@ -39,6 +39,7 @@ import java.util.TimeZone;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.conf.DetachOptions.FetchGroups;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.enhance.DynamicPersistenceCapable;
import org.apache.openjpa.enhance.FieldManager;
@@ -3209,7 +3210,7 @@ public class StateManagerImpl implements
fetch.addFetchGroup(lfg);
lfgAdded = true;
}
- } else if (fmd.isInDefaultFetchGroup() && fields == null) {
+ } else if (fetch.hasFetchGroup(FetchGroup.NAME_DEFAULT) && fmd.isInDefaultFetchGroup() && fields == null) {
// no load group but dfg: add dfg fields if we haven't already
if (!unloadedDFGFieldMarked)
fields = getUnloadedInternal(fetch, LOAD_FGS, null);
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java?rev=1655360&r1=1655359&r2=1655360&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/fetchgroups/TestFetchGroups.java Wed Jan 28 15:28:40 2015
@@ -25,26 +25,44 @@ import org.apache.openjpa.kernel.FetchCo
import org.apache.openjpa.persistence.FetchPlan;
import org.apache.openjpa.persistence.OpenJPAEntityManager;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
import org.apache.openjpa.persistence.test.SingleEMTestCase;
public class TestFetchGroups extends SingleEMTestCase {
private static final int empPerMgr = 5;
private static final int mgrCount = 3;
private static final int empCount = mgrCount * empPerMgr;
-
-
+
private HashSet<FGEmployee> employeeSet = new HashSet<FGEmployee>();
private HashSet<FGManager> managerSet = new HashSet<FGManager>();
-
+
private static final String empDescriptionFieldStr =
- "org.apache.openjpa.persistence.fetchgroups.FGEmployee.description";
-
+ "org.apache.openjpa.persistence.fetchgroups.FGEmployee.description";
+
public void setUp() {
- super.setUp(CLEAR_TABLES,
- FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class);
+ super.setUp(CLEAR_TABLES, FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class);
createEmployeeData();
}
-
+
+ public void testNoDefaultGroupLazyLoad() {
+ FGEmployee emp = employeeSet.iterator().next();
+ OpenJPAEntityManagerSPI em = emf.createEntityManager();
+
+ FGEmployee e = em.find(FGEmployee.class, emp.getId());
+ assertEquals(emp.getFirstName(), e.getFirstName());
+ em.clear();
+
+ em.getFetchPlan().resetFetchGroups().removeFetchGroup("default").addFetchGroups("AddressFetchGroup");
+ FGEmployee e2 = em.find(FGEmployee.class, emp.getId());
+ em.clear();
+ assertNull(e2.getFirstName());
+
+ FGEmployee e3 = em.find(FGEmployee.class, emp.getId());
+ assertEquals(emp.getFirstName(), e3.getFirstName());
+ em.close();
+
+ }
+
/**
* Verify the "default" fetch plan that models JPA's expected eager/lazy fetch load behaviors.
*/
@@ -55,99 +73,94 @@ public class TestFetchGroups extends Sin
assertNotNull(fp.getFetchGroups());
assertEquals(1, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.close();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
/**
- * Verify that adding a FetchGroup to the fetch plan makes a normally JPA determined lazy loaded
- * field to behave as an eagerly loaded field.
+ * Verify that adding a FetchGroup to the fetch plan makes a normally JPA determined lazy loaded field to behave as
+ * an eagerly loaded field.
*/
public void testDefaultFetchPlan002() {
OpenJPAEntityManager em = emf.createEntityManager();
FetchPlan fp = em.getFetchPlan();
assertNotNull(fp);
-
+
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
assertEquals(2, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.close();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
/**
- * Verify that adding a field to the fetch plan makes a normally JPA determined lazy loaded
- * field to behave as an eagerly loaded field.
+ * Verify that adding a field to the fetch plan makes a normally JPA determined lazy loaded field to behave as an
+ * eagerly loaded field.
*/
public void testDefaultFetchPlan003() {
OpenJPAEntityManager em = emf.createEntityManager();
FetchPlan fp = em.getFetchPlan();
assertNotNull(fp);
-
+
fp.addField(empDescriptionFieldStr);
assertNotNull(fp.getFetchGroups());
assertEquals(1, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFields().contains(empDescriptionFieldStr));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.close();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
-
+
/**
- * Verify the use of the "openjpa.FetchGroups" property when used to add a fetch group
- * to the default fetch plan. Note when overriding that "default" must be included in the list.
+ * Verify the use of the "openjpa.FetchGroups" property when used to add a fetch group to the default fetch plan.
+ * Note when overriding that "default" must be included in the list.
*/
public void testPctxDefaultFetchPlan001() {
- OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
- FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
- "openjpa.FetchGroups", "default,DescFetchGroup");
-
+ OpenJPAEntityManagerFactory emf2 =
+ createNamedEMF(getPersistenceUnitName(), FGManager.class, FGDepartment.class, FGEmployee.class,
+ FGAddress.class, "openjpa.FetchGroups", "default,DescFetchGroup");
+
OpenJPAEntityManager em = emf2.createEntityManager();
FetchPlan fp = em.getFetchPlan();
assertNotNull(fp);
@@ -155,37 +168,36 @@ public class TestFetchGroups extends Sin
assertEquals(2, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.close();
emf2.close();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
/**
- * Verify the use of the "openjpa.FetchGroups" property - when a list not containing "default"
- * is provided, then the PCtx's default fetch plan should not include it. This renders
- * fields normally eagerly loaded as per JPA rules to behave as lazy loaded fields.
+ * Verify the use of the "openjpa.FetchGroups" property - when a list not containing "default" is provided, then the
+ * PCtx's default fetch plan should not include it. This renders fields normally eagerly loaded as per JPA rules to
+ * behave as lazy loaded fields.
*
* Note that fetch groups are case sensitive, "default" != "Default".
*/
public void testPctxDefaultFetchPlan002() {
- OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
- FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
- "openjpa.FetchGroups", "Default,DescFetchGroup");
-
+ OpenJPAEntityManagerFactory emf2 =
+ createNamedEMF(getPersistenceUnitName(), FGManager.class, FGDepartment.class, FGEmployee.class,
+ FGAddress.class, "openjpa.FetchGroups", "Default,DescFetchGroup");
+
OpenJPAEntityManager em = emf2.createEntityManager();
FetchPlan fp = em.getFetchPlan();
assertNotNull(fp);
@@ -193,37 +205,36 @@ public class TestFetchGroups extends Sin
assertEquals(2, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.close();
emf2.close();
-
+
assertEquals(mgr.getId(), findMgr.getId()); // Identity is always loaded
assertNull(findMgr.getFirstName());
assertNull(findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
/**
- * Test clearFetchGroups(), which removes all fetch groups from the fetch plan and reactivates
- * the "default" fetch plan.
+ * Test clearFetchGroups(), which removes all fetch groups from the fetch plan and reactivates the "default" fetch
+ * plan.
*
- * Note that the method does not place "default" back in the list of active fetch groups, OPENJPA-2413
- * was opened to note this behavior.
+ * Note that the method does not place "default" back in the list of active fetch groups, OPENJPA-2413 was opened to
+ * note this behavior.
*/
public void testClearFetchGroups001() {
- OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
- FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
- "openjpa.FetchGroups", "Default,DescFetchGroup");
-
+ OpenJPAEntityManagerFactory emf2 =
+ createNamedEMF(getPersistenceUnitName(), FGManager.class, FGDepartment.class, FGEmployee.class,
+ FGAddress.class, "openjpa.FetchGroups", "Default,DescFetchGroup");
+
OpenJPAEntityManager em = emf2.createEntityManager();
FetchPlan fp = em.getFetchPlan();
assertNotNull(fp);
@@ -232,9 +243,8 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
fp.clearFetchGroups(); // OPENJPA-2413: now places "default" in the list of active fetch groups.
@@ -257,13 +267,12 @@ public class TestFetchGroups extends Sin
}
/**
- * The resetFetchGroups() method restores the fetch plan's active fetch plans to
- * the PCtx's configured default.
+ * The resetFetchGroups() method restores the fetch plan's active fetch plans to the PCtx's configured default.
*/
public void testResetFetchGroups001() {
- OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
- FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
- "openjpa.FetchGroups", "Default,DescFetchGroup");
+ OpenJPAEntityManagerFactory emf2 =
+ createNamedEMF(getPersistenceUnitName(), FGManager.class, FGDepartment.class, FGEmployee.class,
+ FGAddress.class, "openjpa.FetchGroups", "Default,DescFetchGroup");
OpenJPAEntityManager em = emf2.createEntityManager();
FetchPlan fp = em.getFetchPlan();
@@ -273,9 +282,8 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
@@ -294,115 +302,112 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("Default")); // Not the same as "default"
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
- // Verify that the PCtx default fetch plan was properly restored. "default" should not be enabled
+
+ // Verify that the PCtx default fetch plan was properly restored. "default" should not be enabled
// since it was not listed by openjpa.FetchGroups.
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.close();
emf2.close();
-
+
assertEquals(mgr.getId(), findMgr.getId()); // Identity is always loaded
-// assertNull(findMgr.getFirstName()); // Commented out, for OPENJPA-2420
-// assertNull(findMgr.getLastName());
+ // assertNull(findMgr.getFirstName()); // Commented out, for OPENJPA-2420
+ // assertNull(findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
/**
* Baseline test for Finder Cache
*/
public void testFinderCache001() {
OpenJPAEntityManager em = emf.createEntityManager();
-
+
FetchPlan fp = em.getFetchPlan();
assertNotNull(fp);
assertNotNull(fp.getFetchGroups());
assertEquals(1, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
{
// First find, to prime the Finder Cache
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
- }
-
+ }
+
em.close();
}
-
+
/**
- * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache,
- * as it currently lacks the ability to distinguish fetch plan configuration in its key value.
- * The PCtx's default fetch plan is the normal plan not modified by the "openjpa.FetchGroups"
- * property.
+ * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache, as it currently lacks the
+ * ability to distinguish fetch plan configuration in its key value. The PCtx's default fetch plan is the normal
+ * plan not modified by the "openjpa.FetchGroups" property.
*
- * In this variant, a find using the default fetch plan is first executed to prime the finder cache.
- * Finds operating under a modified fetch plan should not utilize sql stored in the finder cache.
+ * In this variant, a find using the default fetch plan is first executed to prime the finder cache. Finds operating
+ * under a modified fetch plan should not utilize sql stored in the finder cache.
*/
public void testFinderCache002() {
OpenJPAEntityManager em = emf.createEntityManager();
-
+
FetchPlan fp = em.getFetchPlan();
assertNotNull(fp);
assertNotNull(fp.getFetchGroups());
assertEquals(1, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
{
// First find, to prime the Finder Cache
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
// Add a fetch group to the fetch plan and verify expected behavior
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -410,18 +415,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Remove the fetch group previously added, and verify expected behavior
fp.removeFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -429,17 +434,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
- }
-
+ }
+
// Add a fetch group to the fetch plan and verify expected behavior
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -447,18 +452,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Reset the fetch plan, and verify expected behavior
fp.resetFetchGroups();
assertNotNull(fp.getFetchGroups());
@@ -469,13 +474,13 @@ public class TestFetchGroups extends Sin
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
// Add a fetch group to the fetch plan and verify expected behavior
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -518,13 +523,12 @@ public class TestFetchGroups extends Sin
}
/**
- * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache,
- * as it currently lacks the ability to distinguish fetch plan configuration in its key value.
- * The PCtx's default fetch plan is the normal plan not modified by the "openjpa.FetchGroups"
- * property.
+ * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache, as it currently lacks the
+ * ability to distinguish fetch plan configuration in its key value. The PCtx's default fetch plan is the normal
+ * plan not modified by the "openjpa.FetchGroups" property.
*
- * In this variant, a find using a modified fetch plan is first executed, which should not be added
- * to the finder cache.
+ * In this variant, a find using a modified fetch plan is first executed, which should not be added to the finder
+ * cache.
*/
public void testFinderCache003() {
OpenJPAEntityManager em = emf.createEntityManager();
@@ -538,9 +542,8 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
@@ -564,17 +567,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
- }
-
+ }
+
// Restore the fetch group to the fetch plan and verify expected behavior
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -582,18 +585,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Remove the "DescFetchGroup" fetch group, and verify expected behavior
fp.removeFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -601,17 +604,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
- }
-
+ }
+
// Restore the fetch group to the fetch plan and verify expected behavior
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -619,18 +622,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Reset the fetch plan, and verify expected behavior
fp.resetFetchGroups();
assertNotNull(fp.getFetchGroups());
@@ -638,17 +641,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
// Restore the fetch group to the fetch plan and verify expected behavior
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -691,15 +694,14 @@ public class TestFetchGroups extends Sin
}
/**
- * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache,
- * as it currently lacks the ability to distinguish fetch plan configuration in its key value.
- * The PCtx's default fetch plan is modified by the "openjpa.FetchGroups" property.
- *
+ * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache, as it currently lacks the
+ * ability to distinguish fetch plan configuration in its key value. The PCtx's default fetch plan is modified by
+ * the "openjpa.FetchGroups" property.
*/
public void testFinderCache004() {
- OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
- FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
- "openjpa.FetchGroups", "default,DescFetchGroup");
+ OpenJPAEntityManagerFactory emf2 =
+ createNamedEMF(getPersistenceUnitName(), FGManager.class, FGDepartment.class, FGEmployee.class,
+ FGAddress.class, "openjpa.FetchGroups", "default,DescFetchGroup");
OpenJPAEntityManager em = emf2.createEntityManager();
FetchPlan fp = em.getFetchPlan();
@@ -708,37 +710,36 @@ public class TestFetchGroups extends Sin
assertEquals(2, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
{
// First find, to prime the Finder Cache
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Remove a fetch group to the fetch plan and verify expected behavior
fp.removeFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -746,18 +747,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
// Restore the fetch group previously removed, and verify expected behavior
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -765,17 +766,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
- }
-
+ }
+
// Remove a fetch group to the fetch plan and verify expected behavior
fp.removeFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -783,18 +784,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
// Reset the fetch plan, and verify expected behavior
fp.resetFetchGroups();
assertNotNull(fp.getFetchGroups());
@@ -837,18 +838,18 @@ public class TestFetchGroups extends Sin
}
/**
- * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache,
- * as it currently lacks the ability to distinguish fetch plan configuration in its key value.
- * The PCtx's default fetch plan is modified by the "openjpa.FetchGroups" property.
- *
- * In this variant, a find using a modified fetch plan is first executed, which should not be added
- * to the finder cache.
- */
- public void testFinderCache005() {
- OpenJPAEntityManagerFactory emf2 = createNamedEMF(getPersistenceUnitName(),
- FGManager.class, FGDepartment.class, FGEmployee.class, FGAddress.class,
- "openjpa.FetchGroups", "default,DescFetchGroup");
-
+ * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache, as it currently lacks
+ * the ability to distinguish fetch plan configuration in its key value. The PCtx's default fetch plan is modified
+ * by the "openjpa.FetchGroups" property.
+ *
+ * In this variant, a find using a modified fetch plan is first executed, which should not be added to the finder
+ * cache.
+ */
+ public void testFinderCache005() {
+ OpenJPAEntityManagerFactory emf2 =
+ createNamedEMF(getPersistenceUnitName(), FGManager.class, FGDepartment.class, FGEmployee.class,
+ FGAddress.class, "openjpa.FetchGroups", "default,DescFetchGroup");
+
OpenJPAEntityManager em = emf2.createEntityManager();
FetchPlan fp = em.getFetchPlan();
assertNotNull(fp);
@@ -856,31 +857,30 @@ public class TestFetchGroups extends Sin
assertEquals(2, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
-
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
FGManager mgr = managerSet.iterator().next();
assertNotNull(mgr);
-
+
fp.removeFetchGroup("DescFetchGroup");
assertEquals(1, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
}
-
+
// Restore the "DescFetchGroup" fetch group, and verify expected behavior
fp.addFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -888,17 +888,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
- }
-
+ }
+
// Remove the "DescFetchGroup" fetch group, and verify expected behavior
fp.removeFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -906,17 +906,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
- }
-
+ }
+
// Reset the fetch plan, and verify expected behavior
fp.resetFetchGroups();
assertNotNull(fp.getFetchGroups());
@@ -924,17 +924,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Remove the "DescFetchGroup" fetch group, and verify expected behavior
fp.removeFetchGroup("DescFetchGroup");
assertNotNull(fp.getFetchGroups());
@@ -976,15 +976,14 @@ public class TestFetchGroups extends Sin
emf2.close();
}
- /**
- * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache,
- * as it currently lacks the ability to distinguish fetch plan configuration in its key value.
- * The PCtx's default fetch plan is the normal plan not modified by the "openjpa.FetchGroups"
- * property.
- *
- * In this variant, a find using the default fetch plan is first executed to prime the finder cache.
- * Finds operating under a modified fetch plan should not utilize sql stored in the finder cache.
- */
+ /**
+ * Only SQL generated by the PCtx's default fetch plan should be used by the finder cache, as it currently lacks
+ * the ability to distinguish fetch plan configuration in its key value. The PCtx's default fetch plan is the \
+ * normal plan not modified by the "openjpa.FetchGroups" property.
+ *
+ * In this variant, a find using the default fetch plan is first executed to prime the finder cache. Finds
+ * operating under a modified fetch plan should not utilize sql stored in the finder cache.
+ */
public void testFinderCache006() {
OpenJPAEntityManager em = emf.createEntityManager();
@@ -994,9 +993,8 @@ public class TestFetchGroups extends Sin
assertEquals(1, fp.getFetchGroups().size());
assertTrue(fp.getFetchGroups().contains("default"));
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
FGManager mgr = managerSet.iterator().next();
@@ -1031,18 +1029,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFields().contains(empDescriptionFieldStr));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Remove the field previously added, and verify expected behavior
fp.removeField(empDescriptionFieldStr);
assertNotNull(fp.getFetchGroups());
@@ -1050,17 +1048,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
- }
-
+ }
+
// Add a field to the fetch plan and verify expected behavior
fp.addField(empDescriptionFieldStr);
assertNotNull(fp.getFetchGroups());
@@ -1068,18 +1066,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFields().contains(empDescriptionFieldStr));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Reset the fetch groups, and verify expected behavior (note the reset doesn't remove added fields!)
fp.resetFetchGroups();
assertNotNull(fp.getFetchGroups());
@@ -1158,9 +1156,8 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFields().contains(empDescriptionFieldStr));
- FetchConfiguration fetchCfg = ((org.apache.openjpa.persistence.EntityManagerImpl) em)
- .getBroker()
- .getFetchConfiguration();
+ FetchConfiguration fetchCfg =
+ ((org.apache.openjpa.persistence.EntityManagerImpl) em).getBroker().getFetchConfiguration();
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
@@ -1184,17 +1181,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
- }
-
+ }
+
// Restore the field to the fetch plan and verify expected behavior
fp.addField(empDescriptionFieldStr);
assertNotNull(fp.getFetchGroups());
@@ -1202,18 +1199,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFields().contains(empDescriptionFieldStr));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Remove the "DescFetchGroup" fetch group, and verify expected behavior
fp.removeField(empDescriptionFieldStr);
assertNotNull(fp.getFetchGroups());
@@ -1221,17 +1218,17 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertFalse(fp.getFetchGroups().contains("DescFetchGroup"));
assertTrue(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertNull(findMgr.getDescription()); // Should be lazy-loaded
- }
-
+ }
+
// Restore the field to the fetch plan and verify expected behavior
fp.addField(empDescriptionFieldStr);
assertNotNull(fp.getFetchGroups());
@@ -1239,18 +1236,18 @@ public class TestFetchGroups extends Sin
assertTrue(fp.getFetchGroups().contains("default"));
assertTrue(fp.getFields().contains(empDescriptionFieldStr));
assertFalse(fetchCfg.isDefaultPUFetchGroupConfigurationOnly());
-
+
{
// Second find, should rely on the finder cache to reuse generated SQL.
FGManager findMgr = em.find(FGManager.class, mgr.getId());
em.clear();
-
+
assertEquals(mgr.getId(), findMgr.getId());
assertEquals(mgr.getFirstName(), findMgr.getFirstName());
assertEquals(mgr.getLastName(), findMgr.getLastName());
assertEquals(mgr.getDescription(), findMgr.getDescription()); // Should not be lazy-loaded
}
-
+
// Reset the fetch plan, and verify expected behavior (should not affect fields)
fp.resetFetchGroups();
assertNotNull(fp.getFetchGroups());
@@ -1339,42 +1336,42 @@ public class TestFetchGroups extends Sin
mgr.setDescription("Manager-" + id);
mgr.setAddress(addr);
mgr.setDept(dept);
-
+
em.persist(mgr);
-
+
managerSet.add(mgr);
}
-
+
// Create Employees
for (int i = 1; i < empCount; i++) {
int id = empIdIndex++;
int mgrId = (id % empPerMgr) + 1;
-
+
FGAddress addr = createAddress(id);
em.persist(addr);
-
+
FGDepartment dept = createDepartment(id);
em.persist(dept);
-
+
FGEmployee emp = new FGEmployee();
- emp.setId(id);
+ emp.setId(id);
emp.setFirstName("First-" + id);
emp.setLastName("Last-" + id);
emp.setRating("Rating-" + id);
emp.setDescription("Employee-" + id);
emp.setAddress(addr);
emp.setDept(dept);
-
+
em.persist(emp);
-
+
employeeSet.add(emp);
}
-
+
em.getTransaction().commit();
-
+
em.close();
}
-
+
private FGAddress createAddress(int id) {
FGAddress addr = new FGAddress();
addr.setId(id);
@@ -1382,15 +1379,15 @@ public class TestFetchGroups extends Sin
addr.setCity("City-" + id);
addr.setState("State-" + id);
addr.setZip(id);
-
+
return addr;
}
-
+
private FGDepartment createDepartment(int id) {
FGDepartment dept = new FGDepartment();
dept.setId(id);
dept.setName("Department-" + id);
-
+
return dept;
}
}