1 18 package org.objectweb.speedo.runtime.inheritance; 19 20 import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Article; 21 import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Catalogue; 22 import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Marche; 23 import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Service; 24 import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.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 java.util.Iterator ; 31 import java.util.Collection ; 32 33 37 public class TestRdbSequenceFilterOutOfPK extends SpeedoTestHelper { 38 39 public TestRdbSequenceFilterOutOfPK(String s) { 40 super(s); 41 } 42 43 protected String getLoggerName() { 44 return LOG_NAME + "rt.inheritance.TestRdbSequenceFilterOutOfPK"; 45 } 46 47 public void testA() { 48 final int NB_ARTICLE = 10; 49 final int CATLAOGUE_SIZE = 2; 50 final int MARCHE_SIZE = 2; 51 PersistenceManager pm = pmf.getPersistenceManager(); 52 pm.currentTransaction().begin(); 53 Catalogue cat = null; 54 int nbCat = 0; 55 Marche mar= null; 56 int nbMar = 0; 57 Article a; 58 for(int idArt=0; idArt<NB_ARTICLE; idArt++) { 59 if ((idArt / CATLAOGUE_SIZE) == nbCat) { 60 cat = new Catalogue(); 61 pm.makePersistent(cat); 62 nbCat ++; 63 } 64 if ((idArt / MARCHE_SIZE) == nbMar) { 65 mar = new Marche(); 66 pm.makePersistent(mar); 67 nbMar ++; 68 } 69 if ((idArt % 2) == 0) { a = new Service(idArt); 71 } else { a = new Materiel(idArt); 73 } 74 pm.makePersistent(a); 75 a.setCatalogue(cat); 76 mar.getArticles().add(a); 77 } 78 pm.currentTransaction().commit(); 79 80 a = null; 81 cat = null; 82 mar = null; 83 pm.evictAll(); 84 85 Extent extent = pm.getExtent(Catalogue.class, true); 86 Iterator it = extent.iterator(); 87 while(it.hasNext()) { 88 cat = (Catalogue) it.next(); 89 logger.log(BasicLevel.DEBUG, "Catalogue " + cat.getId()); 90 Collection arts = cat.getArticles(); 91 Iterator articles = arts.iterator(); 92 while(articles.hasNext()) { 93 a = (Article) articles.next(); 94 logger.log(BasicLevel.DEBUG, "\tArticle " + a.getId()); 95 Collection mars = a.getMarches(); 96 Iterator marches = mars.iterator(); 97 while (marches.hasNext()) { 98 mar = (Marche) marches.next(); 99 logger.log(BasicLevel.DEBUG, "\t\tMarche " + mar.getId()); 100 Collection m2as = mar.getArticles(); 101 assertTrue("The article '" + a.getId() 102 + "' is not in the collection marche(" + mar.getId() 103 + ").articles", m2as.contains(a)); 104 } 105 } 106 } 107 extent.closeAll(); 108 109 a = null; 110 cat = null; 111 mar = null; 112 pm.currentTransaction().begin(); 113 extent = pm.getExtent(Article.class, true); 114 it = extent.iterator(); 115 while (it.hasNext()) { 116 a = (Article) it.next(); 117 cat = a.getCatalogue(); 118 if (cat != null) { 119 pm.deletePersistent(cat); 120 } 121 pm.deletePersistentAll(a.getMarches()); 122 pm.deletePersistent(a); 123 } 124 pm.currentTransaction().commit(); 125 pm.close(); 126 } 127 } 128 | Popular Tags |