/**
* Speedo: an implementation of JDO compliant personality on top of JORM generic
* I/O sub-system.
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
*
* Contact: speedo@objectweb.org
*
* Authors: S.Chassande-Barrioz.
*
*/
package org.objectweb.speedo.runtime.query;
import org.objectweb.speedo.api.SpeedoProperties;
import org.objectweb.speedo.pobjects.ref.Department;
import org.objectweb.speedo.pobjects.ref.Employee;
import org.objectweb.speedo.pobjects.ref.GeoRef;
import org.objectweb.speedo.pobjects.collection.AMMB;
import org.objectweb.speedo.pobjects.collection.BMMB;
import org.objectweb.speedo.pobjects.collection.Group;
import org.objectweb.speedo.pobjects.inheritance.query.GroupModerator;
import org.objectweb.speedo.pobjects.inheritance.query.MailingList;
import org.objectweb.speedo.pobjects.inheritance.query.GroupUser;
import org.objectweb.speedo.pobjects.collection.Ref2AMMB;
import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB;
import org.objectweb.speedo.pobjects.collection.User;
import org.objectweb.speedo.SpeedoTestHelper;
import javax.jdo.PersistenceManager;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* @author S.Chassande-Barrioz
*/
public class POBuilder extends SpeedoTestHelper {
public final static String depName = "RD";
public final static String[] depNames = { "MAPS", "BIZZ", "TECK"};
public final static String[] names = {"John", "Paul", "Marie", "Sandie"};
public final static float[] salaries = {4000, 3000, 2999, 3001};
public final static int[] nameOrder = {0, 2, 1, 3};
public final static int[] salariesOrder = {0, 3, 1, 2};
public final static int NB_XMMB = 4;
public final static int NB_GROUP = 3;
public final static int NB_USER_PER_GROUP = 3;
public POBuilder(String name) {
super(name);
}
protected String getLoggerName() {
return LOG_NAME + ".rt.query";
}
public Properties getPMFProperties() {
Properties prop = super.getPMFProperties();
prop.setProperty(SpeedoProperties.MAPPING_STRUCTURE,
SpeedoProperties.MAPPING_STRUCTURE_DD);
return prop;
}
public void testCreationOfPersistentObject() {
PersistenceManager pm = pmf.getPersistenceManager();
Department d = new Department(depName);
pm.makePersistent(d);
for(int i=0; i<depNames.length; i++) {
pm.makePersistent(new Department(depNames[i]));
}
//Creation of Employee
for(int i=0; i<names.length; i++) {
pm.makePersistent(new Employee(names[i], d, salaries[i]));
}
//Creation of XMNB objects for testing collection operator
Ref2AMMB[] r1 = new Ref2AMMB[NB_XMMB];
Ref2Ref2AMMB[] r2 = new Ref2Ref2AMMB[NB_XMMB];
AMMB[] as = new AMMB[NB_XMMB];
BMMB[] bs = new BMMB[NB_XMMB];
for(int i=0; i<as.length; i++) {
as[i] = new AMMB(i);
bs[i] = new BMMB(i);
r1[i] = new Ref2AMMB(i*10, as[i]);
r2[i] = new Ref2Ref2AMMB(i*100, r1[i]);
}
Collection as0 = new ArrayList(2);
as0.add(bs[0]);
as0.add(bs[1]);
as[0].setBs(as0);
Collection as1 = new ArrayList(3);
as1.add(bs[0]);
as1.add(bs[1]);
as1.add(bs[2]);
as[1].setBs(as1);
Collection as2 = new ArrayList(2);
as2.add(bs[1]);
as2.add(bs[2]);
as[2].setBs(as2);
Collection bs0 = new ArrayList(2);
bs0.add(as[0]);
bs0.add(as[1]);
bs[0].setAs(bs0);
Collection bs1 = new ArrayList(3);
bs1.add(as[0]);
bs1.add(as[1]);
bs1.add(as[2]);
bs[1].setAs(bs1);
Collection bs2 = new ArrayList(2);
bs2.add(as[1]);
bs2.add(as[2]);
bs[2].setAs(bs2);
pm.makePersistentAll(r2);
pm.makePersistentAll(bs);
//creation of groups
for(int i=0; i<NB_GROUP; i++) {
Group g = new Group("group_" + i);
Collection users = g.getUsers();
for(int j=0; j<NB_USER_PER_GROUP; j++) {
User u = new User("user_g" + i + "_u" + j);
users.add(u);
}
pm.makePersistent(g);
}
//creation of mailinglists
for(int i=0; i<NB_GROUP; i++) {
MailingList ml = new MailingList("mailinglist_" + i);
Collection users = ml.getUsers();
for(int j=0; j<NB_USER_PER_GROUP; j++) {
GroupUser u = new GroupUser("user_ml" + i + "_u" + j);
users.add(u);
}
Collection moderators = ml.getModerators();
for(int j=0; j<NB_USER_PER_GROUP; j++) {
GroupModerator gm = new GroupModerator("moderator_ml" + i, "mod" + j);
moderators.add(gm);
}
pm.makePersistent(ml);
}
//creation of GeoRef
GeoRef g1 = new GeoRef("g1");
GeoRef g2 = new GeoRef("g2");
GeoRef g3 = new GeoRef("g3");
GeoRef g4 = new GeoRef("g4");
g2.setPreviousRef(g2);
g3.setPreviousRef(g4);
g4.setPreviousRef(g1);
pm.makePersistent(g1);
pm.makePersistent(g2);
pm.makePersistent(g3);
pm.makePersistent(g4);
pm.close();
}
public static List getUserNames() {
ArrayList res = new ArrayList();
for(int i=0; i<NB_GROUP; i++) {
for(int j=0; j<NB_USER_PER_GROUP; j++) {
res.add("user_g" + i + "_u" + j);
}
}
return res;
}
}