Search in sources :

Example 6 with FetchPlan

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
    }
}
Also used : FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) HashSet(java.util.HashSet)

Example 7 with FetchPlan

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());
}
Also used : FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan)

Example 8 with FetchPlan

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());
}
Also used : JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) ExecutionContext(org.datanucleus.ExecutionContext) FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan)

Example 9 with FetchPlan

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")));
}
Also used : FetchPlanForClass(org.datanucleus.FetchPlanForClass) BitSet(java.util.BitSet) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) FP2Base(org.datanucleus.samples.fetchplan.FP2Base) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 10 with FetchPlan

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")));
}
Also used : JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) FetchPlanForClass(org.datanucleus.FetchPlanForClass) BitSet(java.util.BitSet) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) FetchPlan(org.datanucleus.FetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) JDOFetchPlan(org.datanucleus.api.jdo.JDOFetchPlan) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) FP2Base(org.datanucleus.samples.fetchplan.FP2Base) 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