Search in sources :

Example 1 with JPANamingFactory

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

the class JPANamingFactoryTest method testDatastoreIdColumnName.

public void testDatastoreIdColumnName() {
    JPAEntityManagerFactory jpaEMF = (JPAEntityManagerFactory) emf;
    NucleusContext nucCtx = jpaEMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(MyDatastoreId.class, clr);
    NamingFactory factory = new JPANamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.COLUMN, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    assertEquals("Column name for datastore-id is incorrect", "mydatastoreid_id", factory.getColumnName(cmd1, ColumnType.DATASTOREID_COLUMN));
}
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 2 with JPANamingFactory

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

the class JPANamingFactoryTest method testVersionColumnName.

public void testVersionColumnName() {
    JPAEntityManagerFactory jpaEMF = (JPAEntityManagerFactory) emf;
    NucleusContext nucCtx = jpaEMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(Trade4.class, clr);
    NamingFactory factory = new JPANamingFactory(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 : 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 3 with JPANamingFactory

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

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

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

the class JPANamingFactoryTest method testJoinTableName.

public void testJoinTableName() {
    JPAEntityManagerFactory jpaEMF = (JPAEntityManagerFactory) emf;
    NucleusContext nucCtx = jpaEMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(UserGroup.class, clr);
    NamingFactory factory = new JPANamingFactory(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_groupmember", name);
}
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)

Aggregations

JPANamingFactory (org.datanucleus.store.schema.naming.JPANamingFactory)5 NamingFactory (org.datanucleus.store.schema.naming.NamingFactory)5 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)4 NucleusContext (org.datanucleus.NucleusContext)4 JPAEntityManagerFactory (org.datanucleus.api.jpa.JPAEntityManagerFactory)4 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)4 MetaDataManager (org.datanucleus.metadata.MetaDataManager)4 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)1 DN2NamingFactory (org.datanucleus.store.schema.naming.DN2NamingFactory)1