use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class XMLTest method testManyToMany.
/**
* Test of JPA M-N relation
*/
public void testManyToMany() {
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(PetroleumCustomer.class.getName(), clr);
assertEquals("Customer has incorrect table name", cmd1.getTable(), "JPA_MD_PETROL_CUSTOMER");
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("suppliers");
assertNotNull("Customer.suppliers is null!", fmd1);
assertEquals("Customer.suppliers mapped-by is incorrect", fmd1.getMappedBy(), "customers");
assertEquals("Customer.suppliers relationType is incorrect", fmd1.getRelationType(clr), RelationType.MANY_TO_MANY_BI);
assertEquals("Customer.suppliers jointable name is incorrect", fmd1.getTable(), "JPA_MD_PETROL_CUST_SUPP");
// non-owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(PetroleumSupplier.class.getName(), clr);
assertEquals("Supplier has incorrect table name", cmd2.getTable(), "JPA_MD_PETROL_SUPPLIER");
AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("customers");
assertNotNull("Supplier.customers is null!", fmd2);
assertEquals("Supplier.customers mapped-by is incorrect", fmd2.getMappedBy(), null);
assertEquals("Supplier.customers relationType is incorrect", fmd2.getRelationType(clr), RelationType.MANY_TO_MANY_BI);
assertEquals("Supplier.customers jointable name is incorrect", fmd2.getTable(), null);
// join table info
JoinMetaData joinmd = fmd1.getJoinMetaData();
assertNotNull("Customer.suppliers has no join table!", joinmd);
assertNotNull("Customer.suppliers has incorrect join columns", joinmd.getColumnMetaData());
assertEquals("Customer.suppliers has incorrect number of join columns", joinmd.getColumnMetaData().length, 1);
assertEquals("Customer.suppliers has incorrect owner join column name", joinmd.getColumnMetaData()[0].getName(), "CUSTOMER_ID");
ElementMetaData elemmd = fmd1.getElementMetaData();
assertNotNull("Customer.suppliers has no element column info but should", elemmd);
assertNotNull("Customer.suppliers has incorrect element columns", elemmd.getColumnMetaData());
assertEquals("Customer.suppliers has incorrect number of element columns", elemmd.getColumnMetaData().length, 1);
assertEquals("Customer.suppliers has incorrect element join column name", elemmd.getColumnMetaData()[0].getName(), "SUPPLIER_ID");
}
use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class XMLTest method testMappedSuperclass.
/**
* Test of MappedSuperclass
*/
public void testMappedSuperclass() {
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);
// AbstractSimpleBase
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(AbstractSimpleBase.class.getName(), clr);
assertNotNull("No MetaData found for AbstractSimpleBase yet is MappedSuperclass", cmd);
assertNotNull("No Inheritance info found for AbstractSimpleBase", cmd.getInheritanceMetaData());
assertEquals("Inheritance for AbstractSimpleBase is incorrect", "subclass-table", cmd.getInheritanceMetaData().getStrategy().toString());
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("id");
assertNotNull("No field info found for AbstractSimpleBase.id", fmd);
assertNotNull("No column info found for AbstractSimpleBase.id", fmd.getColumnMetaData());
assertEquals("Column name for AbstractSimpleBase.id is wrong", "ID", fmd.getColumnMetaData()[0].getName());
fmd = cmd.getMetaDataForMember("baseField");
assertNotNull("No field info found for AbstractSimpleBase.baseField", fmd);
assertNotNull("No column info found for AbstractSimpleBase.baseField", fmd.getColumnMetaData());
assertEquals("Column name for Product.baseField is wrong", "BASE_FIELD", fmd.getColumnMetaData()[0].getName());
// ConcreteSimpleSub1
cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(ConcreteSimpleSub1.class.getName(), clr);
assertNotNull("No MetaData found for ConcreteSimpleSub1 yet is Entity", cmd);
assertNotNull("No Inheritance info found for ConcreteSimpleSub1", cmd.getInheritanceMetaData());
assertEquals("Inheritance for ConcreteSimpleSub1 is incorrect", "new-table", cmd.getInheritanceMetaData().getStrategy().toString());
fmd = cmd.getOverriddenMember("baseField");
assertNotNull("No overridden field info found for ConcreteSimpleSub1.baseField", fmd);
assertNotNull("No column info found for ConcreteSimpleSub1.baseField", fmd.getColumnMetaData());
assertEquals("Column name for ConcreteSimpleSub1.baseField is wrong", "BASE_FIELD_OR", fmd.getColumnMetaData()[0].getName());
fmd = cmd.getMetaDataForMember("sub1Field");
assertNotNull("No field info found for ConcreteSimpleSub1.sub1Field", fmd);
assertNotNull("No column info found for ConcreteSimpleSub1.sub1Field", fmd.getColumnMetaData());
assertEquals("Column name for ConcreteSimpleSub1.sub1Field is wrong", "SUB1_FIELD", fmd.getColumnMetaData()[0].getName());
// ConcreteSimpleSub2
cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(ConcreteSimpleSub2.class.getName(), clr);
assertNotNull("No MetaData found for ConcreteSimpleSub2 yet is Entity", cmd);
assertNotNull("No Inheritance info found for ConcreteSimpleSub2", cmd.getInheritanceMetaData());
assertEquals("Inheritance for ConcreteSimpleSub2 is incorrect", "new-table", cmd.getInheritanceMetaData().getStrategy().toString());
fmd = cmd.getOverriddenMember("baseField");
assertNull("Overridden field info found for ConcreteSimpleSub2.baseField!", fmd);
fmd = cmd.getMetaDataForMember("sub2Field");
assertNotNull("No overridden field info found for ConcreteSimpleSub2.sub2Field", fmd);
assertNotNull("No column info found for ConcreteSimpleSub2.sub2Field", fmd.getColumnMetaData());
assertEquals("Column name for ConcreteSimpleSub2.sub2Field is wrong", "SUB2_FIELD", fmd.getColumnMetaData()[0].getName());
}
use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class XMLTest method testMapKey.
/**
* Test of JPA <map-key>.
*/
public void testMapKey() {
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);
// Retrieve the metadata from the MetaDataManager (populates and initialises everything)
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
assertEquals("name", cmd1.getMetaDataForMember("phoneNumbers").getKeyMetaData().getMappedBy());
}
use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class AnnotationPlusXMLTest method testMapKeyColumn.
/**
* Test of JPA @MapKeyColumn.
*/
public void testMapKeyColumn() {
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);
// Retrieve the metadata from the MetaDataManager (populates and initialises everything)
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
assertEquals("phoneNumbers_key1", cmd1.getMetaDataForMember("phoneNumbers").getKeyMetaData().getColumnMetaData()[0].getName());
assertTrue(cmd1.getMetaDataForMember("phoneNumbers").getKeyMetaData().getColumnMetaData()[0].getUnique());
}
use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class AnnotationPlusXMLTest method testOneToManyBiJoin.
/**
* Test of JPA 1-N unidir FK relation.
* This is really a 1-N uni join since JPA doesnt support 1-N uni FK.
*/
/*public void testOneToManyUniFK()
{
NucleusContext nucleusCtx = new NucleusContext("JPA", null);
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
MetaDataManager metaDataMgr = new JPAMetaDataManager(pmfcontext);
PersistenceUnitMetaData pumd = metaDataMgr.getMetaDataForPersistenceUnit("JPATest");
metaDataMgr.initialise(pumd, clr);
// owner side
ClassMetaData cmd1 = (ClassMetaData)metaDataMgr.getMetaDataForClass(Site.class.getName(), clr);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("offices");
assertNotNull("Site.offices is null!", fmd1);
assertEquals("Site.offices mapped-by is incorrect", fmd1.getMappedBy(), null);
assertEquals("Site.offices relationType is incorrect",
fmd1.getRelationType(clr), Relation.ONE_TO_MANY_UNI);
assertEquals("Site.offices jointable name is incorrect", fmd1.getTable(), null);
assertNotNull("Site.offices should have join but doesnt", fmd1.getJoinMetaData());
ElementMetaData elemmd = fmd1.getElementMetaData();
assertNotNull("Site.offices has no element column info but should", elemmd);
ColumnMetaData[] colmds = elemmd.getColumnMetaData();
assertNotNull("Site.offices has incorrect element columns", colmds);
assertEquals("Site.offices has incorrect number of element columns", colmds.length, 1);
assertEquals("Site.offices has incorrect element column name", colmds[0].getName(), "SITE_ID");
}*/
/**
* Test of JPA 1-N bidir JoinTable relation
*/
public void testOneToManyBiJoin() {
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(Manager.class.getName(), clr);
assertEquals("Manager has incorrect table name", cmd1.getTable(), "JPA_AX_MANAGER");
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("subordinates");
assertNotNull("Manager.subordinates is null!", fmd1);
assertEquals("Manager.subordinates mapped-by is incorrect", fmd1.getMappedBy(), "manager");
assertEquals("Manager.subordinates relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_BI);
assertEquals("Manager.subordinates jointable name is incorrect", fmd1.getTable(), "JPA_AX_MGR_EMPLOYEES");
// non-owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Employee.class.getName(), clr);
assertEquals("Employee has incorrect table name", cmd2.getTable(), "JPA_AX_EMPLOYEE");
AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("manager");
assertNotNull("Employee.manager is null!", fmd2);
assertEquals("Employee.manager mapped-by is incorrect", fmd2.getMappedBy(), null);
assertEquals("Employee.manager relationType is incorrect", fmd2.getRelationType(clr), RelationType.MANY_TO_ONE_BI);
assertEquals("Employee.manager jointable name is incorrect", fmd2.getTable(), null);
// join-table
JoinMetaData joinmd = fmd1.getJoinMetaData();
assertNotNull("Manager.subordinates has no join table!", joinmd);
assertNotNull("Manager.subordinates has incorrect join columns", joinmd.getColumnMetaData());
assertEquals("Manager.subordinates has incorrect number of join columns", 1, joinmd.getColumnMetaData().length);
assertEquals("Manager.subordinates has incorrect owner join column name", "MGR_ID", joinmd.getColumnMetaData()[0].getName());
ElementMetaData elemmd = fmd1.getElementMetaData();
assertNotNull("Manager.subordinates has no element column info but should", elemmd);
assertNotNull("Manager.subordinates has incorrect element columns", elemmd.getColumnMetaData());
assertEquals("Manager.subordinates has incorrect number of element columns", 1, elemmd.getColumnMetaData().length);
assertEquals("Manager.subordinates has incorrect element join column name", "EMP_ID", elemmd.getColumnMetaData()[0].getName());
}
Aggregations