001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: * Authors: S.Chassande-Barrioz.
025: *
026: */package org.objectweb.speedo.runtime.query;
027:
028: import org.objectweb.speedo.api.SpeedoProperties;
029: import org.objectweb.speedo.pobjects.ref.Department;
030: import org.objectweb.speedo.pobjects.ref.Employee;
031: import org.objectweb.speedo.pobjects.ref.GeoRef;
032: import org.objectweb.speedo.pobjects.collection.AMMB;
033: import org.objectweb.speedo.pobjects.collection.BMMB;
034: import org.objectweb.speedo.pobjects.collection.Group;
035: import org.objectweb.speedo.pobjects.inheritance.query.GroupModerator;
036: import org.objectweb.speedo.pobjects.inheritance.query.MailingList;
037: import org.objectweb.speedo.pobjects.inheritance.query.GroupUser;
038: import org.objectweb.speedo.pobjects.collection.Ref2AMMB;
039: import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB;
040: import org.objectweb.speedo.pobjects.collection.User;
041: import org.objectweb.speedo.SpeedoTestHelper;
042:
043: import javax.jdo.PersistenceManager;
044: import java.util.Collection;
045: import java.util.ArrayList;
046: import java.util.List;
047: import java.util.Properties;
048:
049: /**
050: * @author S.Chassande-Barrioz
051: */
052: public class POBuilder extends SpeedoTestHelper {
053:
054: public final static String depName = "RD";
055: public final static String[] depNames = { "MAPS", "BIZZ", "TECK" };
056: public final static String[] names = { "John", "Paul", "Marie",
057: "Sandie" };
058: public final static float[] salaries = { 4000, 3000, 2999, 3001 };
059: public final static int[] nameOrder = { 0, 2, 1, 3 };
060: public final static int[] salariesOrder = { 0, 3, 1, 2 };
061: public final static int NB_XMMB = 4;
062: public final static int NB_GROUP = 3;
063: public final static int NB_USER_PER_GROUP = 3;
064:
065: public POBuilder(String name) {
066: super (name);
067: }
068:
069: protected String getLoggerName() {
070: return LOG_NAME + ".rt.query";
071: }
072:
073: public Properties getPMFProperties() {
074: Properties prop = super .getPMFProperties();
075: prop.setProperty(SpeedoProperties.MAPPING_STRUCTURE,
076: SpeedoProperties.MAPPING_STRUCTURE_DD);
077: return prop;
078: }
079:
080: public void testCreationOfPersistentObject() {
081: PersistenceManager pm = pmf.getPersistenceManager();
082: Department d = new Department(depName);
083: pm.makePersistent(d);
084: for (int i = 0; i < depNames.length; i++) {
085: pm.makePersistent(new Department(depNames[i]));
086: }
087:
088: //Creation of Employee
089: for (int i = 0; i < names.length; i++) {
090: pm.makePersistent(new Employee(names[i], d, salaries[i]));
091: }
092:
093: //Creation of XMNB objects for testing collection operator
094: Ref2AMMB[] r1 = new Ref2AMMB[NB_XMMB];
095: Ref2Ref2AMMB[] r2 = new Ref2Ref2AMMB[NB_XMMB];
096: AMMB[] as = new AMMB[NB_XMMB];
097: BMMB[] bs = new BMMB[NB_XMMB];
098: for (int i = 0; i < as.length; i++) {
099: as[i] = new AMMB(i);
100: bs[i] = new BMMB(i);
101: r1[i] = new Ref2AMMB(i * 10, as[i]);
102: r2[i] = new Ref2Ref2AMMB(i * 100, r1[i]);
103: }
104: Collection as0 = new ArrayList(2);
105: as0.add(bs[0]);
106: as0.add(bs[1]);
107: as[0].setBs(as0);
108: Collection as1 = new ArrayList(3);
109: as1.add(bs[0]);
110: as1.add(bs[1]);
111: as1.add(bs[2]);
112: as[1].setBs(as1);
113: Collection as2 = new ArrayList(2);
114: as2.add(bs[1]);
115: as2.add(bs[2]);
116: as[2].setBs(as2);
117:
118: Collection bs0 = new ArrayList(2);
119: bs0.add(as[0]);
120: bs0.add(as[1]);
121: bs[0].setAs(bs0);
122: Collection bs1 = new ArrayList(3);
123: bs1.add(as[0]);
124: bs1.add(as[1]);
125: bs1.add(as[2]);
126: bs[1].setAs(bs1);
127: Collection bs2 = new ArrayList(2);
128: bs2.add(as[1]);
129: bs2.add(as[2]);
130: bs[2].setAs(bs2);
131: pm.makePersistentAll(r2);
132: pm.makePersistentAll(bs);
133:
134: //creation of groups
135: for (int i = 0; i < NB_GROUP; i++) {
136: Group g = new Group("group_" + i);
137: Collection users = g.getUsers();
138: for (int j = 0; j < NB_USER_PER_GROUP; j++) {
139: User u = new User("user_g" + i + "_u" + j);
140: users.add(u);
141: }
142: pm.makePersistent(g);
143: }
144:
145: //creation of mailinglists
146: for (int i = 0; i < NB_GROUP; i++) {
147: MailingList ml = new MailingList("mailinglist_" + i);
148: Collection users = ml.getUsers();
149: for (int j = 0; j < NB_USER_PER_GROUP; j++) {
150: GroupUser u = new GroupUser("user_ml" + i + "_u" + j);
151: users.add(u);
152: }
153: Collection moderators = ml.getModerators();
154: for (int j = 0; j < NB_USER_PER_GROUP; j++) {
155: GroupModerator gm = new GroupModerator("moderator_ml"
156: + i, "mod" + j);
157: moderators.add(gm);
158: }
159: pm.makePersistent(ml);
160: }
161:
162: //creation of GeoRef
163: GeoRef g1 = new GeoRef("g1");
164: GeoRef g2 = new GeoRef("g2");
165: GeoRef g3 = new GeoRef("g3");
166: GeoRef g4 = new GeoRef("g4");
167: g2.setPreviousRef(g2);
168: g3.setPreviousRef(g4);
169: g4.setPreviousRef(g1);
170: pm.makePersistent(g1);
171: pm.makePersistent(g2);
172: pm.makePersistent(g3);
173: pm.makePersistent(g4);
174:
175: pm.close();
176: }
177:
178: public static List getUserNames() {
179: ArrayList res = new ArrayList();
180: for (int i = 0; i < NB_GROUP; i++) {
181: for (int j = 0; j < NB_USER_PER_GROUP; j++) {
182: res.add("user_g" + i + "_u" + j);
183: }
184: }
185: return res;
186: }
187: }
|