use of org.datanucleus.ClassLoaderResolverImpl 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")));
}
use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.
the class FetchPlanTest method testNestedFetchPlans.
/**
* Test of nested fetch plans
*/
public void testNestedFetchPlans() throws Exception {
FetchPlan fp = getFetchPlan();
PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(FP2Base.class, new ClassLoaderResolverImpl());
fp.addGroup("defaultPlus12");
FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece12 should be in fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
}
use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.
the class FetchPlanTest method testFetchPlanInheritance.
/**
* Test the use of fetch plans with inherited objects.
*/
public void testFetchPlanInheritance() {
FetchPlan fp = getFetchPlan();
PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
// test parent with fetch-group = group1
AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(DetachParent.class, new ClassLoaderResolverImpl());
fp.addGroup("group1");
fp.removeGroup(FetchPlan.DEFAULT);
FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
int[] fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 2 fields in fetchplan", 2, fieldsInFP.length);
BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("fieldA should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldA")));
assertTrue("fieldB should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldB")));
// test child with fetch-group = group1
cmd = metaMgr.getMetaDataForClass(DetachChildA.class, new ClassLoaderResolverImpl());
fp.addGroup("group1");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 3 fields in fetchplan", 3, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("fieldA should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldA")));
assertTrue("fieldB should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldB")));
assertFalse("fieldC should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldC")));
assertFalse("fieldD should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldD")));
assertTrue("fieldE should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldE")));
// test child with no fetch-groups
cmd = metaMgr.getMetaDataForClass(DetachChildB.class, new ClassLoaderResolverImpl());
fp.addGroup("group1");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 2 fields in fetchplan", 2, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("fieldA should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldA")));
assertTrue("fieldB should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("fieldB")));
cmd = metaMgr.getMetaDataForClass(FP2Sub.class, new ClassLoaderResolverImpl());
// --------------------------------------
// use FetchPlan.ALL
// --------------------------------------
fp.clearGroups();
fp.addGroup(FetchPlan.ALL);
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 17 fields in fetchplan", 17, 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")));
assertTrue("piece20 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece20")));
assertTrue("piece21 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece21")));
assertTrue("piece22 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece22")));
assertTrue("piece23 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece23")));
}
use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.
the class BasicTest method testLoadingMetaDataFileLocations.
/**
* Test to check the loading of MetaData files from valid locations.
*/
public void testLoadingMetaDataFileLocations() {
MetaDataManager mmgr = new PersistenceNucleusContextImpl("JDO", null).getMetaDataManager();
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
// Check for a class defined in its own MetaData file
AbstractClassMetaData cmd = mmgr.getMetaDataForClass(PackageClassWidget.class, clr);
assertNotNull("MetaData is null!", cmd);
assertNotNull("Metadata", cmd);
assertEquals(PackageClassWidget.class.getName(), cmd.getFullClassName());
assertEquals("org.datanucleus.samples.widget", cmd.getPackageName());
assertNull("Superclass", cmd.getPersistableSuperclass());
assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
assertNull("Identity class", cmd.getObjectidClass());
String[] sortedFieldNames = new String[] { "normalString" };
assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
for (int i = 0; i < sortedFieldNames.length; ++i) {
AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
String s = sortedFieldNames[i];
assertEquals(s, fmd.getName());
assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
assertEquals(s + " primary key", false, fmd.isPrimaryKey());
assertEquals(s + " null value handling", NullValue.NONE, fmd.getNullValue());
assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
assertNull(s + " collection metadata", fmd.getContainer());
assertNull(s + " map metadata", fmd.getContainer());
}
// Check for a class defined in package.jdo at a higher level
cmd = mmgr.getMetaDataForClass(LevelAboveWidget.class, clr);
assertNotNull("MetaData is null!", cmd);
assertNotNull("Metadata", cmd);
assertEquals(LevelAboveWidget.class.getName(), cmd.getFullClassName());
assertEquals("org.datanucleus.samples.widget", cmd.getPackageName());
assertNull("Superclass", cmd.getPersistableSuperclass());
assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
assertNull("Identity class", cmd.getObjectidClass());
sortedFieldNames = new String[] { "normalString" };
assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
for (int i = 0; i < sortedFieldNames.length; ++i) {
AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
String s = sortedFieldNames[i];
assertEquals(s, fmd.getName());
assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
assertEquals(s + " primary key", false, fmd.isPrimaryKey());
assertEquals(s + " null value handling", NullValue.NONE, fmd.getNullValue());
assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
assertNull(s + " collection metadata", fmd.getContainer());
assertNull(s + " map metadata", fmd.getContainer());
}
}
use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.
the class BasicTest method testMetaDataManager.
/**
* Test for the MetaDataManager.
*/
public void testMetaDataManager() {
MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mgr.setValidate(false);
org.datanucleus.metadata.AbstractClassMetaData cmd = mgr.getMetaDataForClass(Inventory.class, new ClassLoaderResolverImpl());
if (cmd == null) {
fail("Failed to load MetaData for org.jpox.samples.store.Inventory class");
}
org.datanucleus.metadata.AbstractClassMetaData cmd2 = mgr.getMetaDataForClass(Book.class, new ClassLoaderResolverImpl());
if (cmd2 == null) {
fail("Failed to load MetaData for org.jpox.samples.store.Book class");
}
}
Aggregations