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