Search in sources :

Example 36 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.

the class JPANamingFactoryTest method testTableName.

public void testTableName() {
    JPAEntityManagerFactory jpaEMF = (JPAEntityManagerFactory) emf;
    NucleusContext nucCtx = jpaEMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(ByteArray.class, clr);
    NamingFactory factory = new JPANamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.TABLE, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    assertEquals("Table name is incorrect", "bytearray", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.LOWER_CASE_QUOTED);
    assertEquals("Table name is incorrect", "\"bytearray\"", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.UPPER_CASE);
    assertEquals("Table name is incorrect", "BYTEARRAY", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.UPPER_CASE_QUOTED);
    assertEquals("Table name is incorrect", "\"BYTEARRAY\"", factory.getTableName(cmd1));
    AbstractClassMetaData cmd2 = mmgr.getMetaDataForClass(SimpleClass.class, clr);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    assertEquals("Table name is incorrect", "mysimpleclass", factory.getTableName(cmd2));
}
Also used : JPAEntityManagerFactory(org.datanucleus.api.jpa.JPAEntityManagerFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JPANamingFactory(org.datanucleus.store.schema.naming.JPANamingFactory) JPANamingFactory(org.datanucleus.store.schema.naming.JPANamingFactory) NamingFactory(org.datanucleus.store.schema.naming.NamingFactory) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 37 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.

the class DN2NamingFactoryTest method testVersionColumnName.

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

use of org.datanucleus.metadata.MetaDataManager 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 39 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager 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 40 with MetaDataManager

use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.

the class BasicTest method testDependent.

/**
 * Test for defaulting of "dependent" attribute on a field and on a collection.
 */
public void testDependent() {
    MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
    mgr.setValidate(false);
    AbstractClassMetaData cmdInh2 = mgr.getMetaDataForClass(Container.class, new ClassLoaderResolverImpl());
    AbstractMemberMetaData fmd = cmdInh2.getMetaDataForMember("members");
    // mmd doesn't have dependent attribute, so should default to false
    assertFalse(fmd.isDependent());
    assertFalse(fmd.getCollection().isDependentElement());
}
Also used : JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

MetaDataManager (org.datanucleus.metadata.MetaDataManager)102 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)72 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)69 NucleusContext (org.datanucleus.NucleusContext)65 ClassMetaData (org.datanucleus.metadata.ClassMetaData)55 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)41 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)40 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)38 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)31 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)19 ElementMetaData (org.datanucleus.metadata.ElementMetaData)12 ArrayList (java.util.ArrayList)11 JoinMetaData (org.datanucleus.metadata.JoinMetaData)10 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)9 PackageMetaData (org.datanucleus.metadata.PackageMetaData)8 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)7 DN2NamingFactory (org.datanucleus.store.schema.naming.DN2NamingFactory)7 FetchPlanForClass (org.datanucleus.FetchPlanForClass)6 FileMetaData (org.datanucleus.metadata.FileMetaData)6