use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class BasicTest method testDatastoreIdentityMetadata.
/**
* Tests datastore identity declared in many forms
*/
public void testDatastoreIdentityMetadata() {
MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mgr.setValidate(false);
AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(D0.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(D1.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(D2.class, new ClassLoaderResolverImpl());
assertEquals("identity", cmdD0.getIdentityMetaData().getValueStrategy().toString());
assertEquals(cmdD0.getIdentityMetaData().getValueStrategy(), cmdD1.getIdentityMetaData().getValueStrategy());
assertEquals(cmdD0.getIdentityMetaData().getValueStrategy(), cmdD2.getIdentityMetaData().getValueStrategy());
assertEquals("D_ID", cmdD0.getIdentityMetaData().getColumnMetaData().getName());
assertEquals(cmdD0.getIdentityMetaData().getColumnMetaData().getName(), cmdD1.getIdentityMetaData().getColumnMetaData().getName());
assertEquals(cmdD0.getIdentityMetaData().getColumnMetaData().getName(), cmdD2.getIdentityMetaData().getColumnMetaData().getName());
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class BasicTest method testFieldColumnMetadata.
/**
* Tests the column field declared in many forms
*/
public void testFieldColumnMetadata() {
MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mgr.setValidate(false);
AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(D0.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(D1.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(D2.class, new ClassLoaderResolverImpl());
assertEquals("NNN", cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName(), cmdD1.getMetaDataForManagedMemberAtAbsolutePosition(cmdD1.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
assertEquals(cmdD0.getMetaDataForManagedMemberAtAbsolutePosition(cmdD0.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName(), cmdD2.getMetaDataForManagedMemberAtAbsolutePosition(cmdD2.getAbsolutePositionOfMember("name")).getColumnMetaData()[0].getName());
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class BasicTest method testFieldDeclaredInSubClassMetadata.
/**
* Tests a field declared in the metadata of a subclass, like Subclass.field
*/
public void testFieldDeclaredInSubClassMetadata() {
MetaDataManager mgr = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mgr.setValidate(false);
AbstractClassMetaData cmdD0 = mgr.getMetaDataForClass(Pet.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD1 = mgr.getMetaDataForClass(Dog.class, new ClassLoaderResolverImpl());
AbstractClassMetaData cmdD2 = mgr.getMetaDataForClass(Cat.class, new ClassLoaderResolverImpl());
assertNotNull(cmdD0.getMetaDataForMember("name"));
assertNotNull(cmdD1.getMetaDataForMember("name"));
assertEquals("dog", cmdD1.getMetaDataForMember("name").getColumnMetaData()[0].getName());
assertNotNull(cmdD2.getMetaDataForMember("name"));
assertEquals("cat", cmdD2.getMetaDataForMember("name").getColumnMetaData()[0].getName());
}
use of org.datanucleus.metadata.MetaDataManager 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);
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class DN2NamingFactoryTest method testDatastoreIdColumnName.
public void testDatastoreIdColumnName() {
JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
NucleusContext nucCtx = jdoPMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(Gym.class, clr);
DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.COLUMN, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
assertEquals("Column name for datastore-id is incorrect", "gym_id", factory.getColumnName(cmd1, ColumnType.DATASTOREID_COLUMN));
}
Aggregations