1 package org.apache.ojb.odmg; 2 3 4 import java.util.List ; 5 6 import org.apache.ojb.junit.ODMGTestCase; 7 import org.apache.ojb.odmg.shared.Person; 8 import org.apache.ojb.odmg.shared.PersonImpl; 9 import org.odmg.OQLQuery; 10 import org.odmg.Transaction; 11 12 15 public class ProxyTest extends ODMGTestCase 16 { 17 public static void main(String [] args) 18 { 19 String [] arr = {ProxyTest.class.getName()}; 20 junit.textui.TestRunner.main(arr); 21 } 22 23 24 public void testLoading() 25 { 26 try 27 { 28 Person mum = new PersonImpl(); 29 mum.setFirstname("Macy"); 30 mum.setLastname("Gray"); 31 32 Person dad = new PersonImpl(); 33 dad.setFirstname("Paul"); 34 dad.setLastname("Gray"); 35 36 Person kevin = new PersonImpl(); 37 kevin.setFirstname("Kevin"); 38 kevin.setLastname("Gray"); 39 kevin.setMother(mum); 40 kevin.setFather(dad); 41 42 Transaction tx = odmg.newTransaction(); 43 tx.begin(); 44 tx.lock(kevin, Transaction.WRITE); 45 tx.commit(); 46 47 tx = odmg.newTransaction(); 48 tx.begin(); 49 ((HasBroker) tx).getBroker().clearCache(); 50 OQLQuery qry = odmg.newOQLQuery(); 51 qry.create("select a from " + PersonImpl.class.getName() + " where firstname=$1"); 52 qry.bind("Kevin"); 53 54 List result = (List ) qry.execute(); 55 Person boy = (Person) result.get(0); 56 assertEquals(boy.getFirstname(), kevin.getFirstname()); 57 assertEquals(boy.getFather().getFirstname(), dad.getFirstname()); 58 assertEquals(boy.getMother().getFirstname(), mum.getFirstname()); 59 60 tx.commit(); 61 } 62 catch (Throwable t) 63 { 64 t.printStackTrace(); 65 fail(t.getMessage()); 66 } 67 } 68 } 69 | Popular Tags |