use of org.datanucleus.FetchPlan in project tests by datanucleus.
the class FetchPlanTest method testGetGroups.
public void testGetGroups() {
FetchPlan fp = getFetchPlan();
Set<String> set = new HashSet<>();
fp.clearGroups();
set.add("grp1");
fp.setGroups(set);
assertEquals(1, fp.getGroups().size());
try {
fp.getGroups().add("XXX");
fail("expected UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
// expected
}
}
use of org.datanucleus.FetchPlan in project tests by datanucleus.
the class FetchPlanTest method testAddGroup.
/**
* Test the addition of fetch groups.
*/
public void testAddGroup() {
FetchPlan fp = getFetchPlan();
fp.addGroup("grp1");
assertEquals(2, fp.getGroups().size());
fp.addGroup("grp1");
assertEquals(2, fp.getGroups().size());
fp.addGroup("grp2");
assertEquals(3, fp.getGroups().size());
}
use of org.datanucleus.FetchPlan in project tests by datanucleus.
the class FetchPlanTest method getFetchPlan.
/**
* Convenience accessor for a new FetchPlan.
* @return The FetchPlan
*/
private FetchPlan getFetchPlan() {
JDOPersistenceManager pm = (JDOPersistenceManager) pmf.getPersistenceManager();
ExecutionContext ec = pm.getExecutionContext();
return new FetchPlan(ec, ec.getClassLoaderResolver());
}
use of org.datanucleus.FetchPlan 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.FetchPlan 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")));
}
Aggregations