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

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


      // Persist Side B
      UnownedJPAManyToManySideB b = new UnownedJPAManyToManySideB();
      em.persist(b);

      // Create and persist Side A with another Side B, plus the existing Side B
      UnownedJPAManyToManySideA a = new UnownedJPAManyToManySideA();
      UnownedJPAManyToManySideB b2 = new UnownedJPAManyToManySideB();
      b2.getAs().add(a);
      a.getBs().add(b2);
      a.getBs().add(b);
      b.getAs().add(a);
      em.persist(b2);
      em.persist(a);
    } catch (Exception e) {
      NucleusLogger.GENERAL.error("Exception in persist", e);
      fail("Exception in test : " + e.getMessage());
      return;
    } finally {
      if (em.getTransaction().isActive()) {
        em.getTransaction().rollback();
      }
      em.close();
    }
    if (emf.getCache() != null) {
      emf.getCache().evictAll();
    }

    em = emf.createEntityManager();
    try {
      Query qa = em.createQuery("SELECT a FROM UnownedJPAManyToManySideA a");
      List<UnownedJPAManyToManySideA> results1 = qa.getResultList();
      assertNotNull(results1);
      assertEquals("Incorrect number of side A", 1, results1.size());
      UnownedJPAManyToManySideA a = results1.iterator().next();
      Set<UnownedJPAManyToManySideB> bs = a.getBs();
      assertNotNull(bs);
      assertEquals("Incorrect number of side B for A", 2, bs.size());

      Query qb = em.createQuery("SELECT b FROM UnownedJPAManyToManySideB b");
      List<UnownedJPAManyToManySideB> results2 = qb.getResultList();
View Full Code Here


  public void testPersistAThenRelation() throws Exception {
    EntityManager em = emf.createEntityManager();
    try {
      // Persist Side A
      UnownedJPAManyToManySideA a = new UnownedJPAManyToManySideA();
      em.persist(a);

      // Create and persist Side B with Side A, plus another Side B
      UnownedJPAManyToManySideB b = new UnownedJPAManyToManySideB();
      b.getAs().add(a);
      a.getBs().add(b);
      em.persist(b);

      UnownedJPAManyToManySideB b2 = new UnownedJPAManyToManySideB();
      b2.getAs().add(a);
      a.getBs().add(b2);
      em.persist(b2);
    } catch (Exception e) {
      NucleusLogger.GENERAL.error("Exception in persist", e);
      fail("Exception in test : " + e.getMessage());
      return;
    } finally {
      if (em.getTransaction().isActive()) {
        em.getTransaction().rollback();
      }
      em.close();
    }
    if (emf.getCache() != null) {
      emf.getCache().evictAll();
    }

    em = emf.createEntityManager();
    try {
      Query qa = em.createQuery("SELECT a FROM UnownedJPAManyToManySideA a");
      List<UnownedJPAManyToManySideA> results1 = qa.getResultList();
      assertNotNull(results1);
      assertEquals("Incorrect number of side A", 1, results1.size());
      UnownedJPAManyToManySideA a = results1.iterator().next();
      Set<UnownedJPAManyToManySideB> bs = a.getBs();
      assertNotNull(bs);
      assertEquals("Incorrect number of side B for A", 2, bs.size());

      Query qb = em.createQuery("SELECT b FROM UnownedJPAManyToManySideB b");
      List<UnownedJPAManyToManySideB> results2 = qb.getResultList();
View Full Code Here

  public void testPersistInOneStep() throws Exception {
    EntityManager em = emf.createEntityManager();
    try {
      // Persist Side A
      UnownedJPAManyToManySideB b = new UnownedJPAManyToManySideB();
      UnownedJPAManyToManySideA a = new UnownedJPAManyToManySideA();
      UnownedJPAManyToManySideB b2 = new UnownedJPAManyToManySideB();
      b2.getAs().add(a);
      a.getBs().add(b2);
      a.getBs().add(b);
      b.getAs().add(a);
      em.persist(a);
      em.persist(a);
    } catch (Exception e) {
      NucleusLogger.GENERAL.error("Exception in persist", e);
      fail("Exception in test : " + e.getMessage());
      return;
    } finally {
      if (em.getTransaction().isActive()) {
        em.getTransaction().rollback();
      }
      em.close();
    }
    if (emf.getCache() != null) {
      emf.getCache().evictAll();
    }

    em = emf.createEntityManager();
    try {
      Query qa = em.createQuery("SELECT a FROM UnownedJPAManyToManySideA a");
      List<UnownedJPAManyToManySideA> results1 = qa.getResultList();
      assertNotNull(results1);
      assertEquals("Incorrect number of side A", 1, results1.size());
      UnownedJPAManyToManySideA a = results1.iterator().next();
      Set<UnownedJPAManyToManySideB> bs = a.getBs();
      assertNotNull(bs);
      assertEquals("Incorrect number of side B for A", 2, bs.size());

      Query qb = em.createQuery("SELECT b FROM UnownedJPAManyToManySideB b");
      List<UnownedJPAManyToManySideB> results2 = qb.getResultList();
View Full Code Here

TOP

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

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.