use of org.datanucleus.FetchPlanForClass 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.FetchPlanForClass 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")));
}
Aggregations