1 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 ; 46 import java.util.ArrayList ; 47 48 51 public class POBuilder extends SpeedoTestHelper { 52 53 public final static String depName = "RD"; 54 public final static String [] depNames = { "MAPS", "BIZZ", "TECK"}; 55 public final static String [] 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 name) { 64 super(name); 65 } 66 67 protected String 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 for(int i=0; i<names.length; i++) { 81 pm.makePersistent(new Employee(names[i], d, salaries[i])); 82 } 83 84 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 as0 = new ArrayList (2); 96 as0.add(bs[0]); 97 as0.add(bs[1]); 98 as[0].setBs(as0); 99 Collection as1 = new ArrayList (3); 100 as1.add(bs[0]); 101 as1.add(bs[1]); 102 as1.add(bs[2]); 103 as[1].setBs(as1); 104 Collection as2 = new ArrayList (2); 105 as2.add(bs[1]); 106 as2.add(bs[2]); 107 as[2].setBs(as2); 108 109 Collection bs0 = new ArrayList (2); 110 bs0.add(as[0]); 111 bs0.add(as[1]); 112 bs[0].setAs(bs0); 113 Collection bs1 = new ArrayList (3); 114 bs1.add(as[0]); 115 bs1.add(as[1]); 116 bs1.add(as[2]); 117 bs[1].setAs(bs1); 118 Collection bs2 = new ArrayList (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 for(int i=0; i<NB_GROUP; i++) { 127 Group g = new Group("group_" + i); 128 Collection 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 for(int i=0; i<NB_GROUP; i++) { 138 MailingList ml = new MailingList("mailinglist_" + i); 139 Collection 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 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 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 |