use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class JDOPersistenceTestCase method getPMF.
/**
* Method to obtain the PMF to use allowing specification of custom user PMF properties. Creates a new PMF on each call.
* @param userProps The custom PMF props to use when creating the PMF
* @return The PMF (also stored in the local "pmf" variable)
*/
protected static synchronized PersistenceManagerFactory getPMF(Properties userProps) {
if (pmf != null) {
if (!pmf.isClosed()) {
// Close the current PMF first
pmf.close();
}
}
pmf = JDOPersistenceTestCase.getPMF(1, userProps);
freezePMF(pmf);
// Set up the StoreManager
storeMgr = ((JDOPersistenceManagerFactory) pmf).getNucleusContext().getStoreManager();
ClassLoaderResolver clr = storeMgr.getNucleusContext().getClassLoaderResolver(null);
try {
clr.classForName("org.datanucleus.store.rdbms.RDBMSStoreManager");
if (storeMgr instanceof org.datanucleus.store.rdbms.RDBMSStoreManager) {
// RDBMS datastores have a vendor id
vendorID = ((org.datanucleus.store.rdbms.RDBMSStoreManager) storeMgr).getDatastoreAdapter().getVendorID();
}
} catch (ClassNotResolvedException cnre) {
}
return pmf;
}
use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class JPAPersistenceTestCase method getMetaDataForPersistenceUnit.
/**
* Convenience method to extract the metadata for a persistence-unit.
* @param nucleusCtx NucleusContext
* @param persistenceUnitName Name of the persistence-unit
* @return MetaData for the persistence-unit (or null if not found)
*/
public PersistenceUnitMetaData getMetaDataForPersistenceUnit(NucleusContext nucleusCtx, String persistenceUnitName) {
String filename = nucleusCtx.getConfiguration().getStringProperty(PropertyNames.PROPERTY_PERSISTENCE_XML_FILENAME);
boolean validateXML = nucleusCtx.getConfiguration().getBooleanProperty(PropertyNames.PROPERTY_METADATA_XML_VALIDATE);
boolean supportXMLNamespaces = nucleusCtx.getConfiguration().getBooleanProperty(PropertyNames.PROPERTY_METADATA_XML_NAMESPACE_AWARE);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
return MetaDataUtils.getMetaDataForPersistenceUnit(nucleusCtx.getPluginManager(), filename, persistenceUnitName, validateXML, supportXMLNamespaces, clr);
}
use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationPlusXMLTest 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.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationPlusXMLTest method testOneToOneBi.
/**
* Test of 1-1 bi relation
*/
public void testOneToOneBi() {
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);
// non-owner side
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Boiler.class.getName(), clr);
assertEquals("Boiler has incorrect table name", "JPA_AX_BOILER", cmd1.getTable());
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("timer");
assertNotNull("Boiler.timer is null!", fmd1);
assertEquals("Boiler.timer mapped-by is incorrect", "boiler", fmd1.getMappedBy());
assertEquals("Boiler.timer relationType is incorrect", RelationType.ONE_TO_ONE_BI, fmd1.getRelationType(clr));
// owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Timer.class.getName(), clr);
assertEquals("Timer has incorrect table name", "JPA_AX_TIMER", cmd2.getTable());
AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("boiler");
assertNotNull("Timer.boiler is null!", fmd2);
assertEquals("Timer.boiler mapped-by is incorrect", null, fmd2.getMappedBy());
assertEquals("Timer.boiler relationType is incorrect", RelationType.ONE_TO_ONE_BI, fmd2.getRelationType(clr));
assertNotNull("Timer.boiler has no column info", fmd2.getColumnMetaData());
assertEquals("Timer.boiler has incorrect number of columns", 1, fmd2.getColumnMetaData().length);
assertEquals("Timer.boiler column name is wrong", "BOILER_ID", fmd2.getColumnMetaData()[0].getName());
}
use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationPlusXMLTest method testOneToOneUni.
/**
* Test of 1-1 uni 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_AX_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_AX_LOGIN");
}
Aggregations