1 package org.apache.ojb.jdo; 2 3 17 18 import junit.framework.TestCase; 19 import org.apache.ojb.otm.Person; 20 21 import javax.jdo.JDOUserException; 22 import javax.jdo.PersistenceManager; 23 import javax.jdo.Query; 24 import javax.jdo.Transaction; 25 import java.util.Collection ; 26 27 public class TestTransactions extends TestCase 28 { 29 30 private PersistenceManagerFactoryImpl factory = new PersistenceManagerFactoryImpl(); 31 32 33 public void testReBeginTx() throws Exception 34 { 35 Person person = new Person(); 36 person.setFirstname("Brian"); 37 person.setLastname("McCallister"); 38 PersistenceManager pm = factory.getPersistenceManager(); 39 Transaction tx = pm.currentTransaction(); 40 tx.begin(); 41 pm.makePersistent(person); 42 tx.commit(); 43 44 tx.begin(); 45 Query q = pm.newQuery(Person.class); 46 Collection persons = (Collection ) q.execute(); 47 tx.commit(); 48 assertTrue(persons.size() > 0); 49 pm.close(); 50 } 51 52 public void testExceptionOnReBegin() 53 { 54 PersistenceManager pm = factory.getPersistenceManager(); 55 Transaction tx = pm.currentTransaction(); 56 tx.begin(); 57 try 58 { 59 tx.begin(); 60 fail("Should have thrown an exception"); 61 } 62 catch (JDOUserException e) 63 { 64 assertTrue("Flow passes through here", true); 65 } 66 pm.close(); 67 } 68 } 69 | Popular Tags |