* Transaction testing
*/
public static void test9() throws Exception {
System.out.println("** Test 9: Transaction testing");
DBConnection connection = DBFactory.get().getConnection();
clearData();
try {
connection.startTransaction();
loadData();
throw new Exception("test!!!");
} catch (Exception e) {
connection.rollback();
// checking
check( Author.cls.count() == 0 );
check( Library.cls.count() == 0 );
check( Book.cls.count() == 0 );
check( Member.cls.count() == 0 );
check( Transaction.cls.count() == 0 );
} finally {
connection.finishTransaction();
}
clearData();
connection.startTransaction();
loadData();
connection.commit();
check( Author.cls.count() > 0 );
check( Library.cls.count() > 0 );
check( Book.cls.count() > 0 );
check( Member.cls.count() > 0 );
check( Transaction.cls.count() > 0 );
connection.finishTransaction();
clearData();
connection.startTransaction();
loadData();
// save point
DBSavePoint point = connection.savePoint();
Author.cls.get(1).setLastName("test1");
connection.rollback(point);
connection.releasePoint(point);
connection.commit();
check( Author.cls.count() > 0 );
check( Library.cls.count() > 0 );
check( Book.cls.count() > 0 );
check( Member.cls.count() > 0 );
check( Transaction.cls.count() > 0 );
connection.finishTransaction();
}