Search in sources :

Example 16 with JDOMetaDataManager

use of org.datanucleus.api.jdo.metadata.JDOMetaDataManager in project datanucleus-api-jdo by datanucleus.

the class JDOMetaDataHandlerTest method testParseNamespace.

public void testParseNamespace() {
    NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
    MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
    MetaData md = parser.parseMetaDataURL(getClass().getResource("/org/datanucleus/api/jdo/metadata/xml/package2.jdo"), "jdo");
    assertNotNull(md);
}
Also used : MetaData(org.datanucleus.metadata.MetaData) NucleusContext(org.datanucleus.NucleusContext) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) MetaDataParser(org.datanucleus.metadata.xml.MetaDataParser) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager)

Example 17 with JDOMetaDataManager

use of org.datanucleus.api.jdo.metadata.JDOMetaDataManager in project datanucleus-api-jdo by datanucleus.

the class PersistenceFileMetaDataHandlerTest method testParseDefaultNamespace.

public void testParseDefaultNamespace() {
    NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
    MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
    MetaData md = parser.parseMetaDataURL(getClass().getResource("/org/datanucleus/api/jdo/metadata/xml/persistence1.xml"), "persistence");
    assertNotNull(md);
}
Also used : MetaData(org.datanucleus.metadata.MetaData) NucleusContext(org.datanucleus.NucleusContext) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) MetaDataParser(org.datanucleus.metadata.xml.MetaDataParser) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager)

Example 18 with JDOMetaDataManager

use of org.datanucleus.api.jdo.metadata.JDOMetaDataManager in project datanucleus-api-jdo by datanucleus.

the class MetaDataManagerTest method testLocationsForPackage.

/**
 * Test of the valid locations for a specified package.
 */
public void testLocationsForPackage() {
    Map startupProps = new HashMap<>();
    startupProps.put(JDOPropertyNames.PROPERTY_METADATA_XML_JDO_1_0, "true");
    JDOMetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", startupProps));
    // Try typical JDO package name
    String packageName = "org.jpox.samples";
    List locations = mgr.getValidMetaDataLocationsForPackage("jdo", null, packageName);
    assertTrue("Locations returned from MetaData Manager was null!", locations != null);
    List validLocations = new ArrayList();
    validLocations.add("/META-INF/package.jdo");
    validLocations.add("/WEB-INF/package.jdo");
    validLocations.add("/package.jdo");
    validLocations.add("/org.jdo");
    validLocations.add("/org/package.jdo");
    validLocations.add("/org/jpox.jdo");
    validLocations.add("/org/jpox/package.jdo");
    validLocations.add("/org/jpox/samples.jdo");
    validLocations.add("/org/jpox/samples/package.jdo");
    checkLocations(packageName, locations, validLocations);
    // Try 1 level package name
    packageName = "org";
    locations = mgr.getValidMetaDataLocationsForPackage("jdo", null, packageName);
    assertTrue("Locations returned from MetaData Manager was null!", locations != null);
    validLocations.clear();
    validLocations.add("/META-INF/package.jdo");
    validLocations.add("/WEB-INF/package.jdo");
    validLocations.add("/package.jdo");
    validLocations.add("/org.jdo");
    validLocations.add("/org/package.jdo");
    checkLocations(packageName, locations, validLocations);
    // Try 0 level package name
    packageName = "";
    locations = mgr.getValidMetaDataLocationsForPackage("jdo", null, packageName);
    assertTrue("Locations returned from MetaData Manager was null!", locations != null);
    validLocations.clear();
    validLocations.add("/META-INF/package.jdo");
    validLocations.add("/WEB-INF/package.jdo");
    validLocations.add("/package.jdo");
    checkLocations(packageName, locations, validLocations);
    // Try typical ORM package name
    packageName = "org.jpox.samples";
    locations = mgr.getValidMetaDataLocationsForPackage("orm", "jpox", packageName);
    assertTrue("Locations returned from MetaData Manager was null!", locations != null);
    validLocations.clear();
    validLocations.add("/META-INF/package-jpox.orm");
    validLocations.add("/WEB-INF/package-jpox.orm");
    validLocations.add("/package-jpox.orm");
    validLocations.add("/org-jpox.orm");
    validLocations.add("/org/package-jpox.orm");
    validLocations.add("/org/jpox-jpox.orm");
    validLocations.add("/org/jpox/package-jpox.orm");
    validLocations.add("/org/jpox/samples-jpox.orm");
    validLocations.add("/org/jpox/samples/package-jpox.orm");
    checkLocations(packageName, locations, validLocations);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) List(java.util.List) ArrayList(java.util.ArrayList) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) Map(java.util.Map) HashMap(java.util.HashMap)

Example 19 with JDOMetaDataManager

use of org.datanucleus.api.jdo.metadata.JDOMetaDataManager 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 20 with JDOMetaDataManager

use of org.datanucleus.api.jdo.metadata.JDOMetaDataManager 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

JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)28 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)27 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)20 MetaDataManager (org.datanucleus.metadata.MetaDataManager)17 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)16 MetaDataParser (org.datanucleus.metadata.xml.MetaDataParser)8 NucleusContext (org.datanucleus.NucleusContext)7 FetchPlan (org.datanucleus.FetchPlan)5 FetchPlanForClass (org.datanucleus.FetchPlanForClass)5 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)5 ArrayList (java.util.ArrayList)4 BitSet (java.util.BitSet)4 MetaData (org.datanucleus.metadata.MetaData)4 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 NucleusException (org.datanucleus.exceptions.NucleusException)2 FileMetaData (org.datanucleus.metadata.FileMetaData)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1