use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationPlusXMLTest 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.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationPlusXMLTest method testEventListeners.
/**
* Test of Event Listeners
*/
public void testEventListeners() {
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(WebSite.class.getName(), clr);
// Example callbacks
EventListenerMetaData elmd = cmd1.getListenerForClass(cmd1.getFullClassName());
assertNotNull("Site didnt have its own class registered as an EventListener!", elmd);
assertEquals("Site EventListener has incorrect method for prePersist callback", elmd.getClassName() + ".prePersist", elmd.getMethodNameForCallbackClass(PrePersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".postPersist", elmd.getMethodNameForCallbackClass(PostPersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".load", elmd.getMethodNameForCallbackClass(PostLoad.class.getName()));
assertNull(elmd.getMethodNameForCallbackClass(PreRemove.class.getName()));
// Example listener
elmd = cmd1.getListenerForClass(MyListener.class.getName());
assertNotNull("Site didnt have MyListener registered as an EventListener!", elmd);
assertEquals("Site EventListener has incorrect method for prePersist callback", elmd.getClassName() + ".register", elmd.getMethodNameForCallbackClass(PostPersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".deregister", elmd.getMethodNameForCallbackClass(PreRemove.class.getName()));
assertNull(elmd.getMethodNameForCallbackClass(PrePersist.class.getName()));
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationPlusXMLTest method testOneToManyBiFK.
/**
* Test of JPA 1-N bidir FK relation
*/
public void testOneToManyBiFK() {
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);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("departments");
assertNotNull("Manager.departments is null!", fmd1);
assertEquals("Manager.departments mapped-by is incorrect", fmd1.getMappedBy(), "manager");
assertEquals("Manager.departments relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_BI);
ElementMetaData elemmd = fmd1.getElementMetaData();
assertNull("Manager.departments has join column info but shouldnt (specified on N side)", elemmd);
// non-owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("manager");
assertNotNull("Department.manager is null!", fmd2);
assertEquals("Department.manager mapped-by is incorrect", fmd2.getMappedBy(), null);
assertEquals("Department.manager relationType is incorrect", fmd2.getRelationType(clr), RelationType.MANY_TO_ONE_BI);
ColumnMetaData[] colmds = fmd2.getColumnMetaData();
assertNotNull("Department.manager has no join column info", colmds);
assertEquals("Department.manager has incorrect number of joincolumns", colmds.length, 1);
assertEquals("Department.manager joincolumn name is wrong", "MGR_ID", colmds[0].getName());
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class AnnotationPlusXMLTest 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_AX_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_AX_PETROL_CUST_SUPP");
// non-owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(PetroleumSupplier.class.getName(), clr);
assertEquals("Supplier has incorrect table name", cmd2.getTable(), "JPA_AX_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.MetaDataManager in project tests by datanucleus.
the class AnnotationPlusXMLTest method testOneToManyUniJoin.
/**
* Test of JPA 1-N unidir JoinTable relation
*/
public void testOneToManyUniJoin() {
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(Department.class.getName(), clr);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("projects");
assertNotNull("Department.projects is null!", fmd1);
assertEquals("Department.projects mapped-by is incorrect", null, fmd1.getMappedBy());
assertEquals("Department.projects relationType is incorrect", RelationType.ONE_TO_MANY_UNI, fmd1.getRelationType(clr));
assertEquals("Department.projects jointable name is incorrect", "JPA_AX_DEPT_PROJECTS", fmd1.getTable());
JoinMetaData joinmd = fmd1.getJoinMetaData();
assertNotNull("Department.projects has no join table!", joinmd);
assertNotNull("Department.projects has incorrect join columns", joinmd.getColumnMetaData());
assertEquals("Department.projects has incorrect number of join columns", 1, joinmd.getColumnMetaData().length);
assertEquals("Department.projects has incorrect join column name", joinmd.getColumnMetaData()[0].getName(), "DEPT_ID");
ElementMetaData elemmd = fmd1.getElementMetaData();
assertNotNull("Department.projects has no element column info but should", elemmd);
ColumnMetaData[] colmds = elemmd.getColumnMetaData();
assertNotNull("Department.projects has incorrect element columns", colmds);
assertEquals("Department.projects has incorrect number of element columns", 1, colmds.length);
assertEquals("Department.projects has incorrect element column name", "PROJECT_ID", colmds[0].getName());
}
Aggregations