use of org.datanucleus.metadata.AbstractClassMetaData in project tests by datanucleus.
the class ConvertersTest method testUseOfConvert.
/**
* Test the use of "@Convert" annotation on a field.
*/
public void testUseOfConvert() {
try {
PersistenceNucleusContext nucCtx = ((JDOPersistenceManagerFactory) pmf).getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
AbstractClassMetaData cmd = nucCtx.getMetaDataManager().getMetaDataForClass(PersonWithConverters.class, clr);
// Check the converter is registered with metadata
AbstractMemberMetaData mmd = cmd.getMetaDataForMember("myBool2");
assertNotNull(mmd);
assertTrue(mmd.hasExtension("type-converter-name"));
String converterName = mmd.getValueForExtension("type-converter-name");
assertEquals("org.datanucleus.samples.converters.BooleanYNConverter", converterName);
// Check the correct mapping is chosen for this field
RDBMSStoreManager storeMgr = (RDBMSStoreManager) nucCtx.getStoreManager();
DatastoreClass tbl = storeMgr.getDatastoreClass(PersonWithConverters.class.getName(), clr);
JavaTypeMapping mapping = tbl.getMemberMapping(mmd);
assertTrue(mapping instanceof TypeConverterMapping);
} catch (Exception e) {
LOG.error("Exception during test", e);
fail("Exception was thrown : " + e.getMessage());
} finally {
}
}
use of org.datanucleus.metadata.AbstractClassMetaData in project tests by datanucleus.
the class IdentifierFactoryTest method testDataNucleus2.
/**
* Tests for DNIdentifierFactory
*/
public void testDataNucleus2() {
RDBMSStoreManager srm = (RDBMSStoreManager) storeMgr;
IdentifierFactory idFactory = srm.getIdentifierFactory();
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
// Table identifiers
// a). generated name shorter than max length
DatastoreIdentifier id = idFactory.newIdentifier(IdentifierType.TABLE, "MyClass");
assertTrue("newIdentifier(TABLE, String) has generated an incorrect name : " + id.getName(), "MYCLASS".equalsIgnoreCase(id.getName()));
// b). specified name shorter than max length
id = idFactory.newTableIdentifier("MY_TABLE_NAME");
assertTrue("newDatastoreContainerIdentifier(String) has returned an incorrect name when should have used the supplied name " + id.getName(), "MY_TABLE_NAME".equalsIgnoreCase(id.getName()));
// c). name specified via ClassMetaData
AbstractClassMetaData managerCMD = storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass("org.jpox.samples.models.company.Manager", clr);
id = idFactory.newTableIdentifier(managerCMD);
assertTrue("newDatastoreContainerIdentifier(clr, ClassMetaData) has returned an incorrect generated name " + id.getName(), "MANAGER".equalsIgnoreCase(id.getName()));
// d). name specified via ClassMetaData
AbstractMemberMetaData fmd = managerCMD.getMetaDataForMember("subordinates");
id = idFactory.newTableIdentifier(fmd);
assertTrue("newDatastoreContainerIdentifier(clr, AbstractMemberMetaData) has returned an incorrect generated name " + id.getName(), "MANAGER_SUBORDINATES".equalsIgnoreCase(id.getName()));
// Column identifiers
// a). generated name shorter than max length
id = idFactory.newIdentifier(IdentifierType.COLUMN, "myField");
assertTrue("newIdentifier(COLUMN, String) has generated an incorrect name : " + id.getName(), "MYFIELD".equalsIgnoreCase(id.getName()));
// b). specified name shorter than max length
id = idFactory.newColumnIdentifier("MYCOLUMNNAME");
assertTrue("newColumnIdentifier(String) has returned an incorrect name when should have used the supplied name " + id.getName(), "MYCOLUMNNAME".equalsIgnoreCase(id.getName()));
// c). Discriminator column identifier
id = idFactory.newDiscriminatorFieldIdentifier();
assertTrue("newDiscriminatorFieldIdentifier() has returned an incorrect name : " + id.getName(), "DISCRIMINATOR".equalsIgnoreCase(id.getName()));
// d). Version column identifier
id = idFactory.newVersionFieldIdentifier();
assertTrue("newVersionFieldIdentifier() has returned an incorrect name : " + id.getName(), "VERSION".equalsIgnoreCase(id.getName()));
// e). Index (ordering) column identifier
id = idFactory.newIndexFieldIdentifier(fmd);
assertTrue("newIndexFieldIdentifier() has returned an incorrect name : " + id.getName(), "IDX".equalsIgnoreCase(id.getName()));
// f). Adapter Index column identifier
id = idFactory.newAdapterIndexFieldIdentifier();
assertTrue("newAdapterIndexFieldIdentifier() has returned an incorrect name : " + id.getName(), "IDX".equalsIgnoreCase(id.getName()));
AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
// g). join table owner column identifier (1-N bi JoinTable)
DatastoreIdentifier destId = idFactory.newColumnIdentifier("MANAGER_ID");
id = idFactory.newJoinTableFieldIdentifier(fmd, relatedMmds != null ? relatedMmds[0] : null, destId, false, FieldRole.ROLE_OWNER);
assertTrue("newJoinTableFieldIdentifier(OWNER) has returned an incorrect generated name " + id.getName(), "MANAGER_ID_OID".equalsIgnoreCase(id.getName()));
// h). join table element column identifier (1-N bi JoinTable)
destId = idFactory.newColumnIdentifier("EMPLOYEE_ID");
id = idFactory.newJoinTableFieldIdentifier(fmd, relatedMmds != null ? relatedMmds[0] : null, destId, false, FieldRole.ROLE_COLLECTION_ELEMENT);
assertTrue("newJoinTableFieldIdentifier(ELEMENT) has returned an incorrect generated name " + id.getName(), "EMPLOYEE_ID_EID".equalsIgnoreCase(id.getName()));
// i). FK owner column identifier (1-N bi FK)
AbstractMemberMetaData deptsFMD = managerCMD.getMetaDataForMember("departments");
AbstractMemberMetaData[] deptsRelatedMmds = deptsFMD.getRelatedMemberMetaData(clr);
destId = idFactory.newColumnIdentifier("MANAGER_ID");
id = idFactory.newForeignKeyFieldIdentifier(deptsFMD, deptsRelatedMmds != null ? deptsRelatedMmds[0] : null, destId, false, FieldRole.ROLE_OWNER);
assertTrue("newForeignKeyFieldIdentifier(OWNER) has returned an incorrect generated name " + id.getName(), "MANAGER_MANAGER_ID_OID".equalsIgnoreCase(id.getName()));
// Primary key identifiers
// Index identifiers
// Foreign key identifiers
// Candidate key identifiers
// Sequence identifiers
}
use of org.datanucleus.metadata.AbstractClassMetaData 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.metadata.AbstractClassMetaData 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.metadata.AbstractClassMetaData 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));
}
Aggregations