use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class XMLTest method testTableGenerator.
/**
* Test of JPA <table-generator>
*/
public void testTableGenerator() {
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(Employee.class.getName(), clr);
PackageMetaData pmd = cmd1.getPackageMetaData();
assertEquals("Number of TableGenerators registered for Employee class is wrong", pmd.getNoOfTableGenerators(), 1);
TableGeneratorMetaData tgmd = pmd.getTableGenerators()[0];
assertEquals("TableGenerator has incorrect name", tgmd.getName(), "EmployeeGenerator");
assertEquals("TableGenerator has incorrect table", tgmd.getTableName(), "ID_TABLE");
assertEquals("TableGenerator has incorrect pk column name", tgmd.getPKColumnName(), "TYPE");
assertEquals("TableGenerator has incorrect value column name", tgmd.getValueColumnName(), "LATEST_VALUE");
assertEquals("TableGenerator has incorrect pk column value", tgmd.getPKColumnValue(), "EMPLOYEE");
assertEquals("TableGenerator has incorrect initial value", tgmd.getInitialValue(), 0);
assertEquals("TableGenerator has incorrect allocation size", tgmd.getAllocationSize(), 50);
}
use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class XMLTest method testNamedQuery.
/**
* Test of JPA <named-query>, <named-native-query>
*/
public void testNamedQuery() {
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 cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(LoginAccount.class.getName(), clr);
QueryMetaData[] qmds = cmd.getQueries();
assertNotNull("LoginAccount has no queries!", qmds);
assertEquals("LoginAccount has incorrect number of queries", 2, qmds.length);
QueryMetaData jpqlQuery = null;
QueryMetaData sqlQuery = null;
if (qmds[0].getLanguage().equals(QueryLanguage.JPQL.toString())) {
jpqlQuery = qmds[0];
} else if (qmds[1].getLanguage().equals(QueryLanguage.JPQL.toString())) {
jpqlQuery = qmds[1];
}
if (qmds[0].getLanguage().equals(QueryLanguage.SQL.toString())) {
sqlQuery = qmds[0];
} else if (qmds[1].getLanguage().equals(QueryLanguage.SQL.toString())) {
sqlQuery = qmds[1];
}
if (jpqlQuery == null) {
fail("No JPQL Query was registered for LoginAccount");
}
if (sqlQuery == null) {
fail("No SQL Query was registered for LoginAccount");
}
assertEquals("LoginAccount JPQL has incorrect query name", "LoginForJohnSmith", jpqlQuery.getName());
assertEquals("LoginAccount JPQL has incorrect query", "SELECT a FROM LoginAccount a WHERE a.firstName='John' AND a.lastName='Smith'", jpqlQuery.getQuery());
assertEquals("LoginAccount SQL has incorrect query name", "LoginForJohn", sqlQuery.getName());
assertEquals("LoginAccount SQL has incorrect query", "SELECT * FROM JPALOGIN WHERE FIRSTNAME = 'John'", sqlQuery.getQuery());
}
use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class XMLTest 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.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.
the class XMLTest 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.api.jpa.metadata.JPAMetaDataManager 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");
}
Aggregations