KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > inheritance > TestRdbSequenceFilterOutOfPK


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

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 JavaDoc;
31 import java.util.Collection JavaDoc;
32
33 /**
34  *
35  * @author S.Chassande-Barrioz
36  */

37 public class TestRdbSequenceFilterOutOfPK extends SpeedoTestHelper {
38
39     public TestRdbSequenceFilterOutOfPK(String JavaDoc s) {
40         super(s);
41     }
42
43     protected String JavaDoc 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) { //even
70
a = new Service(idArt);
71             } else { //uneven
72
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 JavaDoc it = extent.iterator();
87         while(it.hasNext()) {
88             cat = (Catalogue) it.next();
89             logger.log(BasicLevel.DEBUG, "Catalogue " + cat.getId());
90             Collection JavaDoc arts = cat.getArticles();
91             Iterator JavaDoc articles = arts.iterator();
92             while(articles.hasNext()) {
93                 a = (Article) articles.next();
94                 logger.log(BasicLevel.DEBUG, "\tArticle " + a.getId());
95                 Collection JavaDoc mars = a.getMarches();
96                 Iterator JavaDoc marches = mars.iterator();
97                 while (marches.hasNext()) {
98                     mar = (Marche) marches.next();
99                     logger.log(BasicLevel.DEBUG, "\t\tMarche " + mar.getId());
100                     Collection JavaDoc 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