001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.runtime.inheritance;
018:
019: import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Article;
020: import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Catalogue;
021: import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Marche;
022: import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Service;
023: import org.objectweb.speedo.pobjects.inheritance.filterOutOfPK.rdbsequence.Materiel;
024: import org.objectweb.speedo.SpeedoTestHelper;
025: import org.objectweb.util.monolog.api.BasicLevel;
026:
027: import javax.jdo.PersistenceManager;
028: import javax.jdo.Extent;
029: import java.util.Iterator;
030: import java.util.Collection;
031:
032: /**
033: *
034: * @author S.Chassande-Barrioz
035: */
036: public class TestRdbSequenceFilterOutOfPK extends SpeedoTestHelper {
037:
038: public TestRdbSequenceFilterOutOfPK(String s) {
039: super (s);
040: }
041:
042: protected String getLoggerName() {
043: return LOG_NAME + "rt.inheritance.TestRdbSequenceFilterOutOfPK";
044: }
045:
046: public void testA() {
047: final int NB_ARTICLE = 10;
048: final int CATLAOGUE_SIZE = 2;
049: final int MARCHE_SIZE = 2;
050: PersistenceManager pm = pmf.getPersistenceManager();
051: pm.currentTransaction().begin();
052: Catalogue cat = null;
053: int nbCat = 0;
054: Marche mar = null;
055: int nbMar = 0;
056: Article a;
057: for (int idArt = 0; idArt < NB_ARTICLE; idArt++) {
058: if ((idArt / CATLAOGUE_SIZE) == nbCat) {
059: cat = new Catalogue();
060: pm.makePersistent(cat);
061: nbCat++;
062: }
063: if ((idArt / MARCHE_SIZE) == nbMar) {
064: mar = new Marche();
065: pm.makePersistent(mar);
066: nbMar++;
067: }
068: if ((idArt % 2) == 0) { //even
069: a = new Service(idArt);
070: } else { //uneven
071: a = new Materiel(idArt);
072: }
073: pm.makePersistent(a);
074: a.setCatalogue(cat);
075: mar.getArticles().add(a);
076: }
077: pm.currentTransaction().commit();
078:
079: a = null;
080: cat = null;
081: mar = null;
082: pm.evictAll();
083:
084: Extent extent = pm.getExtent(Catalogue.class, true);
085: Iterator it = extent.iterator();
086: while (it.hasNext()) {
087: cat = (Catalogue) it.next();
088: logger.log(BasicLevel.DEBUG, "Catalogue " + cat.getId());
089: Collection arts = cat.getArticles();
090: Iterator articles = arts.iterator();
091: while (articles.hasNext()) {
092: a = (Article) articles.next();
093: logger.log(BasicLevel.DEBUG, "\tArticle " + a.getId());
094: Collection mars = a.getMarches();
095: Iterator marches = mars.iterator();
096: while (marches.hasNext()) {
097: mar = (Marche) marches.next();
098: logger.log(BasicLevel.DEBUG, "\t\tMarche "
099: + mar.getId());
100: Collection m2as = mar.getArticles();
101: assertTrue("The article '" + a.getId()
102: + "' is not in the collection marche("
103: + mar.getId() + ").articles", m2as
104: .contains(a));
105: }
106: }
107: }
108: extent.closeAll();
109:
110: a = null;
111: cat = null;
112: mar = null;
113: pm.currentTransaction().begin();
114: extent = pm.getExtent(Article.class, true);
115: it = extent.iterator();
116: while (it.hasNext()) {
117: a = (Article) it.next();
118: cat = a.getCatalogue();
119: if (cat != null) {
120: pm.deletePersistent(cat);
121: }
122: pm.deletePersistentAll(a.getMarches());
123: pm.deletePersistent(a);
124: }
125: pm.currentTransaction().commit();
126: pm.close();
127: }
128: }
|