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

Examples of com.google.appengine.datanucleus.test.jpa.UnidirectionalOneToManySubclassesJPA.SuperChild


    // insertion
    SubParentWithSuperChild parent = new SubParentWithSuperChild();
    parent.setSuperParentString("super parent string");
    parent.setSubParentString("sub parent string");

    SuperChild superChild = new SuperChild();
    superChild.setAString("a string");
    parent.getSuperParentSuperChildren().add(superChild);

    beginTxn();
    em.persist(parent);
    commitTxn();
    Entity parentEntity =
        ds.get(KeyFactory.createKey(kindForClass(parent.getClass()), parent.getId()));
    Entity superParentSuperChildEntity = ds.get(superChild.getId());
    assertEquals(3, parentEntity.getProperties().size());
    assertEquals("super parent string", parentEntity.getProperty("superParentString"));
    assertEquals("sub parent string", parentEntity.getProperty("subParentString"));
    assertEquals(Collections.singletonList(superParentSuperChildEntity.getKey()), parentEntity.getProperty("superChildren"));

    assertEquals(1, superParentSuperChildEntity.getProperties().size());
    assertEquals("a string", superParentSuperChildEntity.getProperty("aString"));

    // lookup
    beginTxn();
    parent = em.find(parent.getClass(), parent.getId());
    assertEquals("super parent string", parent.getSuperParentString());
    assertEquals("sub parent string", parent.getSubParentString());
    assertEquals(1, parent.getSuperParentSuperChildren().size());
    assertEquals(superChild.getId(), parent.getSuperParentSuperChildren().get(0).getId());
    commitTxn();

    beginTxn();
    superChild = em.find(superChild.getClass(), superChild.getId());
    assertEquals("a string", superChild.getAString());
    commitTxn();

    // cascade delete
    beginTxn();
    em.remove(em.merge(parent));
    commitTxn();

    assertEquals(0, countForClass(parent.getClass()));
    assertEquals(0, countForClass(superChild.getClass()));
  }
View Full Code Here


  public void testSuperParentWithSuperChild() throws EntityNotFoundException {
    // insertion
    SuperParentWithSuperChild parent = new SuperParentWithSuperChild();
    parent.setSuperParentString("super parent string");

    SuperChild superChild = new SuperChild();
    superChild.setAString("a string");
    parent.getSuperParentSuperChildren().add(superChild);

    beginTxn();
    em.persist(parent);
    commitTxn();
    Entity parentEntity =
        ds.get(KeyFactory.createKey(kindForClass(parent.getClass()), parent.getId()));
    Entity superParentSuperChildEntity = ds.get(superChild.getId());
    assertEquals(2, parentEntity.getProperties().size());
    assertEquals("super parent string", parentEntity.getProperty("superParentString"));
    assertEquals(Collections.singletonList(superParentSuperChildEntity.getKey()), parentEntity.getProperty("superChildren"));
    assertEquals(1, superParentSuperChildEntity.getProperties().size());
    assertEquals("a string", superParentSuperChildEntity.getProperty("aString"));

    // lookup
    beginTxn();
    parent = em.find(parent.getClass(), parent.getId());
    assertEquals("super parent string", parent.getSuperParentString());
    assertEquals(1, parent.getSuperParentSuperChildren().size());
    assertEquals(superChild.getId(), parent.getSuperParentSuperChildren().get(0).getId());
    commitTxn();

    beginTxn();
    superChild = em.find(superChild.getClass(), superChild.getId());
    assertEquals("a string", superChild.getAString());
    commitTxn();

    // cascade delete
    beginTxn();
    em.remove(em.merge(parent));
    commitTxn();

    assertEquals(0, countForClass(parent.getClass()));
    assertEquals(0, countForClass(superChild.getClass()));
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jpa.UnidirectionalOneToManySubclassesJPA.SuperChild

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.