Search in sources :

Example 1 with MSSQLTypes

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

the class TypesMappingTest method testMSSQLUniqueIdentifierType.

/**
 * Test for MSSQL datastore "UNIQUEIDENTIFIER" type.
 */
public void testMSSQLUniqueIdentifierType() {
    if (!vendorID.equals("sqlserver")) {
        return;
    }
    MSSQLTypes types;
    Object id = null;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        types = new MSSQLTypes();
        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 = (MSSQLTypes) pm.getObjectById(id, true);
        assertEquals("UUIDString retrieved is not 36 chars", 36, types.getUuid().length());
        assertEquals("Simple String retrieved is wrong", "some string", types.getSimpleString());
        assertEquals("UUIDString retrieved is not 36 chars", 36, types.getAnotherString().length());
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
    }
    tx = pm.currentTransaction();
    try {
        tx.begin();
        types = new MSSQLTypes();
        types.setUuid("6F9619FF-8B86-D011-B42D-00C04FC964FF");
        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 = (MSSQLTypes) pm.getObjectById(id, true);
        assertEquals("UUIDString retrieved is not 36 chars", 36, types.getUuid().length());
        assertEquals("UUIDString retrieved is not 6F9619FF-8B86-D011-B42D-00C04FC964FF", "6F9619FF-8B86-D011-B42D-00C04FC964FF", types.getUuid());
        assertEquals("Simple String retrieved is wrong", "some string", types.getSimpleString());
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) MSSQLTypes(org.jpox.samples.rdbms.types.MSSQLTypes)

Aggregations

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