Search in sources :

Example 16 with ClassLoaderResolverImpl

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

the class BasicTest method testLoadingMetaDataForPackage.

/**
 * Tests the loading of XML metadata specified in package,jdo.
 */
public void testLoadingMetaDataForPackage() {
    MetaDataManager mmgr = new PersistenceNucleusContextImpl("JDO", null).getMetaDataManager();
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    // Validate metadata for DateWidget
    AbstractClassMetaData cmd = mmgr.getMetaDataForClass(DateWidget.class, clr);
    assertNotNull("ClassMetaData is null!", cmd);
    assertEquals("Class name", DateWidget.class.getName(), cmd.getFullClassName());
    assertEquals("Package name", "org.datanucleus.samples.widget", cmd.getPackageName());
    assertEquals("Superclass", Widget.class.getName(), cmd.getPersistableSuperclass());
    assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
    assertNull("Identity class", cmd.getObjectidClass());
    assertNotNull("Inheritance", cmd.getInheritanceMetaData());
    assertEquals("Inheritance strategy", cmd.getInheritanceMetaData().getStrategy().toString(), "new-table");
    String[] sortedFieldNames = new String[] { "dateField", "dateJdbcTimestampField", "sqlDateField", "sqlTimestampField" };
    Assert.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());
    }
    // Validate metadata for FloatWidget
    cmd = mmgr.getMetaDataForClass(FloatWidget.class, clr);
    assertNotNull("Metadata", cmd);
    assertEquals("Class name", FloatWidget.class.getName(), cmd.getFullClassName());
    assertEquals("Package name", "org.datanucleus.samples.widget", cmd.getPackageName());
    assertEquals("Superclass", Widget.class.getName(), cmd.getPersistableSuperclass());
    assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
    assertNull("Identity class", cmd.getObjectidClass());
    sortedFieldNames = new String[] { "doubleField", "doubleObjField", "floatField", "floatObjField" };
    NullValue[] nullValueHandlings = new NullValue[] { NullValue.EXCEPTION, NullValue.NONE, NullValue.EXCEPTION, NullValue.NONE };
    assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
    for (int i = 0; i < sortedFieldNames.length; ++i) {
        AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
        String s = sortedFieldNames[i];
        Assert.assertEquals(s, fmd.getName());
        Assert.assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
        Assert.assertEquals(s + " primary key", false, fmd.isPrimaryKey());
        Assert.assertEquals(s + " null value handling", nullValueHandlings[i], fmd.getNullValue());
        Assert.assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
        Assert.assertNull(s + " collection metadata", fmd.getContainer());
        Assert.assertNull(s + " map metadata", fmd.getContainer());
    }
}
Also used : FloatWidget(org.datanucleus.samples.widget.FloatWidget) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) DateWidget(org.datanucleus.samples.widget.DateWidget) LevelAboveWidget(org.datanucleus.samples.widget.LevelAboveWidget) DateWidget(org.datanucleus.samples.widget.DateWidget) FloatWidget(org.datanucleus.samples.widget.FloatWidget) Widget(org.datanucleus.samples.widget.Widget) PackageClassWidget(org.datanucleus.samples.widget.PackageClassWidget) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) NullValue(org.datanucleus.metadata.NullValue) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 17 with ClassLoaderResolverImpl

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

the class FetchPlanTest method testNestedFetchGroupsAgain.

/**
 * Test nested fetch groups.
 * TODO Merge this with the test above
 */
public void testNestedFetchGroupsAgain() {
    FetchPlan fp = getFetchPlan();
    PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
    MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
    // test parent with fetch-group = group1
    AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(FP1Sub.class, new ClassLoaderResolverImpl());
    fp.addGroup("1");
    fp.removeGroup(FetchPlan.DEFAULT);
    FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
    int[] fieldsInFP = fpc.getMemberNumbers();
    assertEquals("should have 2 fields in fetchplan", 2, fieldsInFP.length);
    // check if fields are in the FP
    BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
    assertTrue("name should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("name")));
    assertTrue("room should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("room")));
}
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 18 with ClassLoaderResolverImpl

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

the class FetchPlanTest method testPostLoad.

/**
 * Test the use of "postload"
 */
public void testPostLoad() throws Exception {
    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);
    boolean[] loadedFields = new boolean[14];
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    // --------------------------------------
    // fetch group width postLoad + DFG
    // --------------------------------------
    fp.addGroup("groupD");
    fpc = fp.getFetchPlanForClass(cmd);
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    // --------------------------------------
    // fetch group width postLoad
    // --------------------------------------
    fp.addGroup("groupD");
    fp.removeGroup(FetchPlan.DEFAULT);
    fpc = fp.getFetchPlanForClass(cmd);
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    // --------------------------------------
    // fetch group without postLoad
    // --------------------------------------
    fp.addGroup("groupC");
    fp.removeGroup("groupD");
    fp.removeGroup(FetchPlan.DEFAULT);
    fpc = fp.getFetchPlanForClass(cmd);
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertFalse("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    // --------------------------------------
    // fetch group width postLoad
    // --------------------------------------
    fp.addGroup("groupAll");
    fp.removeGroup("groupC");
    fp.removeGroup(FetchPlan.DEFAULT);
    fpc = fp.getFetchPlanForClass(cmd);
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = false;
    assertTrue("Should call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
    loadedFields[cmd.getAbsolutePositionOfMember("piece1")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece2")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece3")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece4")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece5")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece6")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece7")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece8")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece9")] = false;
    loadedFields[cmd.getAbsolutePositionOfMember("piece10")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece11")] = true;
    loadedFields[cmd.getAbsolutePositionOfMember("piece12")] = true;
    assertFalse("Should not call postLoad callback", fpc.isToCallPostLoadFetchPlan(loadedFields));
}
Also used : FetchPlanForClass(org.datanucleus.FetchPlanForClass) 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 ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl 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 20 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl 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

ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)53 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)35 MetaDataManager (org.datanucleus.metadata.MetaDataManager)31 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)27 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)23 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)22 NucleusContext (org.datanucleus.NucleusContext)14 ClassMetaData (org.datanucleus.metadata.ClassMetaData)14 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)12 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)10 FetchPlan (org.datanucleus.FetchPlan)7 FetchPlanForClass (org.datanucleus.FetchPlanForClass)7 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)7 BitSet (java.util.BitSet)6 NonManagedPluginRegistry (org.datanucleus.plugin.NonManagedPluginRegistry)6 HashSet (java.util.HashSet)3 Properties (java.util.Properties)3 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)3 Bundle (org.datanucleus.plugin.Bundle)3 ArrayList (java.util.ArrayList)2