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