1 package org.apache.ojb.jdo; 2 3 import java.util.Collection ; 4 5 import javax.jdo.PersistenceManager; 6 import javax.jdo.Query; 7 8 import junit.framework.TestCase; 9 10 import org.apache.ojb.otm.Person; 11 12 26 27 28 public class TestQueries extends TestCase 29 { 30 private PersistenceManagerFactoryImpl factory = new PersistenceManagerFactoryImpl(); 31 32 private PersistenceManager pm; 33 34 public void setUp() 35 { 36 this.pm = factory.getPersistenceManager(); 37 } 38 39 public void tearDown() 40 { 41 if (!this.pm.isClosed()) this.pm.close(); 42 } 43 44 public void testEmptyFilter() 45 { 46 Person p = new Person("George", "Harrison"); 47 pm.currentTransaction().begin(); 48 pm.makePersistent(p); 49 pm.currentTransaction().commit(); 50 51 pm.evictAll(); 52 53 pm.currentTransaction().begin(); 54 Query q = pm.newQuery(Person.class); 55 Collection results = (Collection ) q.execute(); 56 assertTrue(results.size() > 0); 57 assertTrue(results.iterator().next() instanceof Person); 58 pm.currentTransaction().commit(); 59 } 60 61 public void testEmptyFilterSettingExtent() 62 { 63 Person p = new Person("George", "Harrison"); 64 pm.currentTransaction().begin(); 65 pm.makePersistent(p); 66 pm.currentTransaction().commit(); 67 68 pm.evictAll(); 69 70 pm.currentTransaction().begin(); 71 Query q = pm.newQuery(); 72 q.setCandidates(pm.getExtent(Person.class, true)); 73 Collection results = (Collection ) q.execute(); 74 assertTrue(results.size() > 0); 75 assertTrue(results.iterator().next() instanceof Person); 76 pm.currentTransaction().commit(); 77 } 78 79 public void testClonedQuery() 80 { 81 Person p = new Person("George", "Harrison"); 82 pm.currentTransaction().begin(); 83 pm.makePersistent(p); 84 pm.currentTransaction().commit(); 85 86 pm.evictAll(); 87 88 pm.currentTransaction().begin(); 89 Query q = pm.newQuery(Person.class); 90 q.compile(); 91 Query q2 = pm.newQuery(q); 92 Collection r = (Collection ) q2.execute(); 93 assertTrue(r.size() > 0); 94 assertTrue(r.iterator().next() instanceof Person); 95 pm.currentTransaction().commit(); 96 } 97 } 98 | Popular Tags |