Search in sources :

Example 31 with JDOPersistenceManagerFactory

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();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JDOMetadata(javax.jdo.metadata.JDOMetadata) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) PersistenceManagerFactory(javax.jdo.PersistenceManagerFactory) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with JDOPersistenceManagerFactory

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();
}
Also used : SpatialHelper(org.datanucleus.store.types.geospatial.jdo.SpatialHelper) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory)

Example 33 with JDOPersistenceManagerFactory

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();
}
Also used : JgeomSpatialHelper(org.datanucleus.store.types.geospatial.jdo.JgeomSpatialHelper) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory)

Example 34 with JDOPersistenceManagerFactory

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);
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) ArrayList(java.util.ArrayList) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 35 with JDOPersistenceManagerFactory

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));
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Aggregations

JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)39 PersistenceManager (javax.jdo.PersistenceManager)15 PersistenceManagerFactory (javax.jdo.PersistenceManagerFactory)14 Transaction (javax.jdo.Transaction)14 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)14 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)12 NucleusContext (org.datanucleus.NucleusContext)9 Query (javax.jdo.Query)8 MetaDataManager (org.datanucleus.metadata.MetaDataManager)7 DN2NamingFactory (org.datanucleus.store.schema.naming.DN2NamingFactory)7 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)6 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 JDOException (javax.jdo.JDOException)4 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)4 IOException (java.io.IOException)3 Field (java.lang.reflect.Field)3 ArrayList (java.util.ArrayList)3