KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > query > POBuilder


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27
28 package org.objectweb.speedo.runtime.query;
29
30 import org.objectweb.speedo.pobjects.ref.Department;
31 import org.objectweb.speedo.pobjects.ref.Employee;
32 import org.objectweb.speedo.pobjects.ref.GeoRef;
33 import org.objectweb.speedo.pobjects.collection.AMMB;
34 import org.objectweb.speedo.pobjects.collection.BMMB;
35 import org.objectweb.speedo.pobjects.collection.Group;
36 import org.objectweb.speedo.pobjects.inheritance.query.GroupModerator;
37 import org.objectweb.speedo.pobjects.inheritance.query.MailingList;
38 import org.objectweb.speedo.pobjects.inheritance.query.GroupUser;
39 import org.objectweb.speedo.pobjects.collection.Ref2AMMB;
40 import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB;
41 import org.objectweb.speedo.pobjects.collection.User;
42 import org.objectweb.speedo.SpeedoTestHelper;
43
44 import javax.jdo.PersistenceManager;
45 import java.util.Collection JavaDoc;
46 import java.util.ArrayList JavaDoc;
47
48 /**
49  * @author S.Chassande-Barrioz
50  */

51 public class POBuilder extends SpeedoTestHelper {
52
53     public final static String JavaDoc depName = "RD";
54     public final static String JavaDoc[] depNames = { "MAPS", "BIZZ", "TECK"};
55     public final static String JavaDoc[] names = {"John", "Paul", "Marie", "Sandie"};
56     public final static float[] salaries = {4000, 3000, 2999, 3001};
57     public final static int[] nameOrder = {0, 2, 1, 3};
58     public final static int[] salariesOrder = {0, 3, 1, 2};
59     public final static int NB_XMMB = 4;
60     public final static int NB_GROUP = 3;
61     public final static int NB_USER_PER_GROUP = 3;
62
63     public POBuilder(String JavaDoc name) {
64         super(name);
65     }
66
67     protected String JavaDoc getLoggerName() {
68         return LOG_NAME + ".rt.query";
69     }
70
71     public void testCreationOfPersistentObject() {
72         PersistenceManager pm = pmf.getPersistenceManager();
73         Department d = new Department(depName);
74         pm.makePersistent(d);
75         for(int i=0; i<depNames.length; i++) {
76             pm.makePersistent(new Department(depNames[i]));
77         }
78
79         //Creation of Employee
80
for(int i=0; i<names.length; i++) {
81             pm.makePersistent(new Employee(names[i], d, salaries[i]));
82         }
83
84         //Creation of XMNB objects for testing collection operator
85
Ref2AMMB[] r1 = new Ref2AMMB[NB_XMMB];
86         Ref2Ref2AMMB[] r2 = new Ref2Ref2AMMB[NB_XMMB];
87         AMMB[] as = new AMMB[NB_XMMB];
88         BMMB[] bs = new BMMB[NB_XMMB];
89         for(int i=0; i<as.length; i++) {
90             as[i] = new AMMB(i);
91             bs[i] = new BMMB(i);
92             r1[i] = new Ref2AMMB(i*10, as[i]);
93             r2[i] = new Ref2Ref2AMMB(i*100, r1[i]);
94         }
95         Collection JavaDoc as0 = new ArrayList JavaDoc(2);
96         as0.add(bs[0]);
97         as0.add(bs[1]);
98         as[0].setBs(as0);
99         Collection JavaDoc as1 = new ArrayList JavaDoc(3);
100         as1.add(bs[0]);
101         as1.add(bs[1]);
102         as1.add(bs[2]);
103         as[1].setBs(as1);
104         Collection JavaDoc as2 = new ArrayList JavaDoc(2);
105         as2.add(bs[1]);
106         as2.add(bs[2]);
107         as[2].setBs(as2);
108
109         Collection JavaDoc bs0 = new ArrayList JavaDoc(2);
110         bs0.add(as[0]);
111         bs0.add(as[1]);
112         bs[0].setAs(bs0);
113         Collection JavaDoc bs1 = new ArrayList JavaDoc(3);
114         bs1.add(as[0]);
115         bs1.add(as[1]);
116         bs1.add(as[2]);
117         bs[1].setAs(bs1);
118         Collection JavaDoc bs2 = new ArrayList JavaDoc(2);
119         bs2.add(as[1]);
120         bs2.add(as[2]);
121         bs[2].setAs(bs2);
122         pm.makePersistentAll(r2);
123         pm.makePersistentAll(bs);
124         
125         //creation of groups
126
for(int i=0; i<NB_GROUP; i++) {
127             Group g = new Group("group_" + i);
128             Collection JavaDoc users = g.getUsers();
129             for(int j=0; j<NB_USER_PER_GROUP; j++) {
130                 User u = new User("user_g" + i + "_u" + j);
131                 users.add(u);
132             }
133             pm.makePersistent(g);
134         }
135         
136         //creation of mailinglists
137
for(int i=0; i<NB_GROUP; i++) {
138             MailingList ml = new MailingList("mailinglist_" + i);
139             Collection JavaDoc users = ml.getUsers();
140             for(int j=0; j<NB_USER_PER_GROUP; j++) {
141                 GroupUser u = new GroupUser("user_ml" + i + "_u" + j);
142                 users.add(u);
143             }
144             Collection JavaDoc moderators = ml.getModerators();
145             for(int j=0; j<NB_USER_PER_GROUP; j++) {
146                 GroupModerator gm = new GroupModerator("moderator_ml" + i, "mod" + j);
147                 moderators.add(gm);
148             }
149             pm.makePersistent(ml);
150         }
151         
152         //creation of GeoRef
153
GeoRef g1 = new GeoRef("g1");
154         GeoRef g2 = new GeoRef("g2");
155         GeoRef g3 = new GeoRef("g3");
156         GeoRef g4 = new GeoRef("g4");
157         g2.setPreviousRef(g2);
158         g3.setPreviousRef(g4);
159         g4.setPreviousRef(g1);
160         pm.makePersistent(g1);
161         pm.makePersistent(g2);
162         pm.makePersistent(g3);
163         pm.makePersistent(g4);
164         
165         pm.close();
166     }
167 }
168
Popular Tags