use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class XMLTest method testOneToManyUniMapFK.
/**
* Test of JPA 1-N unidir Map relation.
*/
public void testOneToManyUniMapFK() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
// owner side
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("phoneNumbers");
assertNotNull("Department.phoneNumbers is null!", fmd1);
assertEquals("Department.phoneNumbers mapped-by is incorrect", fmd1.getMappedBy(), null);
assertEquals("Department.phoneNumbers relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_UNI);
assertEquals("Department.phoneNumbers jointable name is incorrect", fmd1.getTable(), null);
MapMetaData mmd = fmd1.getMap();
assertNotNull("Department.phoneNumbers has no Map metadata!", mmd);
KeyMetaData keymd = fmd1.getKeyMetaData();
assertNotNull("Department.phoneNumbers has no Key metadata!", keymd);
assertEquals("Department.phoneNumbers has incorrect key mapped-by", keymd.getMappedBy(), "name");
}
use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class XMLTest method testSequenceGenerator.
/**
* Test of JPA <sequence-generator>
*/
public void testSequenceGenerator() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
PackageMetaData pmd = cmd1.getPackageMetaData();
assertEquals("Number of Sequences registered for Department class is wrong", pmd.getNoOfSequences(), 1);
SequenceMetaData seqmd = pmd.getSequences()[0];
assertEquals("SequenceGenerator has incorrect name", seqmd.getName(), "DepartmentGenerator");
assertEquals("SequenceGenerator has incorrect sequence name", seqmd.getDatastoreSequence(), "DEPT_SEQ");
assertEquals("SequenceGenerator has incorrect initial value", seqmd.getInitialValue(), 1);
assertEquals("SequenceGenerator has incorrect allocation size", seqmd.getAllocationSize(), 50);
}
use of org.datanucleus.NucleusContext 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);
}
use of org.datanucleus.NucleusContext 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.NucleusContext 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