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));
}
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));
}
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));
}
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;
}
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);
}
Aggregations