Package com.google.appengine.datanucleus.test.jpa

Examples of com.google.appengine.datanucleus.test.jpa.Book


    PutPolicy policy = new PutPolicy();
    DatastoreServiceInterceptor.install(getStoreManager(), policy);
    try {
      emf.close();
      switchDatasource(getEntityManagerFactoryName());
      Book book = new Book();
      pojo.getBooks().add(book);
      pojo.getBidirChildren().add(bidir);
      HasKeyPkJPA hasKeyPk = new HasKeyPkJPA();
      pojo.getHasKeyPks().add(hasKeyPk);
View Full Code Here


    assertEquals(Book.class.getName(), expectedChildren, countForClass(Book.class));
    assertEquals(HasKeyPkJPA.class.getName(), expectedChildren, countForClass(HasKeyPkJPA.class));
  }

  Book newBook() {
    Book b = new Book(nextNamedKey());
    b.setAuthor("max");
    b.setIsbn("22333");
    b.setTitle("yam");
    return b;
  }
View Full Code Here

    if (explicitDemarcation) {
      mockTxn.commit();
    }
    EasyMock.replay(mockDatastoreService, mockTxn);

    Book b1 = new Book();
    b1.setTitle("Foo Bar");
    b1.setAuthor("Joe Blow");
    b1.setIsbn("12345");

    EntityManager em = emf.createEntityManager();
    EntityTransaction txn = em.getTransaction();
    if (explicitDemarcation) {
      txn.begin();
View Full Code Here

  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");
View Full Code Here

        };
    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    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");
View Full Code Here

    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);
View Full Code Here

  public void testUpdateOfDetachedCollides() {
    Entity e = Book.newBookEntity("harold", "1234", "the title");
    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();
View Full Code Here

        };

    Entity e = Book.newBookEntity("harold", "1234", "the title");
    ds.put(e);
    beginTxn();
    Book book = em.find(Book.class, e.getKey());
    commitTxn();

    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    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());
      beginTxn();
      book.setFirstPublished(1989);
      em.merge(book);
      commitTxn();
      beginTxn();
      book = em.find(Book.class, e.getKey());
      assertEquals(book, "harold", "1234", 1989, "the title");
View Full Code Here

        };

    Entity e = Book.newBookEntity("harold", "1234", "the title");
    ds.put(e);
    beginTxn();
    Book b = em.find(Book.class, e.getKey());
    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    setDelegateForThread(dd);

    try {
      try {
        // update attached object TODO The object here is not "detached" at all. It is HOLLOW
        b.setFirstPublished(1988);
        commitTxn();
        fail("expected exception");
      } catch (RollbackException ex) {
        // good
        assertTrue(ex.getCause() instanceof PersistenceException);
        assertTrue(ex.getCause().getCause() instanceof ConcurrentModificationException);
      }
      // rollback of txn causes state of pojo to rollback as well
      assertEquals(2000, b.getFirstPublished());
      assertFalse(em.getTransaction().isActive());
      beginTxn();
      // reapply the change
      b.setFirstPublished(1988);
      em.merge(b);
      commitTxn();
      beginTxn();
      b = em.find(Book.class, e.getKey());
      assertEquals(b, "harold", "1234", 1988, "the title");
View Full Code Here

    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");
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jpa.Book

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.