Package org.objectweb.speedo.pobjects.relations.ni_ejboo

Examples of org.objectweb.speedo.pobjects.relations.ni_ejboo.Article


        pm.currentTransaction().begin();
        Catalogue cat = null;
        int nbCat = 0;
        Marche mar= null;
        int nbMar = 0;
        Article a;
        for(int idArt=0; idArt<NB_ARTICLE; idArt++) {
            if ((idArt / CATLAOGUE_SIZE) == nbCat) {
                cat = new Catalogue();
                pm.makePersistent(cat);
                nbCat ++;
            }
            if ((idArt / MARCHE_SIZE) == nbMar) {
                mar = new Marche();
                pm.makePersistent(mar);
                nbMar ++;
            }
            a = new Article(idArt);
            pm.makePersistent(a);
            a.setCatalogue(cat);
            mar.getArticles().add(a);
        }
        pm.currentTransaction().commit();

        a = null;
        cat = null;
        mar = null;
        pm.evictAll();

        Extent extent = pm.getExtent(Catalogue.class, true);
        Iterator it = extent.iterator();
        while(it.hasNext()) {
            cat = (Catalogue) it.next();
            logger.log(BasicLevel.DEBUG, "Catalogue " + cat.getId());
            Collection arts = cat.getArticles();
            Iterator articles = arts.iterator();
            while(articles.hasNext()) {
                a = (Article) articles.next();
                logger.log(BasicLevel.DEBUG, "\tArticle " + a.getId());
                Collection mars = a.getMarches();
                Iterator marches = mars.iterator();
                while (marches.hasNext()) {
                    mar = (Marche) marches.next();
                    logger.log(BasicLevel.DEBUG, "\t\tMarche " + mar.getId());
                    Collection m2as = mar.getArticles();
                    assertTrue("The article '" + a.getId()
                        + "' is not in the collection marche(" + mar.getId()
                        + ").articles", m2as.contains(a));
                }
            }
        }
        extent.closeAll();

        pm.currentTransaction().begin();
        Query q = pm.newQuery(Catalogue.class);
        q.setResult("distinct this");
        q.setFilter("articles.contains(a) && a.marches.contains(m) && m.id==MID");
        q.declareParameters("long MID");
        q.declareVariables("Marche m;Article a");
        Collection c = (Collection) q.execute(new Long(mar.getId()));
        Collection expectedResults = Collections.singletonList(cat);
        assertSameCollection("Collection of results is not the one expected", expectedResults, c);
        q.closeAll();
        pm.currentTransaction().commit();
       
        a = null;
        cat = null;
        mar = null;
        pm.currentTransaction().begin();
        extent = pm.getExtent(Article.class, true);
        it = extent.iterator();
        while (it.hasNext()) {
            a = (Article) it.next();
            cat = a.getCatalogue();
            if (cat != null) {
                pm.deletePersistent(cat);
            }
            pm.deletePersistentAll(a.getMarches());
            pm.deletePersistent(a);
        }
        pm.currentTransaction().commit();
        pm.close();
    }   
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.relations.ni_ejboo.Article

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.