Search in sources :

Example 1 with JDOFatalDataStoreException

use of javax.jdo.JDOFatalDataStoreException in project tests by datanucleus.

the class TransactionTest method testRollbackOnly.

/**
 * Test for the "rollback-only" functionality of a transaction.
 */
public void testRollbackOnly() {
    try {
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        tx.setRollbackOnly();
        assertTrue("Calling setRollbackOnly before starting the transaction should have had no effect, " + "but it set the rollbackOnly to true!", tx.getRollbackOnly() == false);
        try {
            tx.begin();
            Person pers = new Person(101, "Fred", "Flintstone", "fred.flintstone@warnerbros.com");
            pm.makePersistent(pers);
            tx.setRollbackOnly();
            try {
                tx.commit();
                assertTrue("Calling commit() when setRollbackOnly is set should throw an exception, but didnt", false);
            } catch (JDOFatalDataStoreException fde) {
            // Should come through here (outside JavaEE container)
            } catch (JDOUserException fue) {
            // Should come through here (inside JavaEE container)
            }
            try {
                tx.commit();
                assertTrue("Calling commit() when setRollbackOnly is set should throw an exception, but didnt", false);
            } catch (JDOFatalDataStoreException fde) {
            // Should come through here
            } catch (JDOUserException fue) {
            // Should come through here (inside JavaEE container)
            }
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        clean(Person.class);
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) Person(org.jpox.samples.models.company.Person) JDOFatalDataStoreException(javax.jdo.JDOFatalDataStoreException) JDOUserException(javax.jdo.JDOUserException)

Aggregations

JDOFatalDataStoreException (javax.jdo.JDOFatalDataStoreException)1 JDOUserException (javax.jdo.JDOUserException)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 Person (org.jpox.samples.models.company.Person)1