Examples of DetachableJPA


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

  }

  public void testSimpleSerializeWithTxns()
      throws IOException, ClassNotFoundException, EntityNotFoundException {
    beginTxn();
    DetachableJPA pojo = new DetachableJPA();
    pojo.setVal("yar");
    Date now = new Date();
    pojo.setDate(now);
    em.persist(pojo);
    commitTxn();
    assertEquals(ObjectState.HOLLOW_PERSISTENT_NONTRANSACTIONAL, JDOHelper.getObjectState(pojo));
    assertTrue(Date.class.isAssignableFrom(pojo.getDate().getClass()));
    em.close(); // Detaches objects in L1 cache
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    em = emf.createEntityManager();
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));

    pojo = toBytesAndBack(pojo);

    assertEquals("yar", pojo.getVal());
    assertEquals(now, pojo.getDate());
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    beginTxn();
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    pojo.setVal("not yar");
    Date differentNow = new Date(now.getTime() + 1);
    pojo.setDate(differentNow);
    assertEquals(ObjectState.DETACHED_DIRTY, JDOHelper.getObjectState(pojo));
    pojo = em.merge(pojo);
    assertEquals(ObjectState.PERSISTENT_DIRTY, JDOHelper.getObjectState(pojo));
    commitTxn();
    assertEquals(ObjectState.HOLLOW_PERSISTENT_NONTRANSACTIONAL, JDOHelper.getObjectState(pojo));
    Entity e = ds.get(KeyFactory.createKey(DetachableJPA.class.getSimpleName(), pojo.getId()));
    assertEquals("not yar", e.getProperty("val"));
    assertEquals(differentNow, e.getProperty("date"));
  }
View Full Code Here

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

    assertEquals(differentNow, e.getProperty("date"));
  }

  public void testSimpleSerializeWithoutTxns() throws Exception {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
    DetachableJPA pojo = new DetachableJPA();
    pojo.setVal("yar");
    Date now = new Date();
    pojo.setDate(now);
    em.persist(pojo);
    assertEquals(ObjectState.HOLLOW_PERSISTENT_NONTRANSACTIONAL, JDOHelper.getObjectState(pojo));
    em.close(); // Detaches objects in L1 cache
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    assertEquals(Date.class, pojo.getDate().getClass());
    em = emf.createEntityManager();
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));

    pojo = toBytesAndBack(pojo);

    assertEquals("yar", pojo.getVal());
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    pojo.setVal("not yar");
    Date differentNow = new Date(now.getTime() + 1);
    pojo.setDate(differentNow);
    assertEquals(ObjectState.DETACHED_DIRTY, JDOHelper.getObjectState(pojo));
    em.merge(pojo);
    em.close(); // Detaches objects in L1 cache
    Entity e = ds.get(KeyFactory.createKey(DetachableJPA.class.getSimpleName(), pojo.getId()));
    assertEquals("not yar", e.getProperty("val"));
    assertEquals(differentNow, e.getProperty("date"));
  }
View Full Code Here

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

    assertEquals(differentNow, e.getProperty("date"));
  }

  public void testMergeAfterFetch() throws Exception {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
    DetachableJPA pojo = new DetachableJPA();
    pojo.setVal("yar");
    Date now = new Date();
    pojo.setDate(now);
    em.persist(pojo);
    em.close();
    em = emf.createEntityManager();
//    beginTxn();
//    pojo = em.find(DetachableJPA.class, pojo.getId());
    pojo = (DetachableJPA) em.createQuery("select from " + DetachableJPA.class.getName() + " b").getSingleResult();
//    commitTxn();
    em.close();
    em = emf.createEntityManager();
    assertEquals("yar", pojo.getVal());
    pojo.setVal("not yar");
    em.merge(pojo);
    em.close();
    Entity e = ds.get(KeyFactory.createKey(DetachableJPA.class.getSimpleName(), pojo.getId()));
    assertEquals("not yar", e.getProperty("val"));
  }
View Full Code Here

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

    assertEquals(KeyFactory.stringToKey(pojo.getId()), e.getKey().getParent());
  }
 
  public void testDeleteDetachedObject_NoTxn() {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_not_allowed);
    DetachableJPA pojo = new DetachableJPA();
    pojo.setVal("yar");
    Date now = new Date();
    pojo.setDate(now);
    em.persist(pojo);
    em.close(); // Detaches objects in L1 cache
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    em = emf.createEntityManager();
    pojo = em.find(pojo.getClass(), pojo.getId());
    assertEquals(ObjectState.HOLLOW_PERSISTENT_NONTRANSACTIONAL, JDOHelper.getObjectState(pojo));
    em.close();
    em = emf.createEntityManager();
    pojo = em.merge(pojo);
    // this is wrong and it will start to fail when we upgrade to DN 2.0
View Full Code Here

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

//    assertNull(em.find(pojo.getClass(), pojo.getId()));
  }
 
  public void testDeleteDetachedObject_Txn() {
    beginTxn();
    DetachableJPA pojo = new DetachableJPA();
    pojo.setVal("yar");
    Date now = new Date();
    pojo.setDate(now);
    em.persist(pojo);
    commitTxn();
    Long id = pojo.getId();
    beginTxn();
    pojo = em.find(pojo.getClass(), pojo.getId());
    commitTxn();
    beginTxn();
    pojo = em.merge(pojo);
    em.remove(pojo);
    assertEquals(ObjectState.PERSISTENT_DELETED, JDOHelper.getObjectState(pojo));
    commitTxn();
    beginTxn();
    assertNull(em.find(pojo.getClass(), id));
    rollbackTxn();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.