Search in sources :

Example 16 with FetchPlan

use of org.datanucleus.FetchPlan in project tests by datanucleus.

the class FetchPlanTest method testRemoveGroup.

/**
 * Test the removal of fetch groups.
 */
public void testRemoveGroup() {
    FetchPlan fp = getFetchPlan();
    fp.removeGroup("grp1");
    assertEquals(1, fp.getGroups().size());
    assertEquals(FetchPlan.DEFAULT, fp.getGroups().iterator().next());
    fp.addGroup("grp1");
    fp.removeGroup("grp1");
    assertEquals(1, fp.getGroups().size());
    assertEquals(FetchPlan.DEFAULT, fp.getGroups().iterator().next());
    fp.addGroup("grp1");
    fp.removeGroup(FetchPlan.DEFAULT);
    assertEquals(1, fp.getGroups().size());
    assertEquals("grp1", fp.getGroups().iterator().next());
    fp.removeGroup(FetchPlan.DEFAULT);
    assertEquals(1, fp.getGroups().size());
    assertEquals("grp1", fp.getGroups().iterator().next());
    fp.clearGroups();
    assertEquals(0, fp.getGroups().size());
}
Also used : FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan)

Example 17 with FetchPlan

use of org.datanucleus.FetchPlan in project tests by datanucleus.

the class FetchPlanTest method testSetGroups.

/**
 * Test the setting of fetch groups.
 */
public void testSetGroups() {
    FetchPlan fp = getFetchPlan();
    // setGroups(Collection)
    Set<String> set = new HashSet<>();
    set.add("grp1");
    fp.setGroups(set);
    assertEquals(1, fp.getGroups().size());
    assertEquals("grp1", fp.getGroups().iterator().next());
    set.clear();
    set.add(FetchPlan.DEFAULT);
    fp.setGroups(set);
    assertEquals(1, fp.getGroups().size());
    assertEquals(FetchPlan.DEFAULT, fp.getGroups().iterator().next());
    fp.clearGroups();
    set.add("grp1");
    fp.setGroups(set);
    assertEquals(2, fp.getGroups().size());
    fp.setGroups(fp.getGroups());
    assertEquals(2, fp.getGroups().size());
    // setGroup(String)
    fp.setGroup((String) null);
    assertEquals(0, fp.getGroups().size());
    // setGroups(String[])
    String[] grps = new String[] { "grp1" };
    fp.setGroups(grps);
    assertEquals(1, fp.getGroups().size());
    assertEquals("grp1", fp.getGroups().iterator().next());
}
Also used : FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) HashSet(java.util.HashSet)

Example 18 with FetchPlan

use of org.datanucleus.FetchPlan 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")));
}
Also used : FetchPlanForClass(org.datanucleus.FetchPlanForClass) BitSet(java.util.BitSet) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 19 with FetchPlan

use of org.datanucleus.FetchPlan in project tests by datanucleus.

the class FetchPlanTest method testClearGroups.

/**
 * Test the clearing of fetch groups.
 */
public void testClearGroups() {
    FetchPlan fp = getFetchPlan();
    fp.addGroup("grp1");
    fp.clearGroups();
    assertEquals(0, fp.getGroups().size());
}
Also used : FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan)

Example 20 with FetchPlan

use of org.datanucleus.FetchPlan 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")));
}
Also used : FetchPlanForClass(org.datanucleus.FetchPlanForClass) BitSet(java.util.BitSet) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

FetchPlan (org.datanucleus.FetchPlan)23 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)15 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)10 FetchPlanForClass (org.datanucleus.FetchPlanForClass)9 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)7 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)7 BitSet (java.util.BitSet)6 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)6 ExecutionContext (org.datanucleus.ExecutionContext)5 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)5 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)5 MetaDataManager (org.datanucleus.metadata.MetaDataManager)5 ObjectProvider (org.datanucleus.state.ObjectProvider)5 FieldValues (org.datanucleus.store.FieldValues)5 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)3 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)3 FP2Base (org.datanucleus.samples.fetchplan.FP2Base)3