Search in sources :

Example 31 with NucleusContext

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

the class DN2NamingFactoryTest method testEmbeddedPCColumnNames.

public void testEmbeddedPCColumnNames() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.COLUMN, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    AbstractClassMetaData compCmd = mmgr.getMetaDataForClass(Computer.class, clr);
    AbstractMemberMetaData graphicsMmd = compCmd.getMetaDataForMember("graphicsCard");
    AbstractClassMetaData cardCmd = mmgr.getMetaDataForClass(ComputerCard.class, clr);
    AbstractMemberMetaData makerMmd = cardCmd.getMetaDataForMember("makerName");
    List<AbstractMemberMetaData> colMmds = new ArrayList<AbstractMemberMetaData>();
    colMmds.add(graphicsMmd);
    colMmds.add(makerMmd);
    String colName = factory.getColumnName(colMmds, 0);
    // Comes from EmbeddedMetaData override
    assertEquals("graphics_maker", colName);
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) ArrayList(java.util.ArrayList) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 32 with NucleusContext

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

the class DN2NamingFactoryTest method testTableName.

public void testTableName() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(BooleanArray.class, clr);
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.TABLE, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    assertEquals("Table name is incorrect", "booleanarray", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.LOWER_CASE_QUOTED);
    assertEquals("Table name is incorrect", "\"booleanarray\"", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.UPPER_CASE);
    assertEquals("Table name is incorrect", "BOOLEANARRAY", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.UPPER_CASE_QUOTED);
    assertEquals("Table name is incorrect", "\"BOOLEANARRAY\"", factory.getTableName(cmd1));
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 33 with NucleusContext

use of org.datanucleus.NucleusContext in project datanucleus-api-jdo by datanucleus.

the class JDOMetaDataHandlerTest 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/package1.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 34 with NucleusContext

use of org.datanucleus.NucleusContext in project datanucleus-api-jdo by datanucleus.

the class PersistenceFileMetaDataHandlerTest 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/persistence2.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 35 with NucleusContext

use of org.datanucleus.NucleusContext in project datanucleus-api-jdo by datanucleus.

the class MetaDataParserTest method testParseMetaDataURLnullURL.

public void testParseMetaDataURLnullURL() {
    NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
    MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
    try {
        parser.parseMetaDataURL(null, "jdo");
        fail("expected JPOXException");
    } catch (NucleusException ex) {
    // expected
    }
}
Also used : NucleusContext(org.datanucleus.NucleusContext) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) MetaDataParser(org.datanucleus.metadata.xml.MetaDataParser) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) NucleusException(org.datanucleus.exceptions.NucleusException)

Aggregations

NucleusContext (org.datanucleus.NucleusContext)78 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)68 MetaDataManager (org.datanucleus.metadata.MetaDataManager)65 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)59 ClassMetaData (org.datanucleus.metadata.ClassMetaData)52 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)39 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)32 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)15 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)14 ElementMetaData (org.datanucleus.metadata.ElementMetaData)12 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)10 JoinMetaData (org.datanucleus.metadata.JoinMetaData)10 ArrayList (java.util.ArrayList)7 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)7 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)7 PackageMetaData (org.datanucleus.metadata.PackageMetaData)7 MetaDataParser (org.datanucleus.metadata.xml.MetaDataParser)7 DN2NamingFactory (org.datanucleus.store.schema.naming.DN2NamingFactory)7 IOException (java.io.IOException)4