Package org.objectweb.speedo.pobjects.basic

Examples of org.objectweb.speedo.pobjects.basic.BasicA


        }
    }

  public void testImbricatedPM() {
    logger.log(BasicLevel.DEBUG, "testImbricatedPM");
    BasicA ba = new BasicA();
    ba.writeF1("testImbricatedPM");
    ba.writeF2(2);
    PersistenceManager pm1 = pmf.getPersistenceManager();
    PersistenceManager pm2 = pmf.getPersistenceManager();
        Assert.assertTrue("Same persistence manager", pm1!=pm2);
    pm2.makePersistent(ba);
        pm2.close();
    //touch the pm
    pm1.getUserObject();
        ba.readF1();
        ba.readF2();
        pm1.currentTransaction().begin();
    pm1.deletePersistent(ba);
    pm1.currentTransaction().commit();
        try {
            pm1.close();
View Full Code Here


    logger.log(BasicLevel.INFO, "testMakeDirty");
    try {
      pm = pmf.getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      tx.begin();
      BasicA p1 = new BasicA();
      pm.makePersistent(p1);
      tx.commit();

      Transaction tx1 = pm.currentTransaction();
      tx1.begin();
View Full Code Here

    logger.log(BasicLevel.INFO, "testIsDeletedForTransient");
    try {
      pm = pmf.getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      tx.begin();
      BasicA p1 = new BasicA();
     
      int state = currentState(p1);

      logger.log(BasicLevel.INFO, "IS_PERSISTENT=" + JDOHelper.isPersistent(p1));
      logger.log(BasicLevel.INFO, "IS_TRANSACTIONAL=" + JDOHelper.isTransactional(p1));
View Full Code Here

  }
 
    public void testConcurrentReads() {
        logger.log(BasicLevel.INFO, "test concurrent reads");
        // setup
        BasicA ba = new BasicA();
        ba.writeF1("1");
        ba.writeF2(2);
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        pm.makePersistent(ba);
        final Object id = pm.getObjectId(ba);
        Assert.assertNotNull("Null object identifier", id);
        pm.currentTransaction().commit();
        pm.close();

        ba = null;

        // begin transaction 1
        PersistenceManager pm1 = pmf.getPersistenceManager();
        logger.log(BasicLevel.INFO, "Thread1: begin");
        pm1.currentTransaction().begin();
        logger.log(BasicLevel.INFO, "Thread1: getObjectById");
        ba = (BasicA) pm1.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);
        logger.log(BasicLevel.INFO, "Thread1: read");
        ba.readF2();
        logger.log(BasicLevel.INFO, "Thread1: read done");

        // begin transaction 2
        Thread t = new Thread((new Runnable () {
            public void run () {
                PersistenceManager pm2 = pmf.getPersistenceManager();
                logger.log(BasicLevel.INFO, "Thread2: begin");
                pm2.currentTransaction().begin();
                logger.log(BasicLevel.INFO, "Thread2: getObjectById");
                BasicA ba = (BasicA) pm2.getObjectById(id, true);
                Assert.assertNotNull("Object not found", ba);
                logger.log(BasicLevel.INFO, "Thread2: read");
                ba.readF2();
                logger.log(BasicLevel.INFO, "Thread2: read done");
                logger.log(BasicLevel.INFO, "Thread2: commit");
                pm2.currentTransaction().commit();
                pm2.close();
            }
        }));
        t.start();

        // end transaction 1
        logger.log(BasicLevel.INFO, "Thread1: commit");
        pm1.currentTransaction().commit();
        pm1.close();

        assertUnlock(t);

        // clean up
        pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        ba = (BasicA) pm.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);
        Assert.assertEquals("Bad f1 value", "1", ba.readF1());
        Assert.assertEquals("Bad f2 value", 2, ba.readF2());
        pm.deletePersistent(ba);
        pm.currentTransaction().commit();
        pm.close();
    }
View Full Code Here

    }

    public void testReadConcurrentWrite() {
        logger.log(BasicLevel.INFO, "test read concurrent write");
        // setup
        BasicA ba = new BasicA();
        ba.writeF1("1");
        ba.writeF2(2);
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        pm.makePersistent(ba);
        final Object id = pm.getObjectId(ba);
        Assert.assertNotNull("Null object identifier", id);
        pm.currentTransaction().commit();
        pm.close();

        ba = null;

        // begin transaction 1
        PersistenceManager pm1 = pmf.getPersistenceManager();
        logger.log(BasicLevel.INFO, "Thread1: begin");
        pm1.currentTransaction().begin();
        logger.log(BasicLevel.INFO, "Thread1: getObjectById");
        ba = (BasicA) pm1.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);
        logger.log(BasicLevel.INFO, "Thread1: read");
        ba.readF2();
        logger.log(BasicLevel.INFO, "Thread1: read done");

        // begin transaction 2
        Thread t = assertLock(new Runnable () {
            public void run () {
                PersistenceManager pm2 = pmf.getPersistenceManager();
                logger.log(BasicLevel.INFO, "Thread2: begin");
                pm2.currentTransaction().begin();
                logger.log(BasicLevel.INFO, "Thread2: getObjectById");
                BasicA ba = (BasicA) pm2.getObjectById(id, true);
                Assert.assertNotNull("Object not found", ba);
                logger.log(BasicLevel.INFO, "Thread2: write");
                ba.writeF2(ba.readF2() + 1);
                logger.log(BasicLevel.INFO, "Thread2: write done");
                logger.log(BasicLevel.INFO, "Thread2: commit");
                pm2.currentTransaction().commit();
                pm2.close();
            }
        });

        // end transaction 1
        logger.log(BasicLevel.INFO, "Thread1: commit");
        pm1.currentTransaction().commit();
        pm1.close();

        assertUnlock(t);

        // clean up
        pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        ba = (BasicA) pm.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);
        Assert.assertEquals("Bad f1 value", "1", ba.readF1());
        Assert.assertEquals("Bad f2 value", 3, ba.readF2());
        pm.deletePersistent(ba);
        pm.currentTransaction().commit();
        pm.close();
    }
View Full Code Here

    }

    public void testWriteConcurrentRead() {
        logger.log(BasicLevel.INFO, "test write concurrent read");
        // setup
        BasicA ba = new BasicA();
        ba.writeF1("1");
        ba.writeF2(2);
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        pm.makePersistent(ba);
        final Object id = pm.getObjectId(ba);
        Assert.assertNotNull("Null object identifier", id);
        pm.currentTransaction().commit();
        pm.close();

        ba = null;

        // begin transaction 1
        PersistenceManager pm1 = pmf.getPersistenceManager();
        logger.log(BasicLevel.INFO, "Thread1: begin");
        pm1.currentTransaction().begin();
        logger.log(BasicLevel.INFO, "Thread1: getObjectById");
        ba = (BasicA) pm1.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);
        logger.log(BasicLevel.INFO, "Thread1: write");
        ba.writeF2(ba.readF2() + 1);
        logger.log(BasicLevel.INFO, "Thread1: write done");

        // begin transaction 2
        Thread t = assertLock(new Runnable () {
            public void run () {
                PersistenceManager pm2 = pmf.getPersistenceManager();
                logger.log(BasicLevel.INFO, "Thread2: begin");
                pm2.currentTransaction().begin();
                logger.log(BasicLevel.INFO, "Thread2: getObjectById");
                BasicA ba = (BasicA) pm2.getObjectById(id, true);
                Assert.assertNotNull("Object not found", ba);
                logger.log(BasicLevel.INFO, "Thread2: read");
                ba.readF2();
                logger.log(BasicLevel.INFO, "Thread2: read done");
                logger.log(BasicLevel.INFO, "Thread2: commit");
                pm2.currentTransaction().commit();
                pm2.close();
            }
        });

        // end transaction 1
        logger.log(BasicLevel.INFO, "Thread1: commit");
        pm1.currentTransaction().commit();
        pm1.close();

        assertUnlock(t);

        // clean up
        pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        ba = (BasicA) pm.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);
        Assert.assertEquals("Bad f1 value", "1", ba.readF1());
        Assert.assertEquals("Bad f2 value", 3, ba.readF2());
        pm.deletePersistent(ba);
        pm.currentTransaction().commit();
        pm.close();
    }
View Full Code Here

    }

    public void testWriteConcurrentRead2() {
        logger.log(BasicLevel.INFO, "test write concurrent read 2");
        // setup
        BasicA ba = new BasicA();
        ba.writeF1("1");
        ba.writeF2(2);
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        pm.makePersistent(ba);
        final Object id = pm.getObjectId(ba);
        Assert.assertNotNull("Null object identifier", id);
        pm.currentTransaction().commit();
        pm.close();

        ba = null;

        // begin transaction 1
        PersistenceManager pm1 = pmf.getPersistenceManager();
        logger.log(BasicLevel.INFO, "Thread1: begin");
        pm1.currentTransaction().begin();
        logger.log(BasicLevel.INFO, "Thread1: getObjectById");
        BasicA ba1 = (BasicA) pm1.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba1);

        // begin transaction 2
        Thread t = new Thread((new Runnable () {
            public void run () {
                PersistenceManager pm2 = pmf.getPersistenceManager();
                logger.log(BasicLevel.INFO, "Thread2: begin");
                pm2.currentTransaction().begin();
                logger.log(BasicLevel.INFO, "Thread2: getObjectById");
                BasicA ba2 = (BasicA) pm2.getObjectById(id, true);
                Assert.assertNotNull("Object not found", ba2);
                logger.log(BasicLevel.INFO, "Thread2: read");
                ba2.readF2();
                logger.log(BasicLevel.INFO, "Thread2: read done");
                logger.log(BasicLevel.INFO, "Thread2: commit");
                pm2.currentTransaction().commit();
                pm2.close();
            }
View Full Code Here

    }

  public void testConcurrentWrites() {
        logger.log(BasicLevel.INFO, "test concurrent writes");
        // setup
    BasicA ba = new BasicA();
    ba.writeF1("1");
    ba.writeF2(2);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(ba);
    final Object id = pm.getObjectId(ba);
    Assert.assertNotNull("Null object identifier", id);
    pm.currentTransaction().commit();
    pm.close();

    ba = null;

        // begin transaction 1
        PersistenceManager pm1 = pmf.getPersistenceManager();
        logger.log(BasicLevel.INFO, "Thread1: begin");
        pm1.currentTransaction().begin();
        logger.log(BasicLevel.INFO, "Thread1: getObjectById");
        ba = (BasicA) pm1.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);
        logger.log(BasicLevel.INFO, "Thread1: write");
        ba.writeF2(ba.readF2() + 1);
        logger.log(BasicLevel.INFO, "Thread1: write done");

        // begin transaction 2
        Thread t = assertLock(new Runnable () {
            public void run () {
                PersistenceManager pm2 = pmf.getPersistenceManager();
                try {
                    logger.log(BasicLevel.INFO, "Thread2: begin");
                    pm2.currentTransaction().begin();
                    logger.log(BasicLevel.INFO, "Thread2: getObjectById");
                    BasicA ba = (BasicA) pm2.getObjectById(id, true);
                    Assert.assertNotNull("Object not found", ba);
                    logger.log(BasicLevel.INFO, "Thread2: write");
                    ba.writeF2(ba.readF2() + 1);
                    logger.log(BasicLevel.INFO, "Thread2: write done");

                    logger.log(BasicLevel.INFO, "Thread2: commit");
                    pm2.currentTransaction().commit();
                } catch (JDOFatalException e) {

                } finally {
                    pm2.close();
                }
            }
        });

        // end transaction 1
        logger.log(BasicLevel.INFO, "Thread1: commit");
        pm1.currentTransaction().commit();
        pm1.close();

        // end transaction 2
        assertUnlock(t);

        // clean up
    pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    ba = (BasicA) pm.getObjectById(id, true);
    Assert.assertNotNull("Object not found", ba);
    Assert.assertEquals("Bad f1 value", "1", ba.readF1());
    Assert.assertEquals("Bad f2 value", 4, ba.readF2());
    pm.deletePersistent(ba);
    pm.currentTransaction().commit();
    pm.close();
  }
View Full Code Here

  }

    public void testConcurrentWrites2() {
        logger.log(BasicLevel.INFO, "test concurrent writes 2");
        // setup
        BasicA ba = new BasicA();
        ba.writeF1("1");
        ba.writeF2(2);
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        pm.makePersistent(ba);
        final Object id = pm.getObjectId(ba);
        Assert.assertNotNull("Null object identifier", id);
        pm.currentTransaction().commit();
        pm.close();

        ba = null;

        // begin transaction 1
        PersistenceManager pm1 = pmf.getPersistenceManager();
        logger.log(BasicLevel.INFO, "Thread1: begin");
        pm1.currentTransaction().begin();
        logger.log(BasicLevel.INFO, "Thread1: getObjectById");
        ba = (BasicA) pm1.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);

        // begin transaction 2
        Thread t = assertLock(new Runnable () {
            public void run () {
                PersistenceManager pm2 = pmf.getPersistenceManager();
                try {
                    logger.log(BasicLevel.INFO, "Thread2: begin");
                    pm2.currentTransaction().begin();
                    logger.log(BasicLevel.INFO, "Thread2: getObjectById");
                    BasicA ba = (BasicA) pm2.getObjectById(id, true);
                    Assert.assertNotNull("Object not found", ba);
                    logger.log(BasicLevel.INFO, "Thread2: write");
                    ba.writeF2(ba.readF2() + 1);
                    logger.log(BasicLevel.INFO, "Thread2: write done");

                    logger.log(BasicLevel.INFO, "Thread2: commit");
                    pm2.currentTransaction().commit();
                } catch (JDOFatalException e) {
                } finally {
                    pm2.close();
                }
            }
        });

        // end transaction 1
        logger.log(BasicLevel.INFO, "Thread1: write");
        boolean ok = true;
        try {
            ba.writeF2(ba.readF2() + 1);
            ok = true;
            logger.log(BasicLevel.INFO, "Thread1: write done");
            logger.log(BasicLevel.INFO, "Thread1: commit");
            pm1.currentTransaction().commit();
        } catch (JDOException e) {
            logger.log(BasicLevel.INFO, "Thread1: write aborted"
                    + ExceptionHelper.getNested(e).getMessage());
            ok = false;
        } finally {
            pm1.close();
        }
        assertUnlock(t);

        // clean up
        pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        ba = (BasicA) pm.getObjectById(id, true);
        Assert.assertNotNull("Object not found", ba);
        Assert.assertEquals("Bad f1 value", "1", ba.readF1());
        Assert.assertEquals("Bad f2 value", ( ok ? 4 : 3), ba.readF2());
        pm.deletePersistent(ba);
        pm.currentTransaction().commit();
        pm.close();
    }
View Full Code Here

    }

  public void testNotIgnoreCache() {
    logger.log(BasicLevel.DEBUG, "testSequenceIdNavigateToPrimitive");
    PersistenceManager pm = pmf.getPersistenceManager();
    BasicA ba = new BasicA();
    ba.writeF1("testNotIgnoreCache1");
    ba.writeF2(1);
    pm.makePersistent(ba);
    pm.close();

    pm = pmf.getPersistenceManager();
    ba.writeF1("testNotIgnoreCache2");
    pm.setIgnoreCache(false);
    Assert.assertTrue("Bad ignore cache value", !pm.getIgnoreCache());
    Query query = pm.newQuery(BasicA.class);
    query.setFilter("(f1 == \"testNotIgnoreCache2\")");
    Collection col = (Collection) query.execute();
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.basic.BasicA

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.