Package javax.jdo

Examples of javax.jdo.Extent


      logger.log(BasicLevel.ERROR, "Error the koala fetching:",
        ExceptionHelper.getNested(e));
      fail("koala not found");
    }

    Extent extent = pm.getExtent(Animal.class, true);
    Iterator it = extent.iterator();
    int i = 0;
    while(it.hasNext()) {
      i += ((Animal) it.next()).retrieveSize();
    }
    assertEquals("Bad Sum control", sum, i);
    extent.closeAll();

    Query q = pm.newQuery(Animal.class);
    q.declareParameters("int min, int max");
    q.setFilter("((size > min) && (size < max))");
    Collection col = (Collection) q.execute(
      new Integer(NB_ANIMAL / 2), new Integer(NB_ANIMAL));
    for(Iterator it2 = col.iterator(); it2.hasNext();) {
      a = it2.next();
      assertNotNull("Null AnAnimal", a);
      assertTrue("Bad type", a instanceof Animal);
      int s = ((Animal) a).retrieveSize();
      assertTrue("Animal size (" + s +") is not greater than " + (NB_ANIMAL /2), s > (NB_ANIMAL /2));
      assertTrue("Animal size (" + s +") is not lesser than " + NB_ANIMAL, s < NB_ANIMAL);
    }
    assertEquals("Bad query size", NB_ANIMAL -2, col.size());
    q.closeAll();

    q = pm.newQuery(Kangaroo.class);
    q.declareParameters("int min, int max");
    q.setFilter("((size > min) && (size < max))");
    col = (Collection) q.execute(
      new Integer(NB_ANIMAL / 2), new Integer(NB_ANIMAL));
    for(Iterator it2 = col.iterator(); it2.hasNext();) {
      a = it2.next();
      assertNotNull("Null AnAnimal", a);
      assertTrue("Bad type", a instanceof Kangaroo);
      int s = ((Kangaroo) a).retrieveSize();
      assertTrue("Not greater than " + (NB_ANIMAL /2), s > (NB_ANIMAL /2));
      assertTrue("Not lesser than " + NB_ANIMAL, s < NB_ANIMAL);
    }
    assertEquals("Bad query size", (NB_ANIMAL / 2) - 1 , col.size());
    q.closeAll();


    pm.currentTransaction().begin();
    extent = pm.getExtent(Animal.class, true);
    it = extent.iterator();
    while (it.hasNext()) {
      pm.deletePersistent(it.next());
    }
    pm.deletePersistent(zoo);
    pm.currentTransaction().commit();
    extent.closeAll();
    pm.close();
  }
View Full Code Here


  }

  public void testA() {
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    Extent ex = pm.getExtent(Azerty.class, false);
    Iterator it = ex.iterator();
    while(it.hasNext()) {     
      pm.deletePersistent(it.next());     
    }
    ex = pm.getExtent(Qsdfgh.class, false);
    it = ex.iterator();
    while(it.hasNext()) {
     
      pm.deletePersistent(it.next());
     
    }
View Full Code Here

    logger.log(BasicLevel.DEBUG, "make persistent the team " + t.toString());
    pm.makePersistent(t);
    pm.currentTransaction().commit();
   
    try {
        Extent extent = pm.getExtent(Team.class, false);
        Query query = pm.newQuery(extent, "town == townName");
        query.declareParameters("String townName");
        Collection collection = (Collection) query.execute(t.getTown());
        assertTrue("The result should not be empty", !collection.isEmpty());
        Iterator itr = collection.iterator();
        Team copyOfT = null;
        while (itr.hasNext()) {
          Team team = (Team) itr.next();
          assertEquals("The town should be " + t.getTown(), t.getTown(), team.getTown());
          //detach the team t
          copyOfT = (Team) pm.detachCopy(team);
        }
        query.close(collection);
        extent.closeAll();
      assertNotNull(copyOfT);
      assertEquals("Town of team and detached team are not the same", t.getTown(), copyOfT.getTown());
      assertNull("The coach reference is supposed to be null", copyOfT.getCoach());
    } catch (Exception e) {
      fail(e.getMessage());
View Full Code Here

  //iterate over all the instances of a class
  public void iterateExtent(Class cl){
    PersistenceManager pm = pmf.getPersistenceManager();
    try {
      pm.currentTransaction().begin();
      Extent extent = pm.getExtent(cl, true);
      Iterator it = extent.iterator();
      String className = cl.getName().substring(cl.getName().lastIndexOf("."));
      logger.log(BasicLevel.DEBUG, "All " + cl.getName() + " instances:");
      while(it.hasNext()){
        Form f = (Form) it.next();
        assertNotNull("The form should not be null", f);
        //logger.log(BasicLevel.DEBUG, f.toString());
      }
      extent.close(it);
      pm.currentTransaction().commit();
    } catch (Exception e) {
      fail(e.getMessage());
    } finally {
      if (pm.currentTransaction().isActive())
View Full Code Here

        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);
View Full Code Here

        pm.currentTransaction().commit();
  }

  //iterate over all the instances of a class
  public void iterateExtent(PersistenceManager pm, Class cl){
    Extent extent = pm.getExtent(cl, true);
        Iterator it = extent.iterator();
        String className = cl.getName().substring(cl.getName().lastIndexOf("."));
        logger.log(BasicLevel.DEBUG, "All " + cl.getName() + " instances:");
        while(it.hasNext()){
          Employee e = (Employee) it.next();
          assertNotNull(e);
          logger.log(BasicLevel.DEBUG, e.toString());
        }
        extent.close(it);
  }
View Full Code Here

    public void testExtent(Class clazz, boolean withSubclass, Collection ids) {
        logger.log(BasicLevel.DEBUG, "testExtent_" + clazz.getName() + "_sc=" + withSubclass);
        PersistenceManager pm = pmf.getPersistenceManager();
    try {
            Extent e = pm.getExtent(clazz, withSubclass);
            Assert.assertEquals("Bad candidate class on the extent",
                    clazz, e.getCandidateClass());
            Assert.assertEquals("Bad sub class value on the extent",
                    withSubclass, e.hasSubclasses());
            Iterator it = e.iterator();
            ArrayList found = new ArrayList(ids.size());
            while(it.hasNext()) {
                Object o = it.next();
                if (o == null) {
                    fail("Null object returned by the extent iterator of the class "
                            + clazz.getName());
                } else if (o instanceof AMMB) {
                    AMMB a = (AMMB) o;
                    found.add(new Long(a.getIda()));
                } else if (o instanceof BMMB) {
                    BMMB b = (BMMB) o;
                    found.add(new Long(b.getIdb()));
                } else {
                    fail("the test does not manage the class " + o.getClass().getName());
                }
            }
            try {
                it.remove();
                fail("the remove operation does not throw an exception");
            } catch (UnsupportedOperationException e1) {
            }
            assertSameCollection("Bad extent of the class " + clazz.getName(), ids, found);
            e.close(it);
            try {
                it.hasNext();
                fail("the iterator does not throw an exception on the use of " +
                        "the 'hasNext' method whereas it has been closed");
            } catch (NoSuchElementException e1) {
            }
            try {
                it.next();
                fail("the iterator does not throw an exception on the use of " +
                        "the 'next' method whereas it has been closed");
            } catch (NoSuchElementException e1) {
            }
            e = pm.getExtent(clazz, withSubclass);
            Iterator[] its = new Iterator[5];
            for(int i=0; i<its.length; i++) {
                its[i] = e.iterator();
            }
            e.closeAll();
            for(int i=0; i<its.length; i++) {
                try {
                    its[i].next();
                    fail("the iterator " + i +" does not throw an exception on "
                            + "the use of the 'next' method whereas all"
                            + " iterator have been closed");
                } catch (NoSuchElementException e1) {
                }
            }
            it = e.iterator();
            for(int i=0; i<ids.size(); i++) {
                try {
                    it.next();
                } catch (NoSuchElementException e1) {
                    Assert.assertEquals("Bad size: ", ids.size(), i);
                }
            }
            e.close(it);
    } catch (Exception e) {
      Exception ie = ExceptionHelper.getNested(e);
      logger.log(BasicLevel.ERROR, "", ie);
      fail(ie.getMessage());
    } finally {
View Full Code Here

        Class clazz = AMMB.class;
        boolean withSubclass = false;
        logger.log(BasicLevel.DEBUG, "testExtent_" + clazz.getName() + "_sc=" + withSubclass);
        PersistenceManager pm = pmf.getPersistenceManager();
        try {
            Extent e = pm.getExtent(clazz, false);
            Query q = pm.newQuery(e);
            Collection c = (Collection) q.execute();
            Assert.assertEquals("bad size", POBuilder.NB_XMMB, c.size());
            q.close(c);
        } catch (Exception e) {
View Full Code Here

            p = (Product) query.execute(id + "bis"); //query
            assertNotNull("Null value for " + id + "bis", p);
            pm.currentTransaction().commit();

            pm.currentTransaction().begin();
            Extent e = pm.getExtent(Product.class);
            for (Iterator iter = e.iterator(); iter.hasNext();) {
                pm.deletePersistent(iter.next());
            }
            pm.currentTransaction().commit();
        } catch (JDOException e) {
            Exception ie = ExceptionHelper.getNested(e);
View Full Code Here

            pm.makePersistent(geoRef);
        }
        pm.currentTransaction().commit();
        try {
            pm.currentTransaction().begin();
            Extent e = pm.getExtent(Litem.class, true);//with subclasses
            Query query = pm.newQuery(e);
            query.setFilter("name == id");
            query.declareParameters("String id");
            query.setUnique(true);
            final String id = n + 3;
            Litem litem = (Litem) query.execute(id);//no query
            assertNotNull("Null value for " + id, litem);
            litem.setName(id + "bis");

            //Check that the old value is unbound
            litem = (Litem) query.execute(id);//query
            assertNull("Old value not unbound from the user cache, " + id, litem);

            litem = (Litem) query.execute(id + "bis");//query
            assertNotNull("Null value for " + id + "bis", litem);

            litem = (Litem) query.execute(n + 10);//query
            assertNull("Non null value for " + n + 10, litem);
            pm.currentTransaction().commit();
           
            pm.evictAll();

            pm.currentTransaction().begin();
            litem = (Litem) query.execute(id + "bis"); //query
            assertNotNull("Null value for " + id + "bis", litem);
            pm.currentTransaction().commit();

            pm.currentTransaction().begin();
            String myId = n+1;
            litem = (Litem) query.execute(myId);//no query
            assertNotNull("Null value for " + myId, litem);
            litem = (Litem) query.execute(myId);//no query
            assertNotNull("Null value for " + myId, litem);
            pm.currentTransaction().commit();
           
            pm.currentTransaction().begin();
            e = pm.getExtent(Litem.class, true);
            for (Iterator iter = e.iterator(); iter.hasNext();) {
                pm.deletePersistent(iter.next());
            }
            pm.currentTransaction().commit();
        } catch (JDOException e) {
            Exception ie = ExceptionHelper.getNested(e);
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.