Search in sources :

Example 6 with DN2NamingFactory

use of org.datanucleus.store.schema.naming.DN2NamingFactory in project tests by datanucleus.

the class DN2NamingFactoryTest method testDatastoreIdColumnName.

public void testDatastoreIdColumnName() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(Gym.class, clr);
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.COLUMN, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    assertEquals("Column name for datastore-id is incorrect", "gym_id", factory.getColumnName(cmd1, ColumnType.DATASTOREID_COLUMN));
}
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 7 with DN2NamingFactory

use of org.datanucleus.store.schema.naming.DN2NamingFactory 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 8 with DN2NamingFactory

use of org.datanucleus.store.schema.naming.DN2NamingFactory 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)

Aggregations

DN2NamingFactory (org.datanucleus.store.schema.naming.DN2NamingFactory)8 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)7 NucleusContext (org.datanucleus.NucleusContext)7 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)7 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)7 MetaDataManager (org.datanucleus.metadata.MetaDataManager)7 ArrayList (java.util.ArrayList)3 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)3 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 JPANamingFactory (org.datanucleus.store.schema.naming.JPANamingFactory)1 NamingFactory (org.datanucleus.store.schema.naming.NamingFactory)1