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

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


    q.setParameter("key", KeyFactory.keyToString(pojoEntity.getKey()));
    startEnd.start();
    @SuppressWarnings("unchecked")
    List<HasOneToOneJPA> result = (List<HasOneToOneJPA>) q.getResultList();
    assertEquals(1, result.size());
    HasOneToOneJPA pojo = result.get(0);
    assertNotNull(pojo.getBook());
    assertEquals("auth", pojo.getBook().getAuthor());
    assertNotNull(pojo.getHasKeyPK());
    assertEquals("yar", pojo.getHasKeyPK().getStr());
    assertNotNull(pojo.getHasParent());
    assertEquals("yap", pojo.getHasParent().getStr());
    assertNotNull(pojo.getHasParentKeyPK());
    assertEquals("yag", pojo.getHasParentKeyPK().getStr());
    startEnd.end();
  }
View Full Code Here


      // the only get we're going to perform is for the pojo
      EasyMock.expect(mockDatastore.get(txn, pojoEntity.getKey())).andReturn(pojoEntity);
      EasyMock.replay(mockDatastore);

      beginTxn();
      HasOneToOneJPA pojo = em.find(HasOneToOneJPA.class, KeyFactory.keyToString(pojoEntity.getKey()));
      assertNotNull(pojo);
      pojo.getId();
      commitTxn();
    } finally {
      // need to close the emf before we restore the original datastore service
      emf.close();
      DatastoreServiceFactoryInternal.setDatastoreService(original);
View Full Code Here

    ds.put(notDependentEntity);

    assertEquals(HasOneToOneJPA.class.getName(), 1, countForClass(HasOneToOneJPA.class));

    startEnd.start();
    HasOneToOneJPA pojo = em.find(HasOneToOneJPA.class, KeyFactory.keyToString(pojoEntity.getKey()));
    em.remove(pojo);
    startEnd.end();
    try {
      pojoEntity = ds.get(pojoEntity.getKey());
      fail("expected enfe");
View Full Code Here

  public void testChangeParent() {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_not_allowed);
    Book b1 = newBook();

    HasOneToOneJPA pojo = new HasOneToOneJPA();
    pojo.setBook(b1);
    beginTxn();
    em.persist(pojo);
    commitTxn();

    HasOneToOneJPA pojo2 = new HasOneToOneJPA();
    beginTxn();
    pojo2.setBook(b1);
    em.persist(pojo2);
    try {
      commitTxn();
      em.close();
      fail("expected exception");
View Full Code Here

  }
  public void testNewParentNewChild_SetNamedKeyOnChild_NoTxn() throws EntityNotFoundException {
    testNewParentNewChild_SetNamedKeyOnChild(NEW_EM_START_END);
  }
  private void testNewParentNewChild_SetNamedKeyOnChild(StartEnd startEnd) throws EntityNotFoundException {
    HasOneToOneJPA pojo = new HasOneToOneJPA();
    Book b = newBook("named key");
    pojo.setBook(b);
    startEnd.start();
    em.persist(pojo);
    startEnd.end();

    Entity bookEntity = ds.get(KeyFactory.stringToKey(b.getId()));
View Full Code Here

                 1, countForClass(HasOneToOneStringPkParentKeyPkJPA.class));
  }

  public void testAddAlreadyPersistedChildToParent_NoTxnDifferentEm() {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
    HasOneToOneJPA pojo = new HasOneToOneJPA();
    Book book = new Book();
    em.persist(book);
    em.close();
    em = emf.createEntityManager();
    pojo.setBook(book);
    try {
      em.persist(pojo);
      em.close();
      fail("expected exception");
    } catch (PersistenceException e) {
      // good
    }

    assertEquals(0, countForClass(pojo.getClass()));
    assertEquals(1, countForClass(Book.class));
  }
View Full Code Here

    assertEquals(1, countForClass(Book.class));
  }

  public void testAddAlreadyPersistedChildToParent_NoTxnSameEm() {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
    HasOneToOneJPA pojo = new HasOneToOneJPA();
    Book book = new Book();
    em.persist(book);
    em.close();
    em = emf.createEntityManager();
    pojo.setBook(book);
    try {
      em.persist(pojo);
      em.close();
      fail("expected exception");
    } catch (PersistenceException e) {
      // good
    }

    assertEquals(0, countForClass(pojo.getClass()));
    assertEquals(1, countForClass(Book.class));
  }
View Full Code Here

  public void testOnlyOnePutOnChildUpdate_NoTxn() throws Throwable {
    testOnlyOnePutOnChildUpdate(NEW_EM_START_END);
  }
  private void testOnlyOnePutOnChildUpdate(JPATestCase.StartEnd startEnd)
      throws Throwable {
    HasOneToOneJPA pojo = new HasOneToOneJPA();
    HasOneToOneParentJPA hasParent = new HasOneToOneParentJPA();
    PutPolicy policy = setupPutPolicy(pojo, hasParent, startEnd);
    try {
      startEnd.start();
      pojo = em.find(pojo.getClass(), pojo.getId());
      pojo.getBook().setIsbn("88");
      pojo.getHasParent().setStr("blarg");
      pojo.getHasKeyPK().setStr("double blarg");
      startEnd.end();
    } finally {
      DatastoreServiceInterceptor.uninstall();
    }
    // 1 put for each child update
View Full Code Here

  public void testOnlyOneParentPutOnParentAndChildUpdate_NoTxn() throws Throwable {
    testOnlyOneParentPutOnParentAndChildUpdate(NEW_EM_START_END);
  }
  private void testOnlyOneParentPutOnParentAndChildUpdate(JPATestCase.StartEnd startEnd)
      throws Throwable {
    HasOneToOneJPA pojo = new HasOneToOneJPA();
    HasOneToOneParentJPA hasParent = new HasOneToOneParentJPA();
    PutPolicy policy = setupPutPolicy(pojo, hasParent, startEnd);
    try {
      startEnd.start();
      pojo = em.find(pojo.getClass(), pojo.getId());
      pojo.setStr("another val");
      pojo.getBook().setIsbn("88");
      pojo.getHasParent().setStr("blarg");
      pojo.getHasKeyPK().setStr("double blarg");
      startEnd.end();
    } finally {
      DatastoreServiceInterceptor.uninstall();
    }
    // 1 put for the parent update, 1 put for each child update
View Full Code Here

    testOnlyOneParentPutOnChildDelete(NEW_EM_START_END, expectedPutsOnChildDelete);
  }
  private void testOnlyOneParentPutOnChildDelete(JPATestCase.StartEnd startEnd,
                                                 int expectedPutsOnChildDelete)
      throws Throwable {
    HasOneToOneJPA pojo = new HasOneToOneJPA();
    HasOneToOneParentJPA hasParent = new HasOneToOneParentJPA();
    PutPolicy policy = setupPutPolicy(pojo, hasParent, startEnd);
    try {
      startEnd.start();
      pojo = em.find(pojo.getClass(), pojo.getId());
      pojo.setStr("another val");
      pojo.setBook(null);
      pojo.setHasParent(null);
      pojo.setHasKeyPK(null);
      startEnd.end();
    } finally {
      DatastoreServiceInterceptor.uninstall();
    }
View Full Code Here

TOP

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

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.