Package javax.jdo

Examples of javax.jdo.Extent


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

    pm.currentTransaction().begin();
    Extent extent = pm.getExtent(CataloguePersistantImpl.class, true);
    Iterator it = extent.iterator();
    ArrayList errors = new ArrayList();
    while(it.hasNext()) {
      cat = (CataloguePersistantImpl) it.next();
      logger.log(BasicLevel.DEBUG, "Catalogue " + cat.getId());
      Collection arts = cat.getArticles();
      Iterator articles = arts.iterator();
      while(articles.hasNext()) {
        a = (ArticlePersistantImpl) articles.next();
        logger.log(BasicLevel.DEBUG, "\tArticle " + a.getId());
        Collection mars = a.getMarches();
        Iterator marches = mars.iterator();
        while (marches.hasNext()) {
          mar = (MarchePersistantImpl) marches.next();
          logger.log(BasicLevel.DEBUG, "\t\tMarche " + mar.getId());
          Collection m2as = mar.getArticles();
          if (!m2as.contains(a)) {
              errors.add(new Exception("The article '" + a.getId()
            + "' is not in the collection marche(" + mar.getId()
            + ").articles"));
          }
        }
      }
    }
    extent.closeAll();
    pm.currentTransaction().commit();
    if (!errors.isEmpty()) {
        for (Iterator iter = errors.iterator(); iter.hasNext();) {
                Exception e = (Exception) iter.next();
                logger.log(BasicLevel.ERROR, e.getMessage());
            }
        fail(errors.size() + " error(s)");
    }
    a = null;
    mar = null;

    pm.currentTransaction().begin();
    Query query = pm.newQuery(ArticlePersistantImpl.class);
        query.declareParameters("String p1,CataloguePersistantImpl p2");
        query.setFilter("(nom.startsWith(p1) && (catalogue == p2))");
        query.setResult("count(*)");
    query.setUnique(true);
    query.setRange(0,2);
        Long l = (Long) query.executeWithArray(new Object[] { "article", cat });
        assertTrue("", l.longValue() > 0);
        query.closeAll();
    pm.currentTransaction().commit();
   
    pm.currentTransaction().begin();
    query = pm.newQuery(ArticlePersistantImpl.class);
        query.declareParameters("String p1,CataloguePersistantImpl p2");
        query.setFilter("(nom.startsWith(p1) && (catalogue == p2))");
        query.setResult("count(*)");
    query.setUnique(true);
    query.setRange(0,5);
        l = (Long) query.executeWithArray(new Object[] { "article", cat });
        query.closeAll();
        assertTrue("", l.longValue() > 0);
        pm.currentTransaction().commit();

    pm.currentTransaction().begin();
    query = pm.newQuery(ArticlePersistantImpl.class);
    query.setRange(0,2);
    new ArrayList((Collection) query.execute());
        query.closeAll();
        pm.currentTransaction().commit();
   
    cat = null;
   
    pm.currentTransaction().begin();
    extent = pm.getExtent(ArticlePersistantImpl.class, true);
    it = extent.iterator();
    while (it.hasNext()) {
      a = (ArticlePersistantImpl) it.next();
      cat = a.getCatalogue();
      if (cat != null) {
        pm.deletePersistent(cat);
View Full Code Here


  private void checkNumberOfInstanceWithExtent(Class clazz,
                         boolean withSubClass,
                         int expected,
                         PersistenceManager pm) {
    Extent e = pm.getExtent(clazz, withSubClass);
    Iterator it = e.iterator();
    int cpt = 0;
    ArrayList rfs = new ArrayList(expected);
    while(it.hasNext()) {
      rfs.add(((RootClass) it.next()).getRootField());
      cpt ++;
    }
    e.closeAll();
    assertEquals("Bad number of " + clazz.getName()
      + " instance (withSubclass: " + withSubClass + "): rfs=" + rfs,
      expected, cpt);
  }
View Full Code Here

    mar = null;
    pm.evictAll();

    Article a2 = null;
   
    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()) {
        a2 = a;
        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);
View Full Code Here

   * extent
   */
  public void computeExtent(Class cl, boolean withSubclasses) {
    PersistenceManager pm = pmf.getPersistenceManager();
    try {
      Extent extent = pm.getExtent(cl, withSubclasses);
      Iterator it = extent.iterator();
      while(it.hasNext()) {
        Mother m = (Mother) it.next();
        assertTrue(m.getJava1()>0);
      }
    } catch (Exception e) {
View Full Code Here

  private boolean doPersistentInstancesExist()
  {
    boolean ret;
    Transaction t = pm.currentTransaction();
    t.begin();
    Extent e = pm.getExtent(StateTransitionObj.class, false);
    Iterator iter = e.iterator();
    ret = iter.hasNext();
    t.rollback();
    return ret;
  }
View Full Code Here

    return obj;
  }

  public StateTransitionObj getHollowInstance()
  {
    Extent extent = pm.getExtent(StateTransitionObj.class, false);
    Iterator iter = extent.iterator();
    if( !iter.hasNext() ){
      logger.log(BasicLevel.INFO, "Extent for StateTransitionObj should not be empty");
      return null;
    }
    StateTransitionObj obj = (StateTransitionObj) iter.next();
View Full Code Here

      }     
      pm.close();
    }
    pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    Extent e = pm.getExtent(BasicA.class);
    for(Iterator it = e.iterator(); it.hasNext();) {
      pm.deletePersistent(it.next());
    }
    pm.currentTransaction().commit();
    pm.close();
 
View Full Code Here

  }
 
  private void autoClean(PersistenceManager pm, Class[] classes) {
    pm.currentTransaction().begin();
    for(int i=0; i<classes.length; i++) {
      Extent extent = pm.getExtent(classes[i], false);
      for(Iterator it = extent.iterator(); it.hasNext();) {
          pm.deletePersistent(it.next());
      }
      extent.closeAll();
    }
    pm.currentTransaction().commit();
  }
View Full Code Here

  }
 
  protected int deleteAllInstances(Class clazz) {
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    Extent e = pm.getExtent(clazz, true);
    Iterator it = e.iterator();
    int i = 0;
    while(it.hasNext()) {
        pm.deletePersistent(it.next());
        i++;
    }
    e.closeAll();
    pm.currentTransaction().commit();
    pm.close();
    logger.log(BasicLevel.DEBUG, "Delete " + i + " instance(s) of the class " + clazz.getName());
    return i;
  }
View Full Code Here

        attributeOpCausingExceptions = new ArrayList();
    }   

    static void removeAllInstances(PersistenceManager pm)
    {
        Extent e = pm.getExtent(org.objectweb.speedo.pobjects.tck.InstanceCallbackNonPersistFdsClass.class, true);
        Iterator it = e.iterator();
        while( it.hasNext() ){
            pm.deletePersistent(it.next());
        }       
    }
View Full Code Here

TOP

Related Classes of javax.jdo.Extent

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.