Search in sources :

Example 76 with NucleusContext

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

the class DN2NamingFactoryTest method testJoinTableName.

public void testJoinTableName() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(UserGroup.class, clr);
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    factory.setMaximumLength(SchemaComponent.TABLE, 128);
    String name = factory.getTableName(cmd1.getMetaDataForMember("members"));
    assertEquals("Join table name is incorrect", "usergroup_members", name);
}
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 77 with NucleusContext

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

the class DN2NamingFactoryTest method testNestedEmbeddedPCColumnNames.

/**
 * Test where the sample classes have no EmbeddedMetaData overriding the column names, so we just get generated names for embedded class and nested embedded class.
 */
public void testNestedEmbeddedPCColumnNames() {
    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 emb1Cmd = mmgr.getMetaDataForClass(EmbCls1.class, clr);
    AbstractMemberMetaData embCls2aMmd = emb1Cmd.getMetaDataForMember("embCls2a");
    AbstractMemberMetaData embCls2bMmd = emb1Cmd.getMetaDataForMember("embCls2b");
    AbstractClassMetaData emb2Cmd = mmgr.getMetaDataForClass(EmbCls2.class, clr);
    AbstractMemberMetaData embCls3Mmd = emb2Cmd.getMetaDataForMember("embCls3");
    AbstractMemberMetaData cls2NameMmd = emb2Cmd.getMetaDataForMember("cls2Name");
    AbstractClassMetaData emb3Cmd = mmgr.getMetaDataForClass(EmbCls3.class, clr);
    AbstractMemberMetaData cls3NameMmd = emb3Cmd.getMetaDataForMember("cls3Name");
    List<AbstractMemberMetaData> colMmds = new ArrayList<AbstractMemberMetaData>();
    colMmds.add(embCls2aMmd);
    colMmds.add(cls2NameMmd);
    String colName = factory.getColumnName(colMmds, 0);
    assertEquals("embcls2a_cls2name", colName);
    colMmds.clear();
    colMmds.add(embCls2bMmd);
    colMmds.add(cls2NameMmd);
    colName = factory.getColumnName(colMmds, 0);
    assertEquals("embcls2b_cls2name", colName);
    colMmds.clear();
    colMmds.add(embCls2aMmd);
    colMmds.add(embCls3Mmd);
    colMmds.add(cls3NameMmd);
    colName = factory.getColumnName(colMmds, 0);
    assertEquals("embcls2a_embcls3_cls3name", colName);
    colMmds.clear();
    colMmds.add(embCls2bMmd);
    colMmds.add(embCls3Mmd);
    colMmds.add(cls3NameMmd);
    colName = factory.getColumnName(colMmds, 0);
    assertEquals("embcls2b_embcls3_cls3name", 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 78 with NucleusContext

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

the class RDBMSAdapterFactoryTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    NucleusContext ctxt = new PersistenceNucleusContextImpl("JDO", null);
    pluginMgr = ctxt.getPluginManager();
    clr = ctxt.getClassLoaderResolver(null);
    // Load RDBMS resources since this is normally done on the init of RDBMSStoreManager and we aren't doing that
    Localiser.registerBundle("org.datanucleus.store.rdbms.Localisation", RDBMSStoreManager.class.getClassLoader());
    factory = DatastoreAdapterFactory.getInstance();
}
Also used : NucleusContext(org.datanucleus.NucleusContext) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) RDBMSStoreManager(org.datanucleus.store.rdbms.RDBMSStoreManager)

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