Package javax.jdo.datastore

Examples of javax.jdo.datastore.Sequence


        if (seqmd == null)
        {
            throw new JDOUserException(LOCALISER.msg("017000", sequenceName));
        }

        Sequence seq = null;
        if (seqmd.getFactoryClass() != null)
        {
            // User has specified a factory class
            seq = getAbstractPersistenceManagerFactory().getSequenceForFactoryClass(seqmd.getFactoryClass());
            if (seq == null)
View Full Code Here


  public void testSequence() {
    logger.log(BasicLevel.DEBUG, "***************testSequence*****************");
    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);
View Full Code Here

  public void testAllocate() {
    logger.log(BasicLevel.DEBUG, "***************testAllocate*****************");
    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);
    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());
View Full Code Here

  public void testCompareNextToAllocate() {
    logger.log(BasicLevel.DEBUG, "***************testCompareNextToAllocate*****************");
    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);
    long timeToGetManyNext = System.currentTimeMillis();
    for (int i  = 0; i< COMPARE_NUMBER; i++) {
      s.next();
    }
    timeToGetManyNext = System.currentTimeMillis() - timeToGetManyNext;
    long timeToGetManyAllocate = System.currentTimeMillis();
    s.allocate(COMPARE_NUMBER);
    for (int i  = 0; i< COMPARE_NUMBER; i++) {
      s.next();
    }
    timeToGetManyAllocate = System.currentTimeMillis() - timeToGetManyAllocate;
    logger.log(BasicLevel.DEBUG, COMPARE_NUMBER + " ids generated:\nwith allocate: " + timeToGetManyAllocate
        + "\nwith next: " + timeToGetManyNext);
    assertTrue("The time to get many ids with an allocate should be inferior to the time to get many ids with next()",
View Full Code Here

  public void testSequenceTransactional1() {
    logger.log(BasicLevel.DEBUG, "***************testSequenceTransactional1*****************");
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.getObjectIdClass(Cow.class);
    //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

  public void testSequenceTransactional2() {
    logger.log(BasicLevel.DEBUG, "***************testSequenceTransactional2*****************");
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.getObjectIdClass(Cow.class);
    //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();
    //check the next number generated is not the one used for the rollback : gap
    assertTrue(((Long)s.next()).longValue() != index);
    pm.currentTransaction().commit();
        pm.close();
  }
View Full Code Here

  public void testSequenceDatastore() {
    logger.log(BasicLevel.DEBUG, "***************testSequenceDatastore*****************");
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.getObjectIdClass(Cow.class);
    //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);
View Full Code Here

  public void testSequenceId() {
    logger.log(BasicLevel.DEBUG, "***************testSequenceId*****************");
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.getObjectIdClass(Card.class);
    //get the sequence
    Sequence s = pm.getSequence(CARD_SEQ);
    assertNotNull("Sequence " + CARD_SEQ + " should not be null.", s);
    Card c1 = new Card();
    c1.setName("card 1");
    Card c2 = new Card();
    c2.setName("card 2");
View Full Code Here

  public void testSequenceHiddenField() {
    logger.log(BasicLevel.DEBUG, "***************testSequenceHiddenField*****************");
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.getObjectIdClass(Maps.class);
    //get the sequence
    Sequence s = pm.getSequence(MAP_SEQ);
    assertNotNull("Sequence " + MAP_SEQ + " should not be null.", s);
    Maps m1 = new Maps();
    m1.setName("map 1");
    Maps m2 = new Maps();
    m2.setName("map 2");
View Full Code Here

  public void testSequenceId1() {
    logger.log(BasicLevel.DEBUG, "***************testSequenceId1*****************");
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.getObjectIdClass(Product.class);
    //get the sequence
    Sequence s = pm.getSequence(PRODUCT_SEQ);
    assertNotNull("Sequence " + PRODUCT_SEQ + " should not be null.", s);
    Product p1 = new Product();
    p1.setName("product 1");
    Product p2 = new Product();
    p2.setName("product 2");
View Full Code Here

TOP

Related Classes of javax.jdo.datastore.Sequence

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.