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

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


  public void testInsert_IdGen() {
    Entity bookEntity = Book.newBookEntity("max", "123456", "manifesto");
    ds.put(bookEntity);
    Key bookKey = bookEntity.getKey();
    HasStringAncestorStringPkJPA ha = new HasStringAncestorStringPkJPA(KeyFactory.keyToString(bookKey));
    beginTxn();
    em.persist(ha);
    commitTxn();
    Key keyWithParent = KeyFactory.stringToKey(ha.getId());
    assertEquals(bookKey, keyWithParent.getParent());
    // now we'll issue an ancestor query directly against the datastore and see
    // if our object comes back.
    Query q = new Query(ha.getClass().getSimpleName());
    q.setAncestor(bookKey);
    Entity result = ds.prepare(q).asSingleEntity();
    assertEquals(bookKey, result.getKey().getParent());
  }
View Full Code Here


  public void testInsert_NamedKey() {
    Entity bookEntity = Book.newBookEntity("parent named key", "max", "123456", "manifesto");
    ds.put(bookEntity);
    Key bookKey = bookEntity.getKey();
    Key key = new Entity(HasStringAncestorStringPkJPA.class.getSimpleName(), "named key", bookKey).getKey();
    HasStringAncestorStringPkJPA ha = new HasStringAncestorStringPkJPA(null, KeyFactory.keyToString(key));
    beginTxn();
    em.persist(ha);
    commitTxn();
    Key keyWithParent = KeyFactory.stringToKey(ha.getId());
    assertEquals(bookKey, keyWithParent.getParent());
    // now we'll issue an ancestor query directly against the datastore and see
    // if our object comes back.
    Query q = new Query(ha.getClass().getSimpleName());
    q.setAncestor(bookKey);
    Entity result = ds.prepare(q).asSingleEntity();
    assertEquals(bookKey, result.getKey().getParent());
    assertEquals("named key", result.getKey().getName());
    assertEquals("parent named key", result.getKey().getParent().getName());
View Full Code Here

  public void testInsert_SetAncestorAndPk() {
    Entity bookEntity = Book.newBookEntity("parent named key", "max", "123456", "manifesto");
    ds.put(bookEntity);
    Key bookKey = bookEntity.getKey();
    HasStringAncestorStringPkJPA ha = new HasStringAncestorStringPkJPA(KeyFactory.keyToString(bookKey),
        TestUtils.createKeyString(HasStringAncestorStringPkJPA.class, "named key"));
    beginTxn();
    em.persist(ha);
    try {
      commitTxn();
View Full Code Here

    ds.put(bookEntity);
    Entity hasAncestorEntity = new Entity(HasStringAncestorStringPkJPA.class.getSimpleName(), bookEntity.getKey());
    ds.put(hasAncestorEntity);

    beginTxn();
    HasStringAncestorStringPkJPA ha = em.find(HasStringAncestorStringPkJPA.class, KeyFactory.keyToString(hasAncestorEntity.getKey()));
    assertEquals(KeyFactory.keyToString(bookEntity.getKey()), ha.getAncestorId());
    commitTxn();
  }
View Full Code Here

    Entity hasAncestorEntity =
        new Entity(HasStringAncestorStringPkJPA.class.getSimpleName(), "named key", bookEntity.getKey());
    ds.put(hasAncestorEntity);

    beginTxn();
    HasStringAncestorStringPkJPA ha = em.find(HasStringAncestorStringPkJPA.class, KeyFactory.keyToString(hasAncestorEntity.getKey()));
    assertEquals(KeyFactory.keyToString(bookEntity.getKey()), ha.getAncestorId());
    assertEquals("named key", KeyFactory.stringToKey(ha.getId()).getName());
    assertEquals("parent named key", KeyFactory.stringToKey(ha.getId()).getParent().getName());
    commitTxn();
  }
View Full Code Here

    assertEquals("parent named key", KeyFactory.stringToKey(ha.getId()).getParent().getName());
    commitTxn();
  }

  public void testInsertWithNullAncestor() {
    HasStringAncestorStringPkJPA ha = new HasStringAncestorStringPkJPA(null);
    beginTxn();
    em.persist(ha);
    commitTxn();
    Key keyWithParent = KeyFactory.stringToKey(ha.getId());
    assertNull(keyWithParent.getParent());
  }
View Full Code Here

    ds.get(KeyFactory.stringToKey(parent.getId()));
  }

  public void testOneToOnePersistChildWithAncestorCascadeAll() throws EntityNotFoundException {
    HasOneToOnesWithDifferentCascadesJPA parent = new HasOneToOnesWithDifferentCascadesJPA();
    HasStringAncestorStringPkJPA child = new HasStringAncestorStringPkJPA();
    parent.setCascadeAllChild(child);

    beginTxn();
    em.persist(parent);
    commitTxn();

    assertEquals(parent.getId(), child.getAncestorId());

    Entity childEntity = ds.get(KeyFactory.stringToKey(child.getId()));
    assertKeyParentEquals(parent.getId(), childEntity, childEntity.getKey());

    ds.get(KeyFactory.stringToKey(parent.getId()));
  }
View Full Code Here

    HasOneToOnesWithDifferentCascadesJPA anotherParent = new HasOneToOnesWithDifferentCascadesJPA();
    beginTxn();
    em.persist(anotherParent);
    commitTxn();

    HasStringAncestorStringPkJPA child = new HasStringAncestorStringPkJPA(anotherParent.getId());
    parent.setCascadeAllChild(child);

    beginTxn();
    em.persist(parent);
    try {
View Full Code Here

TOP

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

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.