1 18 package org.objectweb.speedo.runtime.inheritance; 19 20 import org.objectweb.speedo.pobjects.inheritance.ejboo.Article; 21 import org.objectweb.speedo.pobjects.inheritance.ejboo.Catalogue; 22 import org.objectweb.speedo.pobjects.inheritance.ejboo.Marche; 23 import org.objectweb.speedo.pobjects.inheritance.ejboo.Service; 24 import org.objectweb.speedo.pobjects.inheritance.ejboo.Materiel; 25 import org.objectweb.speedo.SpeedoTestHelper; 26 import org.objectweb.util.monolog.api.BasicLevel; 27 28 import javax.jdo.PersistenceManager; 29 import javax.jdo.Extent; 30 import javax.jdo.Query; 31 32 import java.util.ArrayList ; 33 import java.util.Collections ; 34 import java.util.Iterator ; 35 import java.util.Collection ; 36 37 41 public class TestEjboo extends SpeedoTestHelper { 42 43 public TestEjboo(String s) { 44 super(s); 45 } 46 47 protected String getLoggerName() { 48 return LOG_NAME + "rt.inheritance.TesEjboo"; 49 } 50 51 public void testA() { 52 final int NB_ARTICLE = 10; 53 final int CATLAOGUE_SIZE = 2; 54 final int MARCHE_SIZE = 2; 55 PersistenceManager pm = pmf.getPersistenceManager(); 56 pm.currentTransaction().begin(); 57 Catalogue cat = null; 58 int nbCat = 0; 59 Marche mar= null; 60 int nbMar = 0; 61 Article a; 62 for(int idArt=0; idArt<NB_ARTICLE; idArt++) { 63 if ((idArt / CATLAOGUE_SIZE) == nbCat) { 64 cat = new Catalogue(); 65 pm.makePersistent(cat); 66 nbCat ++; 67 } 68 if ((idArt / MARCHE_SIZE) == nbMar) { 69 mar = new Marche(); 70 pm.makePersistent(mar); 71 nbMar ++; 72 } 73 if ((idArt % 2) == 0) { a = new Service(idArt); 75 } else { a = new Materiel(idArt); 77 } 78 pm.makePersistent(a); 79 a.setCatalogue(cat); 80 mar.getArticles().add(a); 81 } 82 pm.currentTransaction().commit(); 83 84 a = null; 85 cat = null; 86 mar = null; 87 pm.evictAll(); 88 89 Article a2 = null; 90 91 Extent extent = pm.getExtent(Catalogue.class, true); 92 Iterator it = extent.iterator(); 93 while(it.hasNext()) { 94 cat = (Catalogue) it.next(); 95 logger.log(BasicLevel.DEBUG, "Catalogue " + cat.getId()); 96 Collection arts = cat.getArticles(); 97 Iterator articles = arts.iterator(); 98 while(articles.hasNext()) { 99 a2 = a; 100 a = (Article) articles.next(); 101 logger.log(BasicLevel.DEBUG, "\tArticle " + a.getId()); 102 Collection mars = a.getMarches(); 103 Iterator marches = mars.iterator(); 104 while (marches.hasNext()) { 105 mar = (Marche) marches.next(); 106 logger.log(BasicLevel.DEBUG, "\t\tMarche " + mar.getId()); 107 Collection m2as = mar.getArticles(); 108 assertTrue("The article '" + a.getId() 109 + "' is not in the collection marche(" + mar.getId() 110 + ").articles", m2as.contains(a)); 111 } 112 } 113 } 114 extent.closeAll(); 115 116 pm.currentTransaction().begin(); 117 Query q = pm.newQuery(Catalogue.class); 118 q.setResult("distinct this"); 119 q.setFilter("articles.contains(a) && a.marches.contains(m) && m.id==MID"); 120 q.declareParameters("long MID"); 121 q.declareVariables("Marche m;Article a"); 122 Collection c = (Collection ) q.execute(new Long (mar.getId())); 123 Collection expectedResults = Collections.singletonList(cat); 124 assertSameCollection("Collection of results is not the one expected", expectedResults, c); 125 q.closeAll(); 126 pm.currentTransaction().commit(); 127 128 a = null; 129 cat = null; 130 mar = null; 131 pm.currentTransaction().begin(); 132 extent = pm.getExtent(Article.class, true); 133 it = extent.iterator(); 134 while (it.hasNext()) { 135 a = (Article) it.next(); 136 cat = a.getCatalogue(); 137 if (cat != null) { 138 pm.deletePersistent(cat); 139 } 140 pm.deletePersistentAll(a.getMarches()); 141 pm.deletePersistent(a); 142 } 143 pm.currentTransaction().commit(); 144 pm.close(); 145 } 146 } 147 | Popular Tags |