use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class DynamicEnhanceSchemaToolTest method persist.
public void persist(DynamicEnhanceSchemaToolClassLoader runtimeCL) throws Exception {
// Persist
Map props = getPropertiesForDatastore(runtimeCL);
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(props);
try {
ClassLoaderResolver clr = ((JDOPersistenceManagerFactory) pmf).getNucleusContext().getClassLoaderResolver(runtimeCL);
JDOMetadata filemd = pmf.newMetadata();
createMetadata(filemd);
NucleusLogger.PERSISTENCE.info(">> registering metadata");
pmf.registerMetadata(filemd);
NucleusLogger.PERSISTENCE.info(filemd);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
Class clazz = clr.classForName("test.Client");
Object o = clazz.newInstance();
pm.makePersistent(o);
tx.commit();
id = pm.getObjectId(o);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Object obj = pm.getObjectById(id);
pm.deletePersistent(obj);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
pmf.close();
}
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class JtsGeometrySpatialHelperTest method setUp.
protected void setUp() throws Exception {
helper = new SpatialHelper((JDOPersistenceManagerFactory) pmf);
super.setUp();
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class JGeometrySpatialHelperTest method setUp.
protected void setUp() throws Exception {
helper = new JgeomSpatialHelper((JDOPersistenceManagerFactory) pmf);
super.setUp();
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class DN2NamingFactoryTest method testEmbeddedCollectionColumnNames.
/**
* Test where the sample has embedded collection element.
*/
public void testEmbeddedCollectionColumnNames() {
JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
NucleusContext nucCtx = jdoPMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.COLUMN, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
AbstractClassMetaData networkCmd = mmgr.getMetaDataForClass(Network.class, clr);
AbstractMemberMetaData devicesMmd = networkCmd.getMetaDataForMember("devices");
AbstractClassMetaData deviceCmd = mmgr.getMetaDataForClass(Device.class, clr);
AbstractMemberMetaData deviceNameMmd = deviceCmd.getMetaDataForMember("name");
AbstractMemberMetaData deviceDescMmd = deviceCmd.getMetaDataForMember("description");
List<AbstractMemberMetaData> colMmds = new ArrayList<AbstractMemberMetaData>();
colMmds.add(devicesMmd);
colMmds.add(deviceNameMmd);
String colName = factory.getColumnName(colMmds, 0);
assertEquals("device_name", colName);
colMmds.clear();
colMmds.add(devicesMmd);
colMmds.add(deviceDescMmd);
colName = factory.getColumnName(colMmds, 0);
assertEquals("devices_description", colName);
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.
the class DN2NamingFactoryTest method testDatastoreIdColumnName.
public void testDatastoreIdColumnName() {
JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
NucleusContext nucCtx = jdoPMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(Gym.class, clr);
DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
factory.setMaximumLength(SchemaComponent.COLUMN, 128);
factory.setNamingCase(NamingCase.LOWER_CASE);
assertEquals("Column name for datastore-id is incorrect", "gym_id", factory.getColumnName(cmd1, ColumnType.DATASTOREID_COLUMN));
}
Aggregations