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

Examples of com.google.appengine.datanucleus.test.jpa.SubclassesJPA.ChildEmbeddedInTablePerClass


    assertEquals("overridden", e.getProperty("overridden_string"));
    assertFalse(e.hasProperty("overriddenString"));
  }

  public void testEmbedded_Child() throws Exception {
    ChildEmbeddedInTablePerClass child = new ChildEmbeddedInTablePerClass();
    child.setAString("aString");
    child.setBString("bString");
    IsEmbeddedWithEmbeddedSuperclass embedded = new IsEmbeddedWithEmbeddedSuperclass();
    embedded.setVal0("embedded val 0");
    embedded.setVal1("embedded val 1");
    child.setEmbedded(embedded);
    SubclassesJPA.IsEmbeddedBase embeddedBase = new SubclassesJPA.IsEmbeddedBase();
    embeddedBase.setVal0("embedded base val 0");
    child.setEmbeddedBase(embeddedBase);
    IsEmbeddedWithEmbeddedSuperclass2 embedded2 = new IsEmbeddedWithEmbeddedSuperclass2();
    embedded2.setVal2("embedded val 2");
    embedded2.setVal3("embedded val 3");
    child.setEmbedded2(embedded2);
    SubclassesJPA.IsEmbeddedBase2
        embeddedBase2 = new SubclassesJPA.IsEmbeddedBase2();
    embeddedBase2.setVal2("embedded base val 2");
    child.setEmbeddedBase2(embeddedBase2);
    beginTxn();
    em.persist(child);
    commitTxn();
    Key key = KeyFactory.createKey(kindForClass(child.getClass()), child.getId());
    Entity e = ds.get(key);
    assertEquals("aString", e.getProperty("aString"));
    assertEquals("bString", e.getProperty("bString"));
    assertEquals("embedded val 0", e.getProperty("val0"));
    assertEquals("embedded val 1", e.getProperty("val1"));
    assertEquals("embedded base val 0", e.getProperty("VAL0"));
    assertEquals("embedded val 2", e.getProperty("val2"));
    assertEquals("embedded val 3", e.getProperty("val3"));
    assertEquals("embedded base val 2", e.getProperty("VAL2"));
    em.close();
    em = emf.createEntityManager();
    beginTxn();
    child = em.find(child.getClass(), child.getId());
    assertEmbeddedChildContents(child);
    commitTxn();
    em.close();
    em = emf.createEntityManager();
    beginTxn();
    Query q = em.createQuery("select from " + child.getClass().getName() + " b where embedded.val1 = :p "
      + "order by embedded.val1 desc, embedded.val0 desc, embeddedBase.val0 desc, "
      + "embedded2.val2 desc, embedded2.val3 desc, embeddedBase2.val2");
    q.setParameter("p", "embedded val 1");
    child = (ChildEmbeddedInTablePerClass) q.getSingleResult();
    assertEmbeddedChildContents(child);

    q = em.createQuery("select from " + child.getClass().getName() + " b where embedded.val0 = :p "
      + "order by embedded.val1 desc, embedded.val0 desc, embeddedBase.val0 desc, "
      + "embedded2.val2 desc, embedded2.val3 desc, embeddedBase2.val2");
    q.setParameter("p", "embedded val 0");
    child = (ChildEmbeddedInTablePerClass) q.getSingleResult();
    assertEmbeddedChildContents(child);

    q = em.createQuery("select from " + child.getClass().getName() + " b where embeddedBase.val0 = :p "
      + "order by embedded.val1 desc, embedded.val0 desc, embeddedBase.val0 desc, "
      + "embedded2.val2 desc, embedded2.val3 desc, embeddedBase2.val2");
    q.setParameter("p", "embedded base val 0");
    child = (ChildEmbeddedInTablePerClass) q.getSingleResult();
    assertEmbeddedChildContents(child);

    q = em.createQuery("select from " + child.getClass().getName() + " b where embedded2.val2 = :p "
      + "order by embedded.val1 desc, embedded.val0 desc, embeddedBase.val0 desc, "
      + "embedded2.val2 desc, embedded2.val3 desc, embeddedBase2.val2");
    q.setParameter("p", "embedded val 2");
    child = (ChildEmbeddedInTablePerClass) q.getSingleResult();
    assertEmbeddedChildContents(child);

    q = em.createQuery("select from " + child.getClass().getName() + " b where embedded2.val3 = :p "
      + "order by embedded.val1 desc, embedded.val0 desc, embeddedBase.val0 desc, "
      + "embedded2.val2 desc, embedded2.val3 desc, embeddedBase2.val2");
    q.setParameter("p", "embedded val 3");
    child = (ChildEmbeddedInTablePerClass) q.getSingleResult();
    assertEmbeddedChildContents(child);

    q = em.createQuery("select from " + child.getClass().getName() + " b where embeddedBase2.val2 = :p "
      + "order by embedded.val1 desc, embedded.val0 desc, embeddedBase.val0 desc, "
      + "embedded2.val2 desc, embedded2.val3 desc, embeddedBase2.val2");
    q.setParameter("p", "embedded base val 2");
    child = (ChildEmbeddedInTablePerClass) q.getSingleResult();
    assertEmbeddedChildContents(child);

    q = em.createQuery("select embedded.val1, embedded.val0, embeddedBase.val0, embedded2.val2, embedded2.val3, embeddedBase2.val2 from " +
                    child.getClass().getName() + " b where embeddedBase2.val2 = :p");
    q.setParameter("p", "embedded base val 2");

    Object[] result = (Object[]) q.getSingleResult();
    assertEquals("embedded val 1", result[0]);
    assertEquals("embedded val 0", result[1]);
View Full Code Here


    assertEquals("embedded val 1", parentWithEmbedded.getEmbedded().getVal1());
    assertEquals("embedded base val 0", parentWithEmbedded.getEmbeddedBase().getVal0());
  }

  private void assertEmbeddedChildContents(Object obj) {
    ChildEmbeddedInTablePerClass child = (ChildEmbeddedInTablePerClass) obj;
    assertEquals("bString", child.getBString());
    assertEquals("embedded val 2", child.getEmbedded2().getVal2());
    assertEquals("embedded val 3", child.getEmbedded2().getVal3());
    assertEquals("embedded base val 2", child.getEmbeddedBase2().getVal2());
    assertEmbeddedParentContents(child);
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jpa.SubclassesJPA.ChildEmbeddedInTablePerClass

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.