1 18 package org.objectweb.speedo.runtime.collection; 19 20 import org.objectweb.speedo.SpeedoTestHelper; 21 import org.objectweb.speedo.pobjects.collection.G; 22 import org.objectweb.speedo.pobjects.collection.H; 23 24 import javax.jdo.PersistenceManager; 25 import javax.jdo.Query; 26 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 31 35 public class TestGH extends SpeedoTestHelper { 36 37 public TestGH(String s) { 38 super(s); 39 } 40 41 protected String getLoggerName() { 42 return LOG_NAME + ".rt.collection.TestGH"; 43 } 44 45 public void testA() { 46 int NBOBJ = 10; 47 PersistenceManager pm = pmf.getPersistenceManager(); 48 pm.currentTransaction().begin(); 49 G g = new G("g1_testA"); 50 Collection hs = g.getHs(); 51 for(int i=0; i<NBOBJ; i++) { 52 H h = new H("hid_" + i); 53 h.setH1("h1_testA"); 54 hs.add(h); 55 } 56 pm.makePersistent(g); 57 g = null; 58 hs = null; 59 pm.currentTransaction().commit(); 60 pm.evictAll(); 61 pm.close(); 62 pm = pmf.getPersistenceManager(); 63 pm.evictAll(); 64 pm.currentTransaction().begin(); 65 H h0 = (H) pm.getObjectById(pm.newObjectIdInstance(H.class, "hid_0"), false); 66 assertNotNull("Null h0", h0); 67 g = h0.getG(); 68 assertNotNull("Null g", g); 69 pm.deletePersistentAll(g.getHs()); 70 pm.deletePersistent(g); 71 pm.currentTransaction().commit(); 72 pm.close(); 73 74 } 75 public void testCollectionElementLoadingWithPrefetch() { 76 int NBOBJ = 2; 77 PersistenceManager pm = pmf.getPersistenceManager(); 78 pm.currentTransaction().begin(); 80 G g = new G("g1_testCollectionElementLoadingWithPrefetch"); 81 Collection hs = g.getHs(); 82 for(int i=0; i<NBOBJ; i++) { 83 H h = new H("hid_" + i); 84 h.setH1("h1_testCollectionElementLoadingWithPrefetch"); 85 hs.add(h); 86 } 87 hs = null; 88 pm.makePersistent(g); 89 Object g_oid = pm.getObjectId(g); 90 g = null; 91 pm.currentTransaction().commit(); 92 93 pm.evictAll(); 95 96 pm.currentTransaction().begin(); 97 Query q = pm.newQuery(H.class); 98 q.declareParameters("String p1"); 99 q.setFilter("hid == p1"); 100 Object o = new ArrayList (((Collection ) q.execute("hid_" + (NBOBJ-1)))); 101 q.closeAll(); 102 103 g = (G) pm.getObjectById(g_oid, false); 104 for (Iterator iter = g.getHs().iterator(); iter.hasNext();) { 105 iter.next(); 106 } 107 pm.currentTransaction().commit(); 108 109 pm.currentTransaction().begin(); 111 pm.deletePersistentAll(g.getHs()); 112 pm.deletePersistent(g); 113 pm.currentTransaction().commit(); 114 pm.close(); 115 116 } 117 } 118 | Popular Tags |