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);
}
}
Aggregations