Search in sources :

Example 1 with DN2NamingFactory

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

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

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

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

the class AbstractStoreManager method getNamingFactory.

public NamingFactory getNamingFactory() {
    if (namingFactory == null) {
        // Create the NamingFactory
        String namingFactoryName = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_NAMING_FACTORY);
        if ("datanucleus2".equalsIgnoreCase(namingFactoryName)) {
            namingFactory = new DN2NamingFactory(nucleusContext);
        } else if ("jpa".equalsIgnoreCase(namingFactoryName)) {
            namingFactory = new JPANamingFactory(nucleusContext);
        } else {
            // Fallback to the plugin mechanism
            String namingFactoryClassName = nucleusContext.getPluginManager().getAttributeValueForExtension("org.datanucleus.identifier_namingfactory", "name", namingFactoryName, "class-name");
            if (namingFactoryClassName == null) {
                // TODO Localise this
                throw new NucleusUserException("Error in specified NamingFactory " + namingFactoryName + " not found");
            }
            try {
                Class[] argTypes = new Class[] { ClassConstants.NUCLEUS_CONTEXT };
                Object[] args = new Object[] { nucleusContext };
                namingFactory = (NamingFactory) nucleusContext.getPluginManager().createExecutableExtension("org.datanucleus.identifier_namingfactory", "name", namingFactoryName, "class-name", argTypes, args);
            } catch (Throwable thr) {
                throw new NucleusUserException("Exception creating NamingFactory for datastore : " + thr.getMessage(), thr);
            }
        }
        // Set the case TODO Handle quoted cases (not specifiable via this property currently)
        String identifierCase = getStringProperty(PropertyNames.PROPERTY_IDENTIFIER_CASE);
        if (identifierCase != null) {
            if (identifierCase.equalsIgnoreCase("lowercase")) {
                namingFactory.setNamingCase(NamingCase.LOWER_CASE);
            } else if (identifierCase.equalsIgnoreCase("UPPERCASE")) {
                namingFactory.setNamingCase(NamingCase.UPPER_CASE);
            } else {
                namingFactory.setNamingCase(NamingCase.MIXED_CASE);
            }
        }
    }
    return namingFactory;
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusUserException(org.datanucleus.exceptions.NucleusUserException) JPANamingFactory(org.datanucleus.store.schema.naming.JPANamingFactory) DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) JPANamingFactory(org.datanucleus.store.schema.naming.JPANamingFactory) NamingFactory(org.datanucleus.store.schema.naming.NamingFactory)

Example 5 with DN2NamingFactory

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

the class DN2NamingFactoryTest method testEmbeddedCollectionColumnNames.

/**
 * Test where the sample has embedded collection element.
 */
public void testEmbeddedCollectionColumnNames() {
    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 networkCmd = mmgr.getMetaDataForClass(Network.class, clr);
    AbstractMemberMetaData devicesMmd = networkCmd.getMetaDataForMember("devices");
    AbstractClassMetaData deviceCmd = mmgr.getMetaDataForClass(Device.class, clr);
    AbstractMemberMetaData deviceNameMmd = deviceCmd.getMetaDataForMember("name");
    AbstractMemberMetaData deviceDescMmd = deviceCmd.getMetaDataForMember("description");
    List<AbstractMemberMetaData> colMmds = new ArrayList<AbstractMemberMetaData>();
    colMmds.add(devicesMmd);
    colMmds.add(deviceNameMmd);
    String colName = factory.getColumnName(colMmds, 0);
    assertEquals("device_name", colName);
    colMmds.clear();
    colMmds.add(devicesMmd);
    colMmds.add(deviceDescMmd);
    colName = factory.getColumnName(colMmds, 0);
    assertEquals("devices_description", 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