001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.runtime.collection;
018:
019: import org.objectweb.speedo.SpeedoTestHelper;
020: import org.objectweb.speedo.pobjects.collection.G;
021: import org.objectweb.speedo.pobjects.collection.H;
022:
023: import javax.jdo.PersistenceManager;
024: import javax.jdo.Query;
025:
026: import java.util.ArrayList;
027: import java.util.Collection;
028: import java.util.Iterator;
029:
030: /**
031: *
032: * @author S.Chassande-Barrioz
033: */
034: public class TestGH extends SpeedoTestHelper {
035:
036: public TestGH(String s) {
037: super (s);
038: }
039:
040: protected String getLoggerName() {
041: return LOG_NAME + ".rt.collection.TestGH";
042: }
043:
044: public void testA() {
045: int NBOBJ = 10;
046: PersistenceManager pm = pmf.getPersistenceManager();
047: pm.currentTransaction().begin();
048: G g = new G("g1_testA");
049: Collection hs = g.getHs();
050: for (int i = 0; i < NBOBJ; i++) {
051: H h = new H("hid_" + i);
052: h.setH1("h1_testA");
053: hs.add(h);
054: }
055: pm.makePersistent(g);
056: g = null;
057: hs = null;
058: pm.currentTransaction().commit();
059: pm.evictAll();
060: pm.close();
061: pm = pmf.getPersistenceManager();
062: pm.evictAll();
063: pm.currentTransaction().begin();
064: H h0 = (H) pm.getObjectById(pm.newObjectIdInstance(H.class,
065: "hid_0"), false);
066: assertNotNull("Null h0", h0);
067: g = h0.getG();
068: assertNotNull("Null g", g);
069: pm.deletePersistentAll(g.getHs());
070: pm.deletePersistent(g);
071: pm.currentTransaction().commit();
072: pm.close();
073:
074: }
075:
076: public void testCollectionElementLoadingWithPrefetch() {
077: int NBOBJ = 2;
078: PersistenceManager pm = pmf.getPersistenceManager();
079: //create persistent instances
080: pm.currentTransaction().begin();
081: G g = new G("g1_testCollectionElementLoadingWithPrefetch");
082: Collection hs = g.getHs();
083: for (int i = 0; i < NBOBJ; i++) {
084: H h = new H("hid_" + i);
085: h.setH1("h1_testCollectionElementLoadingWithPrefetch");
086: hs.add(h);
087: }
088: hs = null;
089: pm.makePersistent(g);
090: Object g_oid = pm.getObjectId(g);
091: g = null;
092: pm.currentTransaction().commit();
093:
094: //evict all instances
095: pm.evictAll();
096:
097: pm.currentTransaction().begin();
098: Query q = pm.newQuery(H.class);
099: q.declareParameters("String p1");
100: q.setFilter("hid == p1");
101: Object o = new ArrayList(((Collection) q.execute("hid_"
102: + (NBOBJ - 1))));
103: q.closeAll();
104:
105: g = (G) pm.getObjectById(g_oid, false);
106: for (Iterator iter = g.getHs().iterator(); iter.hasNext();) {
107: iter.next();
108: }
109: pm.currentTransaction().commit();
110:
111: //Clean up
112: pm.currentTransaction().begin();
113: pm.deletePersistentAll(g.getHs());
114: pm.deletePersistent(g);
115: pm.currentTransaction().commit();
116: pm.close();
117:
118: }
119: }
|