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

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


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


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

    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
    Entity e = Book.newBookEntity("harold", "1234", "the title");
    ds.put(e);
    // DataNuc JPA impl won't detach the object unless you open and close a txn ... like the JPA spec says
    beginTxn();
    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();
View Full Code Here

        };

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

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

    Entity parentEntity = new Entity(HasOneToOneJPA.class.getSimpleName());
    ds.put(parentEntity);
    Entity bookEntity = Book.newBookEntity(parentEntity.getKey(), "Joe Blow", "11111", "Bar Book", 1929);
    ds.put(bookEntity);

    Book book = bp.getBook(bookEntity.getKey());
    Query q = em.createQuery(
        "select from " + HasOneToOneJPA.class.getName() + " c where book = :b");
    q.setParameter("b", book);
    List<HasOneToOneJPA> result = (List<HasOneToOneJPA>) q.getResultList();
    assertEquals(1, result.size());
View Full Code Here

    Entity parentEntity = new Entity(HasOneToOneJPA.class.getSimpleName());
    ds.put(parentEntity);
    Entity bookEntity = Book.newBookEntity(parentEntity.getKey(), "Joe Blow", "11111", "Bar Book", 1929);
    ds.put(bookEntity);

    Book book = bp.getBook(bookEntity.getKey());
    Query q = em.createQuery(
        "select from " + HasOneToOneJPA.class.getName() + " c where id = :parentId and book = :b");
    q.setParameter("parentId", KeyFactory.keyToString(bookEntity.getKey()));
    q.setParameter("b", book);
    List<HasOneToOneJPA> result = (List<HasOneToOneJPA>) q.getResultList();
View Full Code Here

    Entity parentEntity = new Entity(HasOneToOneJPA.class.getSimpleName());
    ds.put(parentEntity);
    Entity bookEntity = Book.newBookEntity(parentEntity.getKey(), "Joe Blow", "11111", "Bar Book", 1929);
    ds.put(bookEntity);

    Book book = bp.getBook(bookEntity.getKey());
    Query q = em.createQuery(
        "select from " + HasOneToOneJPA.class.getName() + " c where book > :b");
    q.setHint(DatastoreManager.QUERYEXT_INMEMORY_WHEN_UNSUPPORTED, "false");
    q.setParameter("b", book);
    try {
View Full Code Here

    Entity parentEntity = new Entity(HasOneToOneJPA.class.getSimpleName());
    ds.put(parentEntity);
    Entity bookEntity = Book.newBookEntity("Joe Blow", "11111", "Bar Book", 1929);
    ds.put(bookEntity);

    Book book = bp.getBook(bookEntity.getKey());
    Query q = em.createQuery(
        "select from " + HasOneToOneJPA.class.getName() + " c where book = :b");
    q.setParameter("b", book);
    q.setHint(DatastoreManager.QUERYEXT_INMEMORY_WHEN_UNSUPPORTED, "false");
    try {
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.