KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > jdo > TestJDOQL


1 package org.apache.ojb.jdo;
2
3 import junit.framework.TestCase;
4 import org.apache.ojb.otm.Person;
5
6 import javax.jdo.PersistenceManager;
7 import javax.jdo.Query;
8 import java.util.Collection JavaDoc;
9
10 public class TestJDOQL extends TestCase
11 {
12     private PersistenceManagerFactoryImpl factory = new PersistenceManagerFactoryImpl();
13
14     private PersistenceManager pm;
15
16     public void setUp()
17     {
18         this.pm = factory.getPersistenceManager();
19     }
20
21     public void tearDown()
22     {
23         if (!this.pm.isClosed()) this.pm.close();
24     }
25
26     public void _testOneVariableSubstitution()
27     {
28         Person p = new Person("George", "Harrison");
29         pm.currentTransaction().begin();
30         pm.makePersistent(p);
31         pm.currentTransaction().commit();
32
33         pm.evictAll();
34
35         pm.currentTransaction().begin();
36         Query q = pm.newQuery(Person.class);
37         q.declareVariables("java.lang.Integer pid");
38         q.declareImports("org.apache.ojb.otm.Person");
39         q.setFilter( "id == pid");
40         Collection JavaDoc results = (Collection JavaDoc) q.execute(new Integer JavaDoc(p.getId()));
41
42         assertNotNull(results);
43         assertEquals(1, results.size());
44         Person same = (Person) results.iterator().next();
45         assertEquals(p.getId(), same.getId());
46         
47         pm.currentTransaction().commit();
48     }
49 }
50
Popular Tags