use of org.datanucleus.FetchPlanForClass in project tests by datanucleus.
the class FetchPlanTest method testPostLoad.
/**
* Test the use of "postload"
*/
public void testPostLoad() throws Exception {
FetchPlan fp = getFetchPlan();
PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(FP2Base.class, new ClassLoaderResolverImpl());
// --------------------------------------
// all fields in DFG
// --------------------------------------
FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
boolean[] loadedFields = new boolean[14];
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
// --------------------------------------
// fetch group width postLoad + DFG
// --------------------------------------
fp.addGroup("groupD");
fpc = fp.getFetchPlanForClass(cmd);
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
// --------------------------------------
// fetch group width postLoad
// --------------------------------------
fp.addGroup("groupD");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
// --------------------------------------
// fetch group without postLoad
// --------------------------------------
fp.addGroup("groupC");
fp.removeGroup("groupD");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertFalse("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
// --------------------------------------
// fetch group width postLoad
// --------------------------------------
fp.addGroup("groupAll");
fp.removeGroup("groupC");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
}
use of org.datanucleus.FetchPlanForClass in project tests by datanucleus.
the class FetchPlanTest method testDynamicFetchPlanViaPMF.
/**
* Test the use of the dynamic fetch plans via PMF.
*/
public void testDynamicFetchPlanViaPMF() {
JDOPersistenceManagerFactory myPMF = (JDOPersistenceManagerFactory) pmf;
AbstractClassMetaData cmd = myPMF.getNucleusContext().getMetaDataManager().getMetaDataForClass(FP2Base.class, new ClassLoaderResolverImpl());
FetchPlan fp = getFetchPlan();
// Test initial without DFG - should only have PK in fetch plan for PlaneA
fp.removeGroup(FetchPlan.DEFAULT);
FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
int[] fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 1 fields in fetchplan (PK)", 1, fieldsInFP.length);
BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
// Test empty group - should only have PK in fetch plan
javax.jdo.FetchGroup grp1 = myPMF.getFetchGroup(FP2Base.class, "MyGroupPMF");
myPMF.addFetchGroups(grp1);
fp.addGroup("MyGroupPMF");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 1, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
// Test group for other class
javax.jdo.FetchGroup grp2 = myPMF.getFetchGroup(FP3Base.class, "MyGroupPMF2");
grp2.addMember("room2");
fp.clearGroups();
fp.removeGroup(FetchPlan.DEFAULT);
fp.addGroup("MyGroupPMF2");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 1, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
// Test one group
grp1 = myPMF.getFetchGroup(FP2Base.class, "MyGroupPMF");
grp1.addMember("piece4").addMember("piece7").addMember("piece10");
fp.setGroup("MyGroupPMF");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 4, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
// Test dynamic update to existing group after use
myPMF.getFetchGroup(FP2Base.class, "MyGroupPMF").removeMember("piece7");
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 3, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
// Test multiple groups for same class
grp1 = myPMF.getFetchGroup(FP2Base.class, "MyGroupPMF1");
grp1.addMember("piece4").addMember("piece5");
grp2 = myPMF.getFetchGroup(FP2Base.class, "MyGroupPMF2");
grp2.addMember("piece7").addMember("piece8");
javax.jdo.FetchGroup grp3 = myPMF.getFetchGroup(FP2Base.class, "MyGroupPMF3");
grp3.addMember("piece10");
myPMF.removeAllFetchGroups();
myPMF.addFetchGroups(new javax.jdo.FetchGroup[] { grp1, grp2, grp3 });
fp.setGroups(new String[] { "MyGroupPMF1", "MyGroupPMF2", "MyGroupPMF3" });
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 6, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
}
use of org.datanucleus.FetchPlanForClass in project tests by datanucleus.
the class FetchPlanTest method testDynamicFetchPlanViaPM.
/**
* Test the use of the dynamic fetch plans via PM.
*/
public void testDynamicFetchPlanViaPM() {
JDOPersistenceManagerFactory myPMF = (JDOPersistenceManagerFactory) pmf;
AbstractClassMetaData cmd = myPMF.getNucleusContext().getMetaDataManager().getMetaDataForClass(FP2Base.class, new ClassLoaderResolverImpl());
JDOPersistenceManager myPM = (JDOPersistenceManager) myPMF.getPersistenceManager();
FetchPlan fp = ((JDOFetchPlan) myPM.getFetchPlan()).getInternalFetchPlan();
// Test initial without DFG - should only have PK in fetch plan for PlaneA
fp.removeGroup(FetchPlan.DEFAULT);
FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
int[] fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 1 fields in fetchplan (PK)", 1, fieldsInFP.length);
BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
// Test empty group - should only have PK in fetch plan for PlaneA
javax.jdo.FetchGroup grp1 = myPM.getFetchGroup(FP2Base.class, "MyGroupPM");
fp.addGroup("MyGroupPM");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 1, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
// Test group for other class
javax.jdo.FetchGroup grp2 = myPM.getFetchGroup(FP3Base.class, "MyGroupPM2");
grp2.addMember("room2");
fp.clearGroups();
fp.removeGroup(FetchPlan.DEFAULT);
fp.addGroup("MyGroupPM2");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 1, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
// Test one group
grp1 = myPM.getFetchGroup(FP2Base.class, "MyGroupPM");
grp1.addMember("piece4").addMember("piece7").addMember("piece10");
fp.setGroup("MyGroupPM");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 4, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
// Test dynamic update to existing group after use
myPM.getFetchGroup(FP2Base.class, "MyGroupPM").removeMember("piece7");
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 3, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
// Test multiple groups for same class
grp1 = myPM.getFetchGroup(FP2Base.class, "MyGroupPM1");
grp1.addMember("piece4").addMember("piece5");
grp2 = myPM.getFetchGroup(FP2Base.class, "MyGroupPM2");
grp2.addMember("piece7").addMember("piece8");
javax.jdo.FetchGroup grp3 = myPM.getFetchGroup(FP2Base.class, "MyGroupPM3");
grp3.addMember("piece10");
myPMF.removeAllFetchGroups();
myPMF.addFetchGroups(new javax.jdo.FetchGroup[] { grp1, grp2, grp3 });
fp.setGroups(new String[] { "MyGroupPM1", "MyGroupPM2", "MyGroupPM3" });
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("Incorrect number of fields in FetchPlan", 6, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
}
use of org.datanucleus.FetchPlanForClass in project datanucleus-rdbms by datanucleus.
the class QueryToSQLMapper method compileResult.
/**
* Method to compile the result clause of the query into the SQLStatement.
* Note that this also compiles queries of the candidate (no specified result), selecting the candidate field(s).
* @param stmt SELECT statement
*/
protected void compileResult(SelectStatement stmt) {
compileComponent = CompilationComponent.RESULT;
boolean unionsPresent = stmt.getNumberOfUnions() > 0;
// TODO Cater for more expression types where we have UNIONs and select each UNION separately
if (compilation.getExprResult() != null) {
// Select any result expressions
Expression[] resultExprs = compilation.getExprResult();
for (int i = 0; i < resultExprs.length; i++) {
String alias = resultExprs[i].getAlias();
if (alias != null && resultAliases == null) {
resultAliases = new HashSet<>();
}
if (resultExprs[i] instanceof InvokeExpression || resultExprs[i] instanceof ParameterExpression || resultExprs[i] instanceof Literal) {
// Process expressions that need no special treatment
if (resultExprs[i] instanceof InvokeExpression) {
processInvokeExpression((InvokeExpression) resultExprs[i]);
} else if (resultExprs[i] instanceof ParameterExpression) {
// Second argument : parameters are literals in result
processParameterExpression((ParameterExpression) resultExprs[i], true);
} else {
processLiteral((Literal) resultExprs[i]);
}
SQLExpression sqlExpr = stack.pop();
validateExpressionForResult(sqlExpr);
int[] cols = stmt.select(sqlExpr, alias);
StatementMappingIndex idx = new StatementMappingIndex(sqlExpr.getJavaTypeMapping());
idx.setColumnPositions(cols);
if (alias != null) {
resultAliases.add(alias);
idx.setColumnAlias(alias);
}
resultDefinition.addMappingForResultExpression(i, idx);
} else if (resultExprs[i] instanceof PrimaryExpression) {
PrimaryExpression primExpr = (PrimaryExpression) resultExprs[i];
if (primExpr.getId().equals(candidateAlias)) {
// "this", so select fetch plan fields
if (unionsPresent) {
// Process the first union separately (in case they have TYPE/instanceof) and then handle remaining UNIONs below
stmt.setAllowUnions(false);
}
StatementClassMapping map = new StatementClassMapping(candidateCmd.getFullClassName(), null);
SQLStatementHelper.selectFetchPlanOfCandidateInStatement(stmt, map, candidateCmd, fetchPlan, 1);
resultDefinition.addMappingForResultExpression(i, map);
if (unionsPresent) {
// Process remaining UNIONs. Assumed that we have the same result mapping as the first UNION otherwise SQL wouldn't work anyway
stmt.setAllowUnions(true);
List<SelectStatement> unionStmts = stmt.getUnions();
SelectStatement originalStmt = stmt;
for (SelectStatement unionStmt : unionStmts) {
this.stmt = unionStmt;
unionStmt.setQueryGenerator(this);
unionStmt.setAllowUnions(false);
StatementClassMapping dummyClsMapping = new StatementClassMapping(candidateCmd.getFullClassName(), null);
SQLStatementHelper.selectFetchPlanOfCandidateInStatement(unionStmt, dummyClsMapping, candidateCmd, fetchPlan, 1);
unionStmt.setQueryGenerator(null);
unionStmt.setAllowUnions(true);
}
this.stmt = originalStmt;
}
} else {
processPrimaryExpression(primExpr);
SQLExpression sqlExpr = stack.pop();
validateExpressionForResult(sqlExpr);
if (primExpr.getId().endsWith("#KEY") || primExpr.getId().endsWith("#VALUE")) {
// JPQL KEY(map) or VALUE(map), so select FetchPlan fields where persistable
if (sqlExpr.getJavaTypeMapping() instanceof PersistableMapping) {
// Method returns persistable object, so select the FetchPlan
String selectedType = ((PersistableMapping) sqlExpr.getJavaTypeMapping()).getType();
AbstractClassMetaData selectedCmd = ec.getMetaDataManager().getMetaDataForClass(selectedType, clr);
FetchPlanForClass fpForCmd = fetchPlan.getFetchPlanForClass(selectedCmd);
int[] membersToSelect = fpForCmd.getMemberNumbers();
ClassTable selectedTable = (ClassTable) sqlExpr.getSQLTable().getTable();
StatementClassMapping map = new StatementClassMapping(selectedCmd.getFullClassName(), null);
if (selectedCmd.getIdentityType() == IdentityType.DATASTORE) {
int[] cols = stmt.select(sqlExpr.getSQLTable(), selectedTable.getSurrogateMapping(SurrogateColumnType.DATASTORE_ID, false), alias);
StatementMappingIndex idx = new StatementMappingIndex(selectedTable.getSurrogateMapping(SurrogateColumnType.DATASTORE_ID, false));
idx.setColumnPositions(cols);
map.addMappingForMember(SurrogateColumnType.DATASTORE_ID.getFieldNumber(), idx);
}
// Select the FetchPlan members
for (int memberToSelect : membersToSelect) {
AbstractMemberMetaData selMmd = selectedCmd.getMetaDataForManagedMemberAtAbsolutePosition(memberToSelect);
// TODO Arbitrary penultimate argument
SQLStatementHelper.selectMemberOfSourceInStatement(stmt, map, fetchPlan, sqlExpr.getSQLTable(), selMmd, clr, 1, null);
}
resultDefinition.addMappingForResultExpression(i, map);
continue;
} else if (sqlExpr.getJavaTypeMapping() instanceof EmbeddedMapping) {
// Method returns embedded object, so select the FetchPlan
EmbeddedMapping embMapping = (EmbeddedMapping) sqlExpr.getJavaTypeMapping();
AbstractClassMetaData selectedCmd = ec.getMetaDataManager().getMetaDataForClass(embMapping.getType(), clr);
// Select the FetchPlan members
StatementClassMapping map = new StatementClassMapping(selectedCmd.getFullClassName(), null);
int[] membersToSelect = fetchPlan.getFetchPlanForClass(selectedCmd).getMemberNumbers();
for (int memberToSelect : membersToSelect) {
AbstractMemberMetaData selMmd = selectedCmd.getMetaDataForManagedMemberAtAbsolutePosition(memberToSelect);
JavaTypeMapping selMapping = embMapping.getJavaTypeMapping(selMmd.getName());
if (selMapping.includeInFetchStatement()) {
int[] cols = stmt.select(sqlExpr.getSQLTable(), selMapping, alias);
StatementMappingIndex idx = new StatementMappingIndex(selMapping);
idx.setColumnPositions(cols);
map.addMappingForMember(memberToSelect, idx);
}
}
resultDefinition.addMappingForResultExpression(i, map);
continue;
}
}
// TODO If the user selects an alias here that is joined, should maybe respect FetchPlan for that (like above for candidate)
// TODO Cater for use of UNIONs (e.g "complete-table" inheritance) where mapping is different in other UNION
// The difficulty here is that processPrimaryExpression makes use of the sqlTableByPrimary lookup, which is based on the primary statement, so
// it still doesn't find the right table/mapping for the UNIONed statements.
int[] cols = null;
if (sqlExpr instanceof SQLLiteral) {
cols = stmt.select(sqlExpr, alias);
} else {
cols = stmt.select(sqlExpr.getSQLTable(), sqlExpr.getJavaTypeMapping(), alias);
}
StatementMappingIndex idx = new StatementMappingIndex(sqlExpr.getJavaTypeMapping());
idx.setColumnPositions(cols);
if (alias != null) {
resultAliases.add(alias);
idx.setColumnAlias(alias);
}
resultDefinition.addMappingForResultExpression(i, idx);
}
} else if (resultExprs[i] instanceof VariableExpression) {
// Subquery?
processVariableExpression((VariableExpression) resultExprs[i]);
SQLExpression sqlExpr = stack.pop();
validateExpressionForResult(sqlExpr);
if (sqlExpr instanceof UnboundExpression) {
// Variable wasn't bound in the compilation so far, so handle as cross-join
processUnboundExpression((UnboundExpression) sqlExpr);
sqlExpr = stack.pop();
NucleusLogger.QUERY.debug("QueryToSQL.exprResult variable was still unbound, so binding via cross-join");
}
int[] cols = stmt.select(sqlExpr, alias);
StatementMappingIndex idx = new StatementMappingIndex(sqlExpr.getJavaTypeMapping());
idx.setColumnPositions(cols);
if (alias != null) {
resultAliases.add(alias);
idx.setColumnAlias(alias);
}
resultDefinition.addMappingForResultExpression(i, idx);
} else if (resultExprs[i] instanceof TypeExpression) {
// TYPE(identification_variable | single_valued_path_expr | input_parameter)
TypeExpression typeExpr = (TypeExpression) resultExprs[i];
Expression containedExpr = typeExpr.getContainedExpression();
if (containedExpr instanceof PrimaryExpression) {
processPrimaryExpression((PrimaryExpression) containedExpr);
SQLExpression sqlExpr = stack.pop();
JavaTypeMapping discrimMapping = sqlExpr.getSQLTable().getTable().getSurrogateMapping(SurrogateColumnType.DISCRIMINATOR, true);
if (discrimMapping == null) {
// TODO If we have a UNIONED primary expression then it would be possible to just select the DN_TYPE from the particular union
throw new NucleusException("Result has call to " + typeExpr + " but contained expression has no discriminator. Not supported");
}
int[] cols = stmt.select(sqlExpr.getSQLTable(), discrimMapping, null, true);
StatementMappingIndex idx = new StatementMappingIndex(discrimMapping);
idx.setColumnPositions(cols);
resultDefinition.addMappingForResultExpression(i, idx);
} else {
throw new NucleusException("Result has call to " + typeExpr + " but contained expression not supported");
}
} else if (resultExprs[i] instanceof CreatorExpression) {
processCreatorExpression((CreatorExpression) resultExprs[i]);
NewObjectExpression sqlExpr = (NewObjectExpression) stack.pop();
StatementNewObjectMapping stmtMap = getStatementMappingForNewObjectExpression(sqlExpr, stmt);
resultDefinition.addMappingForResultExpression(i, stmtMap);
} else if (resultExprs[i] instanceof DyadicExpression || resultExprs[i] instanceof CaseExpression) {
if (unionsPresent) {
// Process the first union separately (in case they have TYPE/instanceof) and then handle remaining UNIONs below
stmt.setAllowUnions(false);
}
resultExprs[i].evaluate(this);
SQLExpression sqlExpr = stack.pop();
int[] cols = stmt.select(sqlExpr, alias);
StatementMappingIndex idx = new StatementMappingIndex(sqlExpr.getJavaTypeMapping());
idx.setColumnPositions(cols);
if (alias != null) {
resultAliases.add(alias);
idx.setColumnAlias(alias);
}
resultDefinition.addMappingForResultExpression(i, idx);
if (unionsPresent) {
// Process remaining UNIONs. Assumed that we have the same result mapping as the first UNION otherwise SQL wouldn't work anyway
stmt.setAllowUnions(true);
List<SelectStatement> unionStmts = stmt.getUnions();
SelectStatement originalStmt = stmt;
for (SelectStatement unionStmt : unionStmts) {
this.stmt = unionStmt;
unionStmt.setQueryGenerator(this);
unionStmt.setAllowUnions(false);
resultExprs[i].evaluate(this);
sqlExpr = stack.pop();
unionStmt.select(sqlExpr, alias);
unionStmt.setQueryGenerator(null);
unionStmt.setAllowUnions(true);
}
this.stmt = originalStmt;
}
} else {
throw new NucleusException("Dont currently support result clause containing expression of type " + resultExprs[i]);
}
}
if (stmt.getNumberOfSelects() == 0) {
// Nothing selected so likely the user had some "new MyClass()" expression, so select "1"
stmt.select(exprFactory.newLiteral(stmt, storeMgr.getMappingManager().getMapping(Integer.class), 1), null);
}
} else {
// Select of the candidate (no result)
if (candidateCmd.getIdentityType() == IdentityType.NONDURABLE) {
// Nondurable identity cases have no "id" for later fetching so get all fields now
if (NucleusLogger.QUERY.isDebugEnabled()) {
NucleusLogger.QUERY.debug(Localiser.msg("052520", candidateCmd.getFullClassName()));
}
fetchPlan.setGroup("all");
}
if (subclasses) {
// TODO Check for special case of candidate+subclasses stores in same table with discriminator, so select FetchGroup of subclasses also
}
int maxFetchDepth = fetchPlan.getMaxFetchDepth();
if (maxFetchDepth < 0) {
NucleusLogger.QUERY.debug("No limit specified on query fetch so limiting to 3 levels from candidate. " + "Specify the '" + PropertyNames.PROPERTY_MAX_FETCH_DEPTH + "' to override this");
// TODO Arbitrary
maxFetchDepth = 3;
}
// This means that we then cater for a UNION using a different column name than the primary statement
if (unionsPresent) {
// Process the first union separately (in case they have TYPE/instanceof) and then handle remaining UNIONs below
stmt.setAllowUnions(false);
}
selectFetchPlanForCandidate(stmt, resultDefinitionForClass, maxFetchDepth);
if (unionsPresent) {
// Process remaining UNIONs. Assumed that we have the same result mapping as the first UNION otherwise SQL wouldn't work anyway
stmt.setAllowUnions(true);
List<SelectStatement> unionStmts = stmt.getUnions();
SelectStatement originalStmt = stmt;
for (SelectStatement unionStmt : unionStmts) {
this.stmt = unionStmt;
unionStmt.setQueryGenerator(this);
unionStmt.setAllowUnions(false);
// We don't want to overwrite anything in the root StatementClassMapping
StatementClassMapping dummyResClsMapping = new StatementClassMapping();
selectFetchPlanForCandidate(unionStmt, dummyResClsMapping, maxFetchDepth);
unionStmt.setQueryGenerator(null);
unionStmt.setAllowUnions(true);
}
this.stmt = originalStmt;
}
}
compileComponent = null;
}
use of org.datanucleus.FetchPlanForClass in project tests by datanucleus.
the class FetchPlanTest method testFetchPlan.
/**
* Test the use of the fetch plan.
*/
public void testFetchPlan() {
FetchPlan fp = getFetchPlan();
PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(FP2Base.class, new ClassLoaderResolverImpl());
// --------------------------------------
// all fields in DFG
// --------------------------------------
FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
int[] fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 11 fields in fetchplan", 11, fieldsInFP.length);
// check if fields are in the FP
BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// one FG + DFG
// --------------------------------------
fp.addGroup("groupA");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 11 fields in fetchplan", 11, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// one FG
// --------------------------------------
fp.addGroup("groupA");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 3 fields in fetchplan", 3, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertFalse("piece7 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertFalse("piece8 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertFalse("piece9 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// two FG
// --------------------------------------
fp.addGroup("groupA");
fp.addGroup("groupC");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 6 fields in fetchplan", 6, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// three FG
// --------------------------------------
fp.addGroup("groupA");
fp.addGroup("groupB");
fp.addGroup("groupC");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 9 fields in fetchplan", 9, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// four FG
// --------------------------------------
fp.addGroup("groupA");
fp.addGroup("groupB");
fp.addGroup("groupC");
fp.addGroup("groupD");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 12 fields in fetchplan", 12, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertTrue("piece12 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// three FG
// --------------------------------------
fp.removeGroup("groupD");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 9 fields in fetchplan", 9, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// two FG
// --------------------------------------
fp.removeGroup("groupB");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 6 fields in fetchplan", 6, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// one FG
// --------------------------------------
fp.removeGroup("groupC");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 3 fields in fetchplan", 3, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertFalse("piece7 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertFalse("piece8 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertFalse("piece9 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// removed all groups, so use DFG = all fields in DFG
// --------------------------------------
fp.removeGroup("groupA");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 1 fields in fetchplan", 1, fieldsInFP.length);
// check if fields are in the FP
fp.addGroup(FetchPlan.DEFAULT);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 11 fields in fetchplan", 11, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// fetch group with nested fetch groups
// --------------------------------------
fp.addGroup("groupAll");
fp.removeGroup("groupA");
fp.removeGroup("groupB");
fp.removeGroup("groupC");
fp.removeGroup("groupD");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 12 fields in fetchplan", 12, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertTrue("piece12 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// test an intersection, first add all groups, and then remove all, except the one with fields in intersection
// --------------------------------------
fp.addGroup("groupA");
fp.addGroup("groupB");
fp.addGroup("groupC");
fp.addGroup("groupD");
fp.addGroup("groupAll");
fp.addGroup("groupIntersection");
fp.removeGroup("groupA");
fp.removeGroup("groupB");
fp.removeGroup("groupC");
fp.removeGroup("groupD");
fp.removeGroup("groupAll");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 4 fields in fetchplan", 4, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertFalse("piece2 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertFalse("piece3 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertFalse("piece8 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertFalse("piece9 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// use FetchPlan.ALL
// --------------------------------------
fp.clearGroups();
fp.addGroup(FetchPlan.ALL);
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 13 fields in fetchplan", 13, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertTrue("piece12 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
assertTrue("piece14 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece14")));
// --------------------------------------
// use FetchPlan.NONE
// --------------------------------------
fp.clearGroups();
fp.addGroup(FetchPlan.NONE);
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 1 fields in fetchplan", 1, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertFalse("piece2 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertFalse("piece3 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertFalse("piece7 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertFalse("piece8 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertFalse("piece9 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
}
Aggregations