01: package org.apache.ojb.odmg;
02:
03: import java.util.List;
04:
05: import org.apache.ojb.junit.ODMGTestCase;
06: import org.apache.ojb.odmg.shared.Person;
07: import org.apache.ojb.odmg.shared.PersonImpl;
08: import org.odmg.OQLQuery;
09: import org.odmg.Transaction;
10:
11: /** Demo Application that shows basic concepts for Applications using the OJB ODMG
12: * implementation as an transactional object server.
13: */
14: public class ProxyTest extends ODMGTestCase {
15: public static void main(String[] args) {
16: String[] arr = { ProxyTest.class.getName() };
17: junit.textui.TestRunner.main(arr);
18: }
19:
20: /**TestThreadsNLocks state transition of modification states*/
21: public void testLoading() {
22: try {
23: Person mum = new PersonImpl();
24: mum.setFirstname("Macy");
25: mum.setLastname("Gray");
26:
27: Person dad = new PersonImpl();
28: dad.setFirstname("Paul");
29: dad.setLastname("Gray");
30:
31: Person kevin = new PersonImpl();
32: kevin.setFirstname("Kevin");
33: kevin.setLastname("Gray");
34: kevin.setMother(mum);
35: kevin.setFather(dad);
36:
37: Transaction tx = odmg.newTransaction();
38: tx.begin();
39: tx.lock(kevin, Transaction.WRITE);
40: tx.commit();
41:
42: tx = odmg.newTransaction();
43: tx.begin();
44: ((HasBroker) tx).getBroker().clearCache();
45: OQLQuery qry = odmg.newOQLQuery();
46: qry.create("select a from " + PersonImpl.class.getName()
47: + " where firstname=$1");
48: qry.bind("Kevin");
49:
50: List result = (List) qry.execute();
51: Person boy = (Person) result.get(0);
52: assertEquals(boy.getFirstname(), kevin.getFirstname());
53: assertEquals(boy.getFather().getFirstname(), dad
54: .getFirstname());
55: assertEquals(boy.getMother().getFirstname(), mum
56: .getFirstname());
57:
58: tx.commit();
59: } catch (Throwable t) {
60: t.printStackTrace();
61: fail(t.getMessage());
62: }
63: }
64: }
|