Package org.objectweb.speedo.pobjects.collection

Examples of org.objectweb.speedo.pobjects.collection.AllCollection


      res.beginTest();
      // Execute first transaction on persistent Collections
      beginTx(pm, task, threadId, txId);
      long[] ls = new long[]{oids, oids + 1, oids + 2, oids + 3, oids + 4, oids + 5};
      long[] reverse = new long[]{oids + 5, oids + 4, oids + 3, oids + 2, oids + 1, oids};
      AllCollection ac = new AllCollection("stressCollection" + nbBeginTest);
      ac.setLongs(ls);
      ac.setRefs(new Object[]{ac});
      pm.makePersistent(ac);
      commitTx(pm, task, threadId, txId);

      // Reverse the data
      ac.setLongs(reverse);
      ac.setRefs(new Object[]{ac});

      // Verify result
      List expectedLong = new ArrayList(reverse.length);
      for (int i = 0; i < reverse.length; i++) {
        expectedLong.add(new Long(reverse[i]));
      }

      List expectedRef = new ArrayList(1);
      expectedRef.add(ac);

      //Collection
      Assert.assertNotNull("The collection of Long is null", ac.getCol_Long());
      assertSameCollection("The collection of Long", expectedLong, ac.getCol_Long());
      Assert.assertNotNull("The collection of reference is null", ac.getCol_ref());
      assertSameCollection("The collection of ref", expectedRef, ac.getCol_ref());

      //HashSet
      Assert.assertNotNull("The Hashset of Long is null", ac.getHset_Long());
      assertSameCollection("The Hashset of Long", expectedLong, ac.getHset_Long());
      Assert.assertNotNull("The Hashset of reference is null", ac.getHset_ref());
      assertSameCollection("The Hashset of ref", expectedRef, ac.getHset_ref());

      //List
      Assert.assertNotNull("The list of Long is null", ac.getList_Long());
      assertSameList("The list of Long", expectedLong, ac.getList_Long());
      Assert.assertNotNull("The list of reference is null", ac.getList_ref());
      assertSameList("The list of reference", expectedRef, ac.getList_ref());

      //Set
      Assert.assertNotNull("The set of Long is null", ac.getSet_Long());
      assertSameCollection("The set of Long", expectedLong, ac.getSet_Long());
      Assert.assertNotNull("The set of reference is null", ac.getSet_ref());
      assertSameCollection("The set of ref", expectedRef, ac.getSet_ref());

      // Execute second transaction on persistent Collections
      beginTx(pm, task, threadId, txId);
      logger.log(BasicLevel.DEBUG, ac.getId() + " is being deleted");
      pm.deletePersistent(ac);
      commitTx(pm, task, threadId, txId);
      res.endTest();
     
    } catch (JDOFatalException e) {
View Full Code Here


    int nbTx = task.txToExecute.length;
    PersistenceManager pm = getPM(task, threadId, txId);
    try {
      res.beginTest();
      beginTx(pm, task, threadId, txId);
      AllCollection ac=null;     
     
      if (plus > 0) {
        //The first transaction creates the additional object
        for (int oid = 0; txId == 0 && oid < plus; oid++) {
          long oids = (oid * 6);
          //long[] ls = new long[]{oids, oids + 1, oids + 2, oids + 3, oids + 4, oids + 5};
          long[] ls = new long[]{oids, oids + 1};
          ac = new AllCollection("stressCollection" + oid);
          ac.setLongs(ls);
          ac.setRefs(new Object[]{ac});
          logger.log(BasicLevel.DEBUG, "make persistent ac="+ac.getId());
          pm.makePersistent(ac);
          if (pctx.keepOidOnPrepare) {
            pctx.oids[oid] = pm.getObjectId(ac);
          }
        }           
      }
      // The other transactions create 'nbCreation' objects
      for (int no = 0; no < NB_CREATION; no++) {
        int oid = (txId * NB_CREATION) + no + plus;
        if (oid < pctx.dbSize) {
          long oids = (oid * 6);
          //long[] ls = new long[]{oids, oids + 1, oids + 2, oids + 3, oids + 4, oids + 5};
          long[] ls = new long[]{oids, oids + 1};
          ac = new AllCollection("stressCollection" + oid);
          ac.setLongs(ls);
          ac.setRefs(new Object[]{ac});
          logger.log(BasicLevel.DEBUG, "make persistent ac="+ac.getId());
          pm.makePersistent(ac);         
          if (pctx.keepOidOnPrepare) {
            pctx.oids[oid] = pm.getObjectId(ac);
          }
        }
View Full Code Here

           
      long[] reverse = new long[]{_oids + 5, _oids + 4, _oids + 3, _oids + 2, _oids + 1, _oids};
      // Reverse a persistent Collections at random
      int oid = Alea.rand(0, acctx.dbSize - 1);
      beginTx(pm, task, threadId, txId);
      AllCollection ac = (AllCollection) pm.getObjectById(acctx.oids[oid], false);
     
      // Reverse the data
      logger.log(BasicLevel.DEBUG, "reverse data of "+ac.getId());
      ac.setLongs(reverse);
      ac.setRefs(new Object[]{ac});
     
     
      // Verify result
      List expectedLong = new ArrayList(reverse.length);
      for (int i = 0; i < reverse.length; i++) {
        expectedLong.add(new Long(reverse[i]));
      }

      List expectedRef = new ArrayList(1);
      expectedRef.add(ac);

      //Collection
      Assert.assertNotNull("The collection of Long is null", ac.getCol_Long());
      assertSameCollection("The collection of Long", expectedLong, ac.getCol_Long());
      Assert.assertNotNull("The collection of reference is null", ac.getCol_ref());
      assertSameCollection("The collection of ref", expectedRef, ac.getCol_ref());

      //HashSet
      Assert.assertNotNull("The Hashset of Long is null", ac.getHset_Long());
      assertSameCollection("The Hashset of Long", expectedLong, ac.getHset_Long());
      Assert.assertNotNull("The Hashset of reference is null", ac.getHset_ref());
      assertSameCollection("The Hashset of ref", expectedRef, ac.getHset_ref());

      //List
      Assert.assertNotNull("The list of Long is null", ac.getList_Long());
      assertSameList("The list of Long", expectedLong, ac.getList_Long());
      Assert.assertNotNull("The list of reference is null", ac.getList_ref());
      assertSameList("The list of reference", expectedRef, ac.getList_ref());

      //Set
      Assert.assertNotNull("The set of Long is null", ac.getSet_Long());
      assertSameCollection("The set of Long", expectedLong, ac.getSet_Long());
      Assert.assertNotNull("The set of reference is null", ac.getSet_ref());
      assertSameCollection("The set of ref", expectedRef, ac.getSet_ref());
     
      commitTx(pm, task, threadId, txId);

      res.endTest();
    } catch (JDOFatalException e) {
View Full Code Here

  }

    public void testNullCollection() {
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        AllCollection ac = new AllCollection("testNullCollection");
        pm.makePersistent(ac);
        Object oid = pm.getObjectId(ac);
        Assert.assertNotNull("The identifier is null", oid);
        ac.setLongs(null);
        ac.setRefs(null);
        pm.currentTransaction().commit();
        pm.close();
        pm = null;
        ac = null;
        pm = pmf.getPersistenceManager();
        ac = (AllCollection) pm.getObjectById(oid, true);
        Assert.assertNotNull("No persistence found with the id " + oid, ac);
        Assert.assertTrue("The collection of Long is not null", ac.getCol_Long().isEmpty());
        Assert.assertTrue("The collection of reference is not null", ac.getCol_ref().isEmpty());
        Assert.assertTrue("The Hashset of Long is not null", ac.getHset_Long().isEmpty());
        Assert.assertTrue("The Hashset of reference is not null", ac.getHset_ref().isEmpty());
        Assert.assertTrue("The list of Long is not null", ac.getList_Long().isEmpty());
        Assert.assertTrue("The list of reference is not null", ac.getList_ref().isEmpty());
        Assert.assertTrue("The set of Long is not null", ac.getSet_Long().isEmpty());
        Assert.assertTrue("The set of reference is not null", ac.getSet_ref().isEmpty());
        pm.currentTransaction().begin();
        pm.deletePersistent(ac);
        pm.currentTransaction().commit();
        pm.close();
    }
View Full Code Here


    public void testEmptyCollection() {
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        AllCollection ac = new AllCollection("testEmptyCollection");
        pm.makePersistent(ac);
        Object oid = pm.getObjectId(ac);
        assertNotNull("The identifier is null", oid);
        ac.setLongs(new long[]{});
        ac.setRefs(new Object[]{});
        pm.currentTransaction().commit();
        pm.close();
        pm = null;
        ac = null;
        pm = pmf.getPersistenceManager();
        ac = (AllCollection) pm.getObjectById(oid, true);
        Assert.assertNotNull("No persistence found with the id " + oid, ac);
        Assert.assertNotNull("The collection of Long is null", ac.getCol_Long());
        Assert.assertEquals("The collection of Long is not empty", 0, ac.getCol_Long().size());

        Assert.assertNotNull("The collection of reference is  null", ac.getCol_ref());
        Assert.assertEquals("The collection of reference is not empty", 0, ac.getCol_ref().size());

        Assert.assertNotNull("The Hashset of Long is  null", ac.getHset_Long());
        Assert.assertEquals("The Hashset of Long is not empty", 0, ac.getHset_Long().size());

        Assert.assertNotNull("The Hashset of reference is  null", ac.getHset_ref());
        Assert.assertEquals("The Hashset of reference is not empty", 0, ac.getHset_ref().size());

        Assert.assertNotNull("The list of Long is  null", ac.getList_Long());
        Assert.assertEquals("The list of Long is not empty", 0, ac.getList_Long().size());

        Assert.assertNotNull("The list of reference is  null", ac.getList_ref());
        Assert.assertEquals("The list of reference is not empty", 0, ac.getList_ref().size());

        Assert.assertNotNull("The set of Long is  null", ac.getSet_Long());
        Assert.assertEquals("The set of Long is not empty", 0, ac.getSet_Long().size());

        Assert.assertNotNull("The set of reference is  null", ac.getSet_ref());
        Assert.assertEquals("The set of reference is not empty", 0, ac.getSet_ref().size());

        pm.currentTransaction().begin();
        pm.deletePersistent(ac);
        pm.currentTransaction().commit();
        pm.close();
View Full Code Here

    public void testOneElement() {
        long[] ls = new long[]{217,218};
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        AllCollection ac = new AllCollection("testOneElement");
        ac.setLongs(ls);
        ac.setRefs(new Object[]{ac});
        pm.makePersistent(ac);
        Object oid = pm.getObjectId(ac);
        assertNotNull("The identifier is null", oid);
        pm.currentTransaction().commit();
        pm.close();
        pm = null;
        ac = null;
        pm = pmf.getPersistenceManager();
        ac = (AllCollection) pm.getObjectById(oid, true);
        assertNotNull("No persistence found with the id " + oid, ac);

        List expectedLong = new ArrayList(ls.length);
        for(int i=0; i<ls.length; i++) {
            expectedLong.add(new Long(ls[i]));
        }

        List expectedRef = new ArrayList(1);
        expectedRef.add(ac);

        //Collection
        Assert.assertNotNull("The collection of Long is null", ac.getCol_Long());
        assertSameCollection("The collection of Long", expectedLong, ac.getCol_Long());
        Assert.assertNotNull("The collection of reference is null", ac.getCol_ref());
        assertSameCollection("The collection of ref", expectedRef, ac.getCol_ref());

        //HashSet
        Assert.assertNotNull("The Hashset of Long is null", ac.getHset_Long());
        assertSameCollection("The Hashset of Long", expectedLong, ac.getHset_Long());
        Assert.assertNotNull("The Hashset of reference is null", ac.getHset_ref());
        assertSameCollection("The Hashset of ref", expectedRef, ac.getHset_ref());

        //List
        Assert.assertNotNull("The list of Long is null", ac.getList_Long());
        assertSameList("The list of Long", expectedLong, ac.getList_Long());
        Assert.assertNotNull("The list of reference is null", ac.getList_ref());
        assertSameList("The list of reference", expectedRef, ac.getList_ref());

        //Set
        Assert.assertNotNull("The set of Long is null", ac.getSet_Long());
        assertSameCollection("The set of Long", expectedLong, ac.getSet_Long());
        Assert.assertNotNull("The set of reference is null", ac.getSet_ref());
        assertSameCollection("The set of ref", expectedRef, ac.getSet_ref());

        pm.currentTransaction().begin();
        pm.deletePersistentAll(ac.getArraylist_ref());       
      ac.setRefs(null);
      ac.setLongs(null);
        pm.deletePersistent(ac);
        pm.currentTransaction().commit();
        pm.close();
    }
View Full Code Here

    public void testSeveralSameElement() {
        long[] ls = new long[]{217,217,218,218,219,219,217,218,219};
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        AllCollection ac = new AllCollection("testSeveralSameElement");
        ac.setLongs(ls);
        pm.makePersistent(ac);
        Object oid = pm.getObjectId(ac);
        pm.currentTransaction().commit();

        List expectedLong = new ArrayList(ls.length);
        HashSet expectedLongset = new HashSet();
        for(int i=0; i<ls.length; i++) {
            expectedLong.add(new Long(ls[i]));
            expectedLongset.add(new Long(ls[i]));
        }

        pm.currentTransaction().begin();
        checkAC(ac, expectedLong, expectedLongset);
        pm.currentTransaction().commit();

        for(int i = 0; i<5; i++) {
            pm.currentTransaction().begin();
            ac.addAll(new long[]{217});
            expectedLongset.add(new Long(217));
            expectedLong.add(new Long(217));
            checkAC(ac, expectedLong, expectedLongset);
            pm.currentTransaction().commit();

            pm.currentTransaction().begin();
            checkAC(ac, expectedLong, expectedLongset);
            pm.currentTransaction().commit();
        }

        for(int i = 0; i<5; i++) {
            pm.currentTransaction().begin();
            ac.addAll(new long[]{218,218});
            expectedLongset.add(new Long(218));
            expectedLongset.add(new Long(218));
            expectedLong.add(new Long(218));
            expectedLong.add(new Long(218));
            checkAC(ac, expectedLong, expectedLongset);
            pm.currentTransaction().commit();

            pm.currentTransaction().begin();
            checkAC(ac, expectedLong, expectedLongset);
            pm.currentTransaction().commit();
        }

        ac = null;
        pm.evictAll();
       
        pm.currentTransaction().begin();
        ac = (AllCollection) pm.getObjectById(oid, false);
        checkAC(ac, expectedLong, expectedLongset);
        pm.currentTransaction().commit();
       
        pm.currentTransaction().begin();
      ac.setLongs(null);
        pm.deletePersistent(ac);
        pm.currentTransaction().commit();
        pm.close();
    }
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.collection.AllCollection

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.