Package org.objectweb.speedo.pobjects.sequence.basic

Examples of org.objectweb.speedo.pobjects.sequence.basic.Cow


    PersistenceManager pm = pmf.getPersistenceManager();
    pm.getObjectIdClass(Cow.class);
    //get the sequence
    Sequence s = pm.getSequence(COW_SEQ);
    assertNotNull("Sequence " + COW_SEQ + " should not be null.", s);
    Cow c1 = new Cow("cowSeq1", ((Long)s.next()).longValue());
    Cow c2 = new Cow("cowSeq2", ((Long)s.next()).longValue());
    Cow c3 = new Cow("cowSeq3", ((Long)s.next()).longValue());
    assertTrue(c1.getNbOfLegs() < c2.getNbOfLegs());
    assertTrue(c2.getNbOfLegs() < c3.getNbOfLegs());
    Collection c = new ArrayList();
    c.add(c1);
    c.add(c2);
    c.add(c3);
    //make persistent
    pm.currentTransaction().begin();
    pm.makePersistentAll(c);
    pm.currentTransaction().commit();
    logger.log(BasicLevel.DEBUG, "c1: " + c1.getNbOfLegs());
    logger.log(BasicLevel.DEBUG, "c2: " + c2.getNbOfLegs());
    logger.log(BasicLevel.DEBUG, "c3: " + c3.getNbOfLegs());
        pm.close();
  }
View Full Code Here


    //get the sequence
    Sequence s = pm.getSequence(COW_SEQ);
    assertNotNull("Sequence " + COW_SEQ + " should not be null.", s);
    long beforeAllocate = ((Long) s.current()).longValue();
    Collection col = new ArrayList();
    Cow cow = null;
    for (int i = 1; i <= ADDITIONAL; i++) {
      cow = new Cow("cowAllocate" + i, ((Long)s.next()).longValue());
      col.add(cow);
    }
    assertEquals(beforeAllocate + ADDITIONAL, ((Long) s.current()).longValue());
    cow = new Cow("cowAfterAllocate", ((Long)s.next()).longValue());
    col.add(cow);
    pm.currentTransaction().begin();
    //make persistent
    pm.makePersistentAll(col);
    s.current();
    pm.currentTransaction().commit();
    Iterator it = col.iterator();
    while (it.hasNext()) {
      Cow c = (Cow) it.next();
      logger.log(BasicLevel.DEBUG, "cow " + c.getName() + ": " + c.getNbOfLegs());
    }
        pm.close();
  }
View Full Code Here

    //get the sequence
    Sequence s = pm.getSequence(COW_SEQ_TRANSACTIONAL);
    assertNotNull("Sequence " + COW_SEQ_TRANSACTIONAL + " should not be null.", s);
    try {
      //use the sequence outside a tx
      Cow c1 = new Cow("cowSeqNC1", ((Long)s.next()).longValue());
      fail("An exception should be caught: a transactional sequence is used outside a transaction.");
    } catch (Exception e) {
      if (!JDODataStoreException.class.equals(e.getClass())) {
        logger.log(BasicLevel.ERROR, "Found exception: ", e);
      }
View Full Code Here

    //get the sequence
    Sequence s = pm.getSequence(COW_SEQ_TRANSACTIONAL);
    assertNotNull("Sequence " + COW_SEQ_TRANSACTIONAL + " should not be null.", s);
    //begin the tx
    pm.currentTransaction().begin();
    Cow c1 = new Cow("cowSeqNC1", ((Long)s.next()).longValue());
    Cow c2 = new Cow("cowSeqNC2", ((Long)s.next()).longValue());
    Cow c3 = new Cow("cowSeqNC3", ((Long)s.next()).longValue());
    assertTrue(c1.getNbOfLegs() < c2.getNbOfLegs());
    assertTrue(c2.getNbOfLegs() < c3.getNbOfLegs());
    Collection c = new ArrayList();
    c.add(c1);
    c.add(c2);
    c.add(c3);
    //make persistent
    pm.makePersistentAll(c);
    pm.currentTransaction().commit();
    //begin a tx
    pm.currentTransaction().begin();
    Cow c4 = new Cow("cowSeqNC4", ((Long)s.next()).longValue());
    //keep the number
    long index = c4.getNbOfLegs();
    pm.makePersistent(c4);
    //rollback
    pm.currentTransaction().rollback();
    //begin a tx
    pm.currentTransaction().begin();
View Full Code Here

    //get the sequence
    Sequence s = pm.getSequence(COW_SEQ_DATASTORE);
    assertNotNull("Sequence " + COW_SEQ_DATASTORE + " should not be null.", s);
    //begin the tx
    pm.currentTransaction().begin();
    Cow c1 = new Cow("cowSeqDS1", ((Long)s.next()).longValue());
    Cow c2 = new Cow("cowSeqDS2", ((Long)s.next()).longValue());
    Cow c3 = new Cow("cowSeqDS3", ((Long)s.next()).longValue());
    assertTrue(c1.getNbOfLegs() < c2.getNbOfLegs());
    assertTrue(c2.getNbOfLegs() < c3.getNbOfLegs());
    Collection c = new ArrayList();
    c.add(c1);
    c.add(c2);
    c.add(c3);
    //make persistent
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.sequence.basic.Cow

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.