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

Examples of com.google.appengine.datanucleus.test.jpa.SingleTableInheritanceJPA.Child12


    Assert.assertTrue(c11.getChild11Manys().isEmpty());
    startEnd.end();

    //  create Child12
    Child11Many c12m = new Child11Many("Child11ManyStr");
    Child12 c12 = newChild12(startEnd, "Child12", null, 112, null, new Embedded1("Child12Embedded1"), c12m);
    Long c12Id = c12.getId();
    String c12mId = c12m.getId();
    Key c12Key = KeyFactory.createKey(PARENT_KIND, c12Id);
   
    //  verify Child12 entity
    Entity c12e = ds.get(c12Key);
    Assert.assertEquals(c12Key, c12e.getKey());
    Assert.assertEquals("C12", c12e.getProperty("DTYPE"));
    Assert.assertEquals("Child12", c12e.getProperty("parentStr"));
    Assert.assertTrue(c12e.hasProperty("child11Integer"));
    Assert.assertNull(c12e.getProperty("child11Integer"));
    Assert.assertEquals(112, ((Long) c12e.getProperty("child12Int")).intValue());
    Assert.assertTrue(c12e.hasProperty("value"));
    Assert.assertEquals(0d, c12e.getProperty("value"));
    Assert.assertEquals("Child12Embedded1", c12e.getProperty("string"));
    Assert.assertTrue(c12e.hasProperty("child11Manys"));
    Assert.assertEquals(1, ((List<Key>)c12e.getProperty("child11Manys")).size());
    Assert.assertEquals(KeyFactory.stringToKey(c12mId), ((List<Key>)c12e.getProperty("child11Manys")).get(0));
    Assert.assertEquals(7, c12e.getProperties().size());
   
    //  verify Child12 object
    startEnd.start();
    c12 = em.find(Child12.class, c12Id);
    Assert.assertEquals(c12Id, c12.getId());
    Assert.assertEquals("Child12", c12.getParentStr());
    Assert.assertNull(c12.getChild11Integer());
    Assert.assertEquals(112, c12.getChild12Int());
    Assert.assertNotNull(c12.getEmbedded1());
    Assert.assertEquals("Child12Embedded1", c12.getEmbedded1().getStr());
    Assert.assertNotNull(c12.getChild11Manys());
    Assert.assertEquals(1, c12.getChild11Manys().size());
    Assert.assertEquals("Child11ManyStr", c12.getChild11Manys().get(0).getStr());
    startEnd.end();
   
    //  create Child21
    Child21 c21 = newChild21(startEnd, null, 21L);   
    Long c21Id = c21.getId();
View Full Code Here


    testUpdateDependent(NEW_EM_START_END);
  }
  @SuppressWarnings("unchecked")
  private void testUpdateDependent(StartEnd startEnd) throws Exception {
    //  create Child12
    Child12 c12_0 = newChild12(startEnd, "A", null, 12, null, new Embedded1("Child12Embedded1(1)"));
    Long c12_0Id = c12_0.getId();
    Key c12_0key = KeyFactory.createKey(PARENT_KIND, c12_0Id);
   
    //  add a Child11Many to Child12
    startEnd.start();
    c12_0 = em.find(Child12.class, c12_0Id);
    Assert.assertTrue(c12_0.getChild11Manys().isEmpty());
    Assert.assertEquals("Child12Embedded1(1)",c12_0.getEmbedded1().getStr());
    Child11Many c12m_0 = new Child11Many("Child12Embedded1(1)/Child11ManyStr(1)");
    c12_0.getChild11Manys().add(c12m_0);
    startEnd.end();
    String c12m_0Id = c12m_0.getId();
   
    // more objects to prove we update and delete the correct one
    newChild12(startEnd, "B", null, 121, null, new Embedded1("Child12Embedded1(2)"), new Child11Many("Child12Embedded1(2)/Child11ManyStr(1)"));
   
    Assert.assertEquals(2, countForKind(PARENT_KIND));
    Assert.assertEquals(2, countForClass(Child11Many.class));
   
    //  check the key of  Child11Many in the Entity
    Entity c12e = ds.get(c12_0key);
    Assert.assertEquals(KeyFactory.stringToKey(c12m_0Id), ((List<Key>)c12e.getProperty("child11Manys")).get(0));
   
    //  query the first Child12
    startEnd.start();
    Query q = em.createQuery("select c from " + Child12.class.getName() + " c order by parentStr");
    q.setFirstResult(0);
    q.setMaxResults(1);
    List<Child12> r = (List<Child12>)q.getResultList();
    Assert.assertEquals(1, r.size());
    Assert.assertEquals(c12_0Id, r.get(0).getId());
    Assert.assertEquals("Child12Embedded1(1)", r.get(0).getEmbedded1().getStr());
    Assert.assertEquals("A", c12_0.getParentStr());
    Child11Many c12m_1 = new Child11Many("Child12Embedded1(1)/Child11ManyStr(2)");
    r.get(0).getChild11Manys().add(c12m_1);
    startEnd.end();
    String c12m_1Id = c12m_1.getId();
   
    Assert.assertEquals(2, countForKind(PARENT_KIND));
    Assert.assertEquals(3, countForClass(Child11Many.class));

    c12e = ds.get(c12_0key);
    Assert.assertEquals(KeyFactory.stringToKey(c12m_0Id), ((List<Key>)c12e.getProperty("child11Manys")).get(0));
    Assert.assertEquals(KeyFactory.stringToKey(c12m_1Id), ((List<Key>)c12e.getProperty("child11Manys")).get(1));

    startEnd.start();
    c12_0 = (Child12)em.find(Child12.class, c12_0Id);
    c12_0.getChild11Manys().remove(0);
    startEnd.end();

    c12e = ds.get(c12_0key);
    Assert.assertEquals(1, ((List<Key>)c12e.getProperty("child11Manys")).size());
    Assert.assertEquals(KeyFactory.stringToKey(c12m_1Id), ((List<Key>)c12e.getProperty("child11Manys")).get(0));
View Full Code Here

  @SuppressWarnings("unchecked")
  private void testQueryChildren(StartEnd startEnd) {
    Child11 c11_0 = newChild11(startEnd, "Child11", 11);
    Long c11Id = c11_0.getId();
   
    Child12 c12_0 = newChild12(startEnd, "Child12", 111, 112, null, new Embedded1("Child12Embedded1"));
    Long c12_0Id = c12_0.getId();

    newChild12(startEnd, "Child12", 111, 112, null, null);

    startEnd.start();
    Query q = em.createQuery("select p from " + Parent.class.getName() + " p where id = :id");
    q.setParameter("id", c11Id);
    List<Child11> r11 = (List<Child11>)q.getResultList();
    Assert.assertEquals(1, r11.size());
    c11_0 = r11.get(0);
    Assert.assertEquals(c11Id, c11_0.getId());
    Assert.assertEquals("Child11", c11_0.getParentStr());
    Assert.assertEquals(new Integer(11), c11_0.getChild11Integer());
    startEnd.end();
   
    startEnd.start();
    q = em.createQuery("select c from " + Child11.class.getName() + " c where child12Int > 0");
    try {
      q.getResultList();
      fail("expected JDOFatalUserException");
    } catch (Exception ex) {
      // good Child11 does not have a property child12Int
    } finally {
      startEnd.end();
    }

    startEnd.start();
    q = em.createQuery("select c from " + Child12.class.getName() + " c where embedded1.str = :str");
    q.setParameter("str", "Child12Embedded1");
    List<Child12> r12 = (List<Child12>)q.getResultList();
    Assert.assertEquals(1, r12.size());
    c12_0 = r12.get(0);
    Assert.assertEquals(c12_0Id, c12_0.getId());
    Assert.assertEquals("Child12Embedded1", c12_0.getEmbedded1().getStr());
    startEnd.end();
   
    startEnd.start();
    q = em.createQuery("select c from " + Child11.class.getName() + " c where parentStr = :str");
    q.setParameter("str", "Child12");
View Full Code Here

  @SuppressWarnings("unchecked")
  private void testQueryParentAndChildren(StartEnd startEnd) {
    Child11 c11 = newChild11(startEnd, "A", 111);
    Long c11Id = c11.getId();

    Child12 c12 = newChild12(startEnd, "B", 112, 211, 8.15f, new Embedded1("Embedded1"),
  new Child11Many("Child12(2)/Child11Many"));
    Long c12Id = c12.getId();
   
    Parent p = newParent(startEnd, "C");
    Long pId = p.getId();

    Child21 c21 = newChild21(startEnd, "D", 121L);
    Long c21Id = c21.getId();

    Child22 c22 = newChild22(startEnd, "E", "Child22", Boolean.TRUE, null);
    Long c22Id = c22.getId();
   
    Assert.assertEquals(5, countForKind(PARENT_KIND));
   
    if (em.isOpen()) {
      em.close();
    }
    em = emf.createEntityManager();
   
    startEnd.start();
    Query q = em.createQuery("select p from " + Parent.class.getName() + " p order by parentStr desc");
    List<Parent> r = (List<Parent>)q.getResultList();
    Assert.assertEquals(5, r.size());

    c22 = (Child22)r.get(0);
    Assert.assertEquals(c22Id, c22.getId());
    Assert.assertEquals("E", c22.getParentStr());
    Assert.assertEquals("Child22", c22.getChild22Str());
    Assert.assertEquals(Boolean.TRUE, c22.getValue());

    c21 = (Child21)r.get(1);
    Assert.assertEquals(c21Id, c21.getId());
    Assert.assertEquals("D", c21.getParentStr());
    Assert.assertEquals(121L, c21.getChild21Long());

    p = r.get(2);
    Assert.assertEquals(pId, p.getId());
    Assert.assertEquals("C", p.getParentStr());
   
    c12 = (Child12)r.get(3);
    Assert.assertEquals(c12Id, c12.getId());
    Assert.assertEquals("B", c12.getParentStr());
    Assert.assertEquals(new Integer(112), c12.getChild11Integer());
    Assert.assertEquals(211, c12.getChild12Int());
    Assert.assertEquals(8.15f, c12.getValue());
    Assert.assertEquals("Embedded1", c12.getEmbedded1().getStr());
    Assert.assertEquals(1, c12.getChild11Manys().size());

    c11 = (Child11)r.get(4);
    Assert.assertEquals(c11Id, c11.getId());
    Assert.assertEquals("A", c11.getParentStr());
    Assert.assertEquals(new Integer(111), c11.getChild11Integer());
    startEnd.end();
   
    startEnd.start();
    q = em.createQuery("select c from " + Child11.class.getName() + " c where child11Integer >= 111");
    r = (List<Parent>)q.getResultList();
    Assert.assertEquals(2, r.size());
    startEnd.end();
   
    startEnd.start();

    q = em.createQuery("select c from " + Child12.class.getName() + " c where value >= 8.0");
    r = (List<Parent>)q.getResultList();
    Assert.assertEquals(1, r.size());
    Assert.assertEquals(c12Id, r.get(0).getId());
    c12 = (Child12)r.get(0);
    Assert.assertEquals("B", c12.getParentStr());
    Assert.assertEquals(new Integer(112), c12.getChild11Integer());
    Assert.assertEquals(211, c12.getChild12Int());
    Assert.assertEquals(8.15f, c12.getValue());
    Assert.assertEquals("Embedded1", c12.getEmbedded1().getStr());
    Assert.assertEquals(1, c12.getChild11Manys().size());
    startEnd.end();

    startEnd.start();
    q = em.createQuery("select c from " + Child22.class.getName() + " c where value = true");
    r = (List<Parent>)q.getResultList();
View Full Code Here

  private void testQueryHierarchy(StartEnd startEnd) {
   
    Child11 c11 = newChild11(startEnd, "A", 111);
    Long c11Id = c11.getId();

    Child12 c12 = newChild12(startEnd, "A", 211, 112, 8.15f, null);
    Long c12_0_Id = c12.getId();
   
    Parent p = newParent(startEnd, "A");
    Long pId = p.getId();

    c12 = newChild12(startEnd, "B", 2211, 2112, 47.11f, null);
    Long c12_1_Id = c12.getId();
   
    startEnd.start();
    Query q = em.createQuery("select p from " + Parent.class.getName() + " p where parentStr = 'A'");
    List<Parent> r = (List<Parent>)q.getResultList();
    Assert.assertEquals(3, r.size());
View Full Code Here

    c11 = (Child11) em.find(Child11.class, c11Id);
    Assert.assertEquals("Child11", c11.getParentStr());
    Assert.assertEquals(new Integer(211), c11.getChild11Integer());
    startEnd.end();

    Child12 c12 = newChild12(startEnd, null, null, 0, null, null);
    Long c12Id = c12.getId();

    Assert.assertEquals(2, countForKind(PARENT_KIND));

    startEnd.start();
    em.remove(em.find(Child11.class, c11Id));
    startEnd.end();
   
    Assert.assertEquals(1, countForKind(PARENT_KIND));
   
    startEnd.start();
    c12 = (Child12) em.find(Child12.class, c12Id);
    Assert.assertEquals(c12Id, c12.getId());
    startEnd.end();
  }
View Full Code Here

    makePersistent(c11, startEnd);
    return c11;
  }
 
  private Child12 newChild12(StartEnd startEnd, String parentStr, Integer child11Integer, int child12Int, Float value, Embedded1 embedded1, Child11Many... child11Many) {
    Child12 c12 = new Child12();
    c12.setParentStr(parentStr);
    c12.setChild11Integer(child11Integer);
    c12.setChild12Int(child12Int);
    c12.setEmbedded1(embedded1);
    if (value != null) {
      c12.setValue(value);
    }
    if (child11Many != null) {
      for (Child11Many c : child11Many) {
        c12.getChild11Manys().add(c);
      }
    }
    makePersistent(c12, startEnd);
    return c12;
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jpa.SingleTableInheritanceJPA.Child12

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.