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

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


      // good
    }
  }

  public void testEmbedded_Parent() throws Exception {
    TablePerClassParentWithEmbedded parent = new TablePerClassParentWithEmbedded();
    parent.setAString("aString");
    IsEmbeddedWithEmbeddedSuperclass embedded = new IsEmbeddedWithEmbeddedSuperclass();
    embedded.setVal0("embedded val 0");
    embedded.setVal1("embedded val 1");
    parent.setEmbedded(embedded);
    SubclassesJPA.IsEmbeddedBase
        embeddedBase = new SubclassesJPA.IsEmbeddedBase();
    embeddedBase.setVal0("embedded base val 0");
    parent.setEmbeddedBase(embeddedBase);
    beginTxn();
    em.persist(parent);
    commitTxn();
    Key key = KeyFactory.createKey(kindForClass(parent.getClass()), parent.getId());
    Entity e = ds.get(key);
    assertEquals("aString", e.getProperty("aString"));
    assertEquals("embedded val 0", e.getProperty("val0"));
    assertEquals("embedded val 1", e.getProperty("val1"));
    assertEquals("embedded base val 0", e.getProperty("VAL0"));
    em.close();
    em = emf.createEntityManager();
    beginTxn();
    parent = em.find(parent.getClass(), parent.getId());
    assertEmbeddedParentContents(parent);
    commitTxn();
    em.close();
    em = emf.createEntityManager();
    beginTxn();
    Query q = em.createQuery("select from " + parent.getClass().getName() + " b where embedded.val1 = :p "
      + "order by embedded.val1 desc, embedded.val0 asc, embeddedBase.val0 desc");
    q.setParameter("p", "embedded val 1");
    parent = (TablePerClassParentWithEmbedded) q.getSingleResult();
    assertEmbeddedParentContents(parent);

    q = em.createQuery("select from " + parent.getClass().getName() + " b where embedded.val0 = :p "
      + "order by embedded.val1 desc, embedded.val0 asc, embeddedBase.val0 desc");
    q.setParameter("p", "embedded val 0");
    parent = (TablePerClassParentWithEmbedded) q.getSingleResult();
    assertEmbeddedParentContents(parent);

    q = em.createQuery("select from " + parent.getClass().getName() + " b where embeddedBase.val0 = :p "
      + "order by embedded.val1 desc, embedded.val0 asc, embeddedBase.val0 desc");
    q.setParameter("p", "embedded base val 0");
    parent = (TablePerClassParentWithEmbedded) q.getSingleResult();
    assertEmbeddedParentContents(parent);

    q = em.createQuery("select embedded.val1, embedded.val0, embeddedBase.val0 from " +
                    parent.getClass().getName() + " b where embeddedBase.val0 = :p "
      + "order by embedded.val1 desc, embedded.val0 asc, embeddedBase.val0 desc");
    q.setParameter("p", "embedded base val 0");

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


  // This is absurd, but if the signature of this method and the one below
  // refers to the actual type we want the runtime enhancer gets totally
  // confused. 
  private void assertEmbeddedParentContents(Object obj) {
    TablePerClassParentWithEmbedded parentWithEmbedded = (TablePerClassParentWithEmbedded) obj;
    assertEquals("aString", parentWithEmbedded.getAString());
    assertEquals("embedded val 0", parentWithEmbedded.getEmbedded().getVal0());
    assertEquals("embedded val 1", parentWithEmbedded.getEmbedded().getVal1());
    assertEquals("embedded base val 0", parentWithEmbedded.getEmbeddedBase().getVal0());
  }
View Full Code Here

TOP

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

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.