Package org.objectweb.speedo.pobjects.detach.groupama

Examples of org.objectweb.speedo.pobjects.detach.groupama.DomaineHelper


    zg1.setConvention(convention1);
    convention1.addZoneGeographique(zg2);
    zg2.setConvention(convention2);
   
    //create a domaine
    DomaineHelper domaine1 = new DomaineHelper();
    domaine1.setCdmed(1);
    domaine1.setLimed(1);
   
    SpecialiteMercureHelper specialiteMercure1 = new SpecialiteMercureHelper();
    specialiteMercure1.setCdmec(1);
    specialiteMercure1.setCdmed(1);
    specialiteMercure1.setCdmese(1);
    // spcecialiteMercure * <-> 1 domaine
    specialiteMercure1.setDomaine(domaine1);
    domaine1.addSpecialiteMercure(specialiteMercure1);
    // spcecialiteMercure 1 <-> * convention
    specialiteMercure1.addConvention(convention1);
    convention1.setSpecialiteMercure(specialiteMercure1);
   
    SpecialiteMercureHelper specialiteMercure2 = new SpecialiteMercureHelper();
    specialiteMercure1.setCdmec(2);
    specialiteMercure1.setCdmed(1);
    specialiteMercure1.setCdmese(2);
    // spcecialiteMercure * <-> 1 domaine
    specialiteMercure2.setDomaine(domaine1);
    domaine1.addSpecialiteMercure(specialiteMercure2);
    // spcecialiteMercure 1 <-> * convention
    specialiteMercure2.addConvention(convention2);
    convention2.setSpecialiteMercure(specialiteMercure2);
   
    PersistenceManager pm = pmf.getPersistenceManager();
   
    try {
      pm.currentTransaction().begin();
      logger.log(BasicLevel.DEBUG, "make persistent the 2 conventions");
      pm.makePersistent(convention1);
      pm.makePersistent(convention2);
     
      pm.currentTransaction().commit();
   
      //set the fetch group to listeIntervenants
      FetchPlan fp = pm.getFetchPlan();
      fp.clearGroups().addGroup("listeIntervenants");
      //detach the  intervenant
      IntervenantHelper copyOfIntervenant1 = (IntervenantHelper) pm.detachCopy(intervenant1);
      assertNotNull(copyOfIntervenant1);
      assertEquals("Nomep of intervenant1 and its detached copy are not the same.", intervenant1.getNomep(), copyOfIntervenant1.getNomep());
      Collection conv = intervenant1.getConventions();
      Collection copyConv = copyOfIntervenant1.getConventions();
      assertEquals("Size of conventions not the same for intervenant1 and its detached copy.", conv.size(), copyConv.size());
      Iterator itConv = conv.iterator();
      Iterator itCopyConv = copyConv.iterator();
      while (itConv.hasNext() && itCopyConv.hasNext()) {
        ConventionHelper convention = (ConventionHelper) itConv.next();
        ConventionHelper copyConvention = (ConventionHelper) itCopyConv.next();
        assertEquals("cdmem is not the same for the convention and its detached copy", convention.getCdmem(), copyConvention.getCdmem());
        assertEquals("nomep is not the same for the convention and its detached copy", convention.getNomep(), copyConvention.getNomep());
        SpecialiteMercureHelper specialiteMercure = convention.getSpecialiteMercure();
        SpecialiteMercureHelper copySpecialiteMercure = copyConvention.getSpecialiteMercure();
            assertEquals("cdmed not the same for the specialiteMercure and its detached copy", specialiteMercure.getCdmed(), copySpecialiteMercure.getCdmed());
            assertEquals("cdmec not the same for the specialiteMercure and its detached copy", specialiteMercure.getCdmec(), copySpecialiteMercure.getCdmec());
            assertEquals("cdmese not the same for the specialiteMercure and its detached copy", specialiteMercure.getCdmese(), copySpecialiteMercure.getCdmese());
            DomaineHelper domaine = specialiteMercure.getDomaine();
            DomaineHelper copyDomaine = copySpecialiteMercure.getDomaine();
            assertEquals("cdmed not the same for the domaine and its detached copy", domaine.getCdmed(), copyDomaine.getCdmed());
            assertEquals("limed not the same for the domaine and its detached copy", domaine.getLimed(), copyDomaine.getLimed());
            MarqueHelper marque = convention.getMarque();
        MarqueHelper copyMarque = copyConvention.getMarque();
        assertEquals("cdmem is not the same for the marque and its detached copy", marque.getCdmem(), copyMarque.getCdmem());
        assertEquals("limem is not the same for the marque and its detached copy", marque.getLimem(), copyMarque.getLimem());
      }
     
      //query
        Query query = pm.newQuery(ConventionHelper.class);
        StringBuffer filter = new StringBuffer();
        filter.append("(intervenant.nomep == (\"" +
                         intervenant1.getNomep() + "\")) && ");
        filter.append("(cdmem == (\"" + marque1.getCdmem() + "\"))");
          query.setFilter(filter.toString());
          //fetchplan
        fp = pm.getFetchPlan().clearGroups();
        fp.addGroup("listeConventions");
        //execute
        Collection results = (Collection) query.execute();
        //detach all the conventions retrieved
        Collection detachedConv = pm.detachCopyAll(results);
        Iterator itDC = detachedConv.iterator();
        while (itDC.hasNext()) {
          ConventionHelper dConv = (ConventionHelper) itDC.next();
            Collection zonesGeo = dConv.getZoneGeographiques();
            assertEquals("Size of zoneGeo for convention1 and its detached copy si not the same.", convention1.getZoneGeographiques().size(), zonesGeo.size());
            Iterator itZg = zonesGeo.iterator();
            while (itZg.hasNext()) {
              ZoneGeographiqueHelper zoneGeo = (ZoneGeographiqueHelper) itZg.next();
              assertNotNull("Commune null for zoneGeo " + zoneGeo.getId() + ".", zoneGeo.getCommune());
              logger.log(BasicLevel.DEBUG, "Commune of zg" + zoneGeo.getId() + ": " + zoneGeo.getCommune().getDummy());
            }
            SpecialiteMercureHelper dSpecialiteMercure = dConv.getSpecialiteMercure();
            assertEquals("cdmed not the same for the specialiteMercure and its detached copy", specialiteMercure1.getCdmed(), dSpecialiteMercure.getCdmed());
            assertEquals("cdmec not the same for the specialiteMercure and its detached copy", specialiteMercure1.getCdmec(), dSpecialiteMercure.getCdmec());
            assertEquals("cdmese not the same for the specialiteMercure and its detached copy", specialiteMercure1.getCdmese(), dSpecialiteMercure.getCdmese());
            DomaineHelper dDomaine = dSpecialiteMercure.getDomaine();
            assertEquals("cdmed not the same for the domaine and its detached copy", domaine1.getCdmed(), dDomaine.getCdmed());
            assertEquals("limed not the same for the domaine and its detached copy", domaine1.getLimed(), dDomaine.getLimed());
        }
        query.closeAll();
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.detach.groupama.DomaineHelper

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.