Package com.google.appengine.datanucleus

Examples of com.google.appengine.datanucleus.ExceptionThrowingDatastoreDelegate$BaseExceptionPolicy


              exploded = true;
              throw new DatastoreFailureException("boom: " + methodName);
            }
          }
        };
    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);

    ApiProxy.Delegate original = getDelegateForThread();
    setDelegateForThread(dd);

    try {
View Full Code Here


            if (count == 1) {
              throw new IllegalArgumentException("boom");
            }
          }
        };
    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    ApiProxy.Delegate original = getDelegateForThread();
    setDelegateForThread(dd);

    try {
      Query q = pm.newQuery(Flight.class);
View Full Code Here

              throw new DatastoreTimeoutException("boom: " + methodName);
            }
          }
        };
    ApiProxy.Delegate original = getDelegateForThread();
    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    setDelegateForThread(dd);

    try {
      Query q = pm.newQuery(Flight.class);
      @SuppressWarnings("unchecked")
View Full Code Here

              throw new ConcurrentModificationException();
            }
            count++;
          }
        };
    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");
      } catch (RollbackException e) {
        // good
        assertTrue(e.getCause() instanceof PersistenceException);
        assertTrue(e.getCause().getCause() instanceof NucleusDataStoreException);
        assertTrue(e.getCause().getCause().getCause() instanceof ConcurrentModificationException);
      }
      assertFalse(em.getTransaction().isActive());
      assertEquals(book, "harold", "1234", 1888, "the title");
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

    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");
      commitTxn();
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
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");
      commitTxn();
    } finally {
      setDelegateForThread(dd.getInner());
    }
  }
View Full Code Here

    beginTxn();
    Book b = em.find(Book.class, e.getKey());
    commitTxn();
    em.close();
    em = emf.createEntityManager();
    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    setDelegateForThread(dd);

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

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

    Entity e = Book.newBookEntity("harold", "1234", "the title");
    ds.put(e);
    Book b = em.find(Book.class, e.getKey());
    // make a copy right away, otherwise our change will get reverted when the txn rolls back
    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    setDelegateForThread(dd);

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

            }
          }
        };

    ApiProxy.Delegate original = getDelegateForThread();
    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    setDelegateForThread(dd);

    try {
      javax.persistence.Query q = em.createQuery(
          "select from " + Book.class.getName() + " b");
View Full Code Here

            }
          }
        };
    ApiProxy.Delegate original = getDelegateForThread();

    ExceptionThrowingDatastoreDelegate dd =
        new ExceptionThrowingDatastoreDelegate(getDelegateForThread(), policy);
    setDelegateForThread(dd);

    try {
      Query q = em.createQuery("select from " + Book.class.getName() + " b");
      try {
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.ExceptionThrowingDatastoreDelegate$BaseExceptionPolicy

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.