Package com.google.appengine.datanucleus

Examples of com.google.appengine.datanucleus.CollisionDatastoreDelegate


*/
@Inner
public class JPAConcurrentModificationTest extends JPATestCase {

  public void testInsertCollides() {
    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);
    try {
      Book book = new Book();
      book.setAuthor("harold");
      book.setIsbn("1234");
      book.setFirstPublished(1888);
      book.setTitle("the title");
      beginTxn();
      try {
        em.persist(book);
        commitTxn();
        fail("expected exception");
      } catch (RollbackException e) {
        // good
        assertTrue(e.getCause() instanceof PersistenceException);
        assertTrue(e.getCause().getCause() instanceof ConcurrentModificationException);
      }
      assertFalse(em.getTransaction().isActive());
      assertEquals(book, "harold", "1234", 1888, "the title");
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here


  }

  public void testUpdateCollides() {
    Entity e = Book.newBookEntity("harold", "1234", "the title");
    ds.put(e);
    CollisionDatastoreDelegate dd =
        new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);
    try {
      beginTxn();
      Book b = em.find(Book.class, e.getKey());
      try {
        b.setFirstPublished(1998);
        commitTxn();
        fail("expected exception");
      } catch (RollbackException ex) {
        // good
        assertTrue(ex.getCause() instanceof PersistenceException);
        assertTrue(ex.getCause().getCause() instanceof ConcurrentModificationException);
      }
      assertFalse(em.getTransaction().isActive());
      assertEquals(b, "harold", "1234", 2000, "the title");
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

    ds.put(e);
    beginTxn();
    Book book = em.find(Book.class, e.getKey());
    commitTxn();

    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);

    try {
      try {
        // update detached object TODO The object here is not "detached" at all. It is HOLLOW
        book.setFirstPublished(1988);
        beginTxn();

        // reattach
        em.merge(book);
        commitTxn();
        fail("expected exception");
      } catch (RollbackException ex) {
        // good
        assertTrue(ex.getCause() instanceof PersistenceException);
        assertTrue(ex.getCause().getCause() instanceof ConcurrentModificationException);
      } catch (NucleusDataStoreException nde) {
        assertTrue(nde.getCause() instanceof ConcurrentModificationException);
      }
      assertFalse(em.getTransaction().isActive());
      // now verify that the new value is still in the detached version.
      assertEquals(book, "harold", "1234", 1988, "the title");
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

  }

  public void testDeleteCollides() {
    Entity e = Book.newBookEntity("harold", "1234", "the title");
    ds.put(e);
    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);

    try {
      beginTxn();
      Book b = em.find(Book.class, e.getKey());
      em.remove(b);

      try {
        commitTxn();
        fail("expected exception");
      } catch (RollbackException ex) {
        // good
        assertTrue(ex.getCause() instanceof PersistenceException);
        assertTrue(ex.getCause().getCause() instanceof ConcurrentModificationException);
      }
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

    }
  }

  public void testInsertCollides_NoTxn() {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);
    try {
      Book book = new Book();
      book.setAuthor("harold");
      book.setIsbn("1234");
      book.setFirstPublished(1988);
      book.setTitle("the title");
      try {
        em.persist(book);
        em.close();
        fail("expected exception");
      } catch (PersistenceException e) {
        assertTrue(e.getCause() instanceof ConcurrentModificationException);
      }
      assertEquals(book, "harold", "1234", 1988, "the title");
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

  public void testUpdateCollides_NoTxn() {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
    Entity e = Book.newBookEntity("harold", "1234", "the title");
    ds.put(e);
    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);

    try {
      Book b = em.find(Book.class, e.getKey());
      try {
        b.setFirstPublished(1988);
        em.close();
        fail("expected exception");
      } catch (PersistenceException ex) {
        assertTrue(ex.getCause() instanceof ConcurrentModificationException);
      } catch (NucleusDataStoreException nde) {
        assertTrue(nde.getCause() instanceof ConcurrentModificationException);
      }
      assertEquals(b, "harold", "1234", 1988, "the title");
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

    Book book = em.find(Book.class, e.getKey());
    commitTxn();
    em.close();
    em = emf.createEntityManager();

    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);

    try {
      // update detached object
      book.setFirstPublished(1988);

      try {
        // reattach
        em.merge(book);
        em.close();
        fail("expected exception");
      } catch (PersistenceException ex) {
        assertTrue(ex.getCause() instanceof ConcurrentModificationException);
      }
      // now verify that the new value is still in the detached version.
      assertEquals(book, "harold", "1234", 1988, "the title");
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

  public void testDeleteCollides_NoTxn() {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);

    Entity e = Book.newBookEntity("harold", "1234", "the title");
    ds.put(e);
    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);

    try {
      Book b = em.find(Book.class, e.getKey());
      try {
        em.remove(b);
        em.close();
        fail("expected exception");
      } catch (PersistenceException ex) {
        assertTrue(ex.getCause() instanceof ConcurrentModificationException);
      }
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

*/
@Inner
public class JDOConcurrentModificationTest extends JDOTestCase {

  public void testInsertCollides() {
    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);
    try {
      Flight flight = new Flight();
      flight.setName("harold");
      flight.setOrigin("bos");
      flight.setDest("mia");
      flight.setYou(23);
      flight.setMe(24);
      flight.setFlightNumber(88);
      beginTxn();
      try {
        pm.makePersistent(flight);
        fail("expected exception");
      } catch (JDODataStoreException e) {
        // good
        assertTrue(e.getCause() instanceof ConcurrentModificationException);
      }
      assertTrue(pm.currentTransaction().isActive());
      rollbackTxn();
      assertEquals(flight, "harold", "bos", "mia", 23, 24, 88);
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

  }

  public void testUpdateCollides() {
    Entity e = Flight.newFlightEntity("harold", "bos", "mia", 23, 24, 88);
    ds.put(e);
    CollisionDatastoreDelegate dd = new CollisionDatastoreDelegate(getDelegateForThread());
    setDelegateForThread(dd);
    try {
      beginTxn();
      Flight f = pm.getObjectById(Flight.class, e.getKey());
      f.setYou(12);
      try {
        commitTxn();
        fail("expected exception");
      } catch (JDODataStoreException ex) {
        // good
        assertTrue(ex.getCause() instanceof ConcurrentModificationException);
      }
      assertFalse(pm.currentTransaction().isActive());
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.CollisionDatastoreDelegate

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.