use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testIdClassAccessors.
/**
* Test of JPA @IdClass with pk using acessors.
*/
public void testIdClassAccessors() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(IdClassAccessors.class.getName(), clr);
assertEquals(1, cmd1.getNoOfPrimaryKeyMembers());
assertTrue(cmd1.getAbsolutePositionOfMember("free") >= 0);
assertEquals("FFFF", cmd1.getMetaDataForManagedMemberAtAbsolutePosition(cmd1.getRelativePositionOfMember("free")).getColumnMetaData()[0].getName());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest 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_AN_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_AN_PETROL_CUST_SUPP");
// non-owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(PetroleumSupplier.class.getName(), clr);
assertEquals("Supplier has incorrect table name", cmd2.getTable(), "JPA_AN_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.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testOrderBy.
/**
* Test of @OrderBy.
*/
public void testOrderBy() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(UserGroup.class.getName(), clr);
OrderMetaData omd = cmd1.getMetaDataForMember("members").getOrderMetaData();
assertNotNull("UserGroup.members has no OrderMetaData!", omd);
FieldOrder[] orderTerms = omd.getFieldOrders();
assertFalse("UserGroup.members is not marked as using an ordered list", omd.isIndexedList());
assertNotNull("UserGroup.members has null field ordering info", orderTerms);
assertEquals("UserGroup.members has incorrect number of field ordering terms", orderTerms.length, 1);
assertEquals("UserGroup.members has incorrect field ordering field-name", orderTerms[0].getFieldName(), "name");
assertTrue("UserGroup.members has incorrect field ordering direction", orderTerms[0].isForward());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testEmbeddedId.
/**
* Test of basic JPA @EmbeddedId.
*/
public void testEmbeddedId() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
// Retrieve the metadata from the MetaDataManager (populates and initialises everything)
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
assertEquals(1, cmd1.getNoOfPrimaryKeyMembers());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testOneToOneUni.
/**
* Test of JPA 1-1 unidir relation
*/
public void testOneToOneUni() {
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(LoginAccount.class.getName(), clr);
assertEquals("LoginAccount has incorrect table name", cmd1.getTable(), "JPA_AN_LOGINACCOUNT");
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("login");
assertNotNull("LoginAccount.login is null!", fmd1);
assertEquals("LoginAccount.login mapped-by is incorrect", fmd1.getMappedBy(), null);
assertEquals("LoginAccount.login relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_ONE_UNI);
assertNotNull("LoginAccount.login has no column info", fmd1.getColumnMetaData());
assertEquals("LoginAccount.login has incorrect number of columns", fmd1.getColumnMetaData().length, 1);
assertEquals("LoginAccount.login column name is wrong", fmd1.getColumnMetaData()[0].getName(), "LOGIN_ID");
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Login.class.getName(), clr);
assertEquals("LoginAccount has incorrect table name", cmd2.getTable(), "JPA_AN_LOGIN");
}
Aggregations