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

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


/**
* @author Max Ross <maxr@google.com>
*/
public class JPAPrimaryKeyTest extends JPATestCase {
  public void testLongPk() throws EntityNotFoundException {
    HasLongPkJPA pojo = new HasLongPkJPA();
    beginTxn();
    em.persist(pojo);
    commitTxn();

    assertNotNull(pojo.getId());
    Entity e = ds.get(KeyFactory.createKey(HasLongPkJPA.class.getSimpleName(), pojo.getId()));

    beginTxn();
    em.find(HasLongPkJPA.class, e.getKey().getId());
    em.find(HasLongPkJPA.class, e.getKey());
    em.find(HasLongPkJPA.class, KeyFactory.keyToString(e.getKey()));
View Full Code Here


    em.find(HasLongPkJPA.class, KeyFactory.keyToString(e.getKey()));
    commitTxn();
  }

  public void testLongPk_UserProvided() throws EntityNotFoundException {
    HasLongPkJPA pojo = new HasLongPkJPA();
    pojo.setId(33L);
    beginTxn();
    em.persist(pojo);
    commitTxn();
    // the fact that this doesn't throw an exception is the test
    ds.get(KeyFactory.createKey(HasLongPkJPA.class.getSimpleName(), 33));
View Full Code Here

    // the fact that this doesn't throw an exception is the test
    ds.get(KeyFactory.createKey(HasKeyPkJPA.class.getSimpleName(), 34));
  }

  public void testCannotChangeLongPk() {
    HasLongPkJPA pojo = new HasLongPkJPA();
    beginTxn();
    em.persist(pojo);
    commitTxn();
    beginTxn();
    pojo = em.find(HasLongPkJPA.class, pojo.getId());
    pojo.setId(88L);
    try {
      commitTxn();
      fail("expected exception");
    } catch (PersistenceException e) {
      // good
View Full Code Here

    commitTxn();
  }

  public void testUnencodedLongPk_BatchGet() throws EntityNotFoundException {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_allowed);
    HasLongPkJPA pojo = new HasLongPkJPA();
    beginTxn();
    pojo.setId(1L);
    em.persist(pojo);
    commitTxn();

    HasLongPkJPA pojo2 = new HasLongPkJPA();
    beginTxn();
    pojo2.setId(2L);
    em.persist(pojo2);
    commitTxn();

    assertNotNull(pojo.getId());
    assertNotNull(pojo2.getId());

    beginTxn();
    Query q = em.createQuery("select from " + HasLongPkJPA.class.getName() + " b where id = :ids");
    q.setParameter("ids", Utils.newArrayList(pojo.getId(), pojo2.getId()));
    List<HasLongPkJPA> pojos = (List<HasLongPkJPA>) q.getResultList();
    assertEquals(2, pojos.size());
    // we should preserve order but right now we don't
    Set<Long> pks = Utils.newHashSet(pojos.get(0).getId(), pojos.get(1).getId());
    assertEquals(pks, Utils.newHashSet(1L, 2L));
View Full Code Here

TOP

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

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.