Search in sources :

Example 1 with OracleTypes

use of org.datanucleus.samples.dbspecific.OracleTypes in project tests by datanucleus.

the class TypesMappingTest method testXMLType.

/**
 * Test for Oracles XMLType.
 * TODO Need to have Oracle XMLType in CLASSPATH for this
 */
public void testXMLType() {
    if (!vendorID.equals("oracle")) {
        return;
    }
    OracleTypes types;
    Object id = null;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    String xml = "<jdo><package/></jdo>";
    String xml2 = "<jdo><package name=\"org.datanucleus\"/></jdo>";
    try {
        tx.begin();
        types = new OracleTypes();
        types.setXml(xml);
        pm.makePersistent(types);
        id = JDOHelper.getObjectId(types);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        types = (OracleTypes) pm.getObjectById(id, true);
        assertEquals(xml, types.getXml());
        tx.commit();
        // test update
        tx.begin();
        types = (OracleTypes) pm.getObjectById(id, true);
        types.setXml(xml2);
        tx.commit();
        tx.begin();
        types = (OracleTypes) pm.getObjectById(id, true);
        pm.refresh(types);
        assertEquals(xml2, types.getXml());
        tx.commit();
        // test update to null
        tx.begin();
        types = (OracleTypes) pm.getObjectById(id, true);
        types.setXml(null);
        tx.commit();
        tx.begin();
        types = (OracleTypes) pm.getObjectById(id, true);
        pm.refresh(types);
        assertNull(types.getXml());
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
    }
    // test null
    tx = pm.currentTransaction();
    try {
        tx.begin();
        types = new OracleTypes();
        types.setXml(null);
        pm.makePersistent(types);
        id = JDOHelper.getObjectId(types);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        types = (OracleTypes) pm.getObjectById(id, true);
        assertNull(types.getXml());
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) OracleTypes(org.datanucleus.samples.dbspecific.OracleTypes)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 OracleTypes (org.datanucleus.samples.dbspecific.OracleTypes)1