Search in sources :

Example 1 with DB2Types

use of org.jpox.samples.rdbms.types.DB2Types in project tests by datanucleus.

the class TypesMappingTest method testDB2DataLinkType.

/**
 * Test for DB2 datastore "DATALINK" type.
 */
public void testDB2DataLinkType() {
    if (!vendorID.equals("db2")) {
        return;
    }
    DB2Types types;
    Object id = null;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        types = new DB2Types();
        types.setDataLinkString("http://www.jpox.org");
        types.setDataLinkString2("http://www.someurl.org/path");
        types.setSimpleString("some string");
        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 = (DB2Types) pm.getObjectById(id, true);
        assertEquals("DataLinkString retrieved is wrong", "http://www.jpox.org".toUpperCase(), types.getDataLinkString().toUpperCase());
        assertEquals("DataLinkString2 retrieved is wrong", "/path".toUpperCase(), types.getDataLinkString2().toUpperCase());
        assertEquals("Simple String retrieved is wrong", "some string", types.getSimpleString());
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        types = (DB2Types) ((Collection) pm.newQuery(DB2Types.class).execute()).iterator().next();
        assertEquals("DataLinkString retrieved from Query is wrong", "http://www.jpox.org".toUpperCase(), types.getDataLinkString().toUpperCase());
        assertEquals("DataLinkString2 retrieved from Query is wrong", "/path".toUpperCase(), types.getDataLinkString2().toUpperCase());
        assertEquals("Simple String retrieved from Query is wrong", "some string", types.getSimpleString());
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : DB2Types(org.jpox.samples.rdbms.types.DB2Types) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 DB2Types (org.jpox.samples.rdbms.types.DB2Types)1