Package org.apache.openjpa.persistence.entityoperation.common.apps

Examples of org.apache.openjpa.persistence.entityoperation.common.apps.CascadesEntity


     }


     public void testNoCascadeReferenceIsPreLoadedReference ()
     {
         CascadesEntity ent = new CascadesEntity ();
         CascadesEntity rel = new CascadesEntity ();
         CascadesEntity other = new CascadesEntity ();
         ent.setName ("ent");
         rel.setName ("rel");
         other.setName ("other");
         ent.setNone (rel);
         ent.getNoneCollection ().add (rel);

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persistAll (ent, rel, other);
         endTx(em);
         long otherId = other.getId ();
         endEm(em);

         ent.setNone (other);
         ent.getNoneCollection ().remove (rel);
         ent.getNoneCollection ().add (other);
View Full Code Here


         endTx(em);
         endEm(em);
     }

    public void testNoCascadeNewCausesException() {
        CascadesEntity ent = new CascadesEntity();
        CascadesEntity rel = new CascadesEntity();
        ent.setNone(rel);

        OpenJPAEntityManager em =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(em);
        em.persistAll(ent, rel);
        endTx(em);
        endEm(em);

        CascadesEntity other = new CascadesEntity();
        ent.setNone(other);

        em = (OpenJPAEntityManager) currentEntityManager();
        startTx(em);
        try {
            ent = em.merge(ent);
            fail("Allowed merge of new instance in non-cascading relation.");
        }
        catch (RuntimeException re) {
            if (isActiveTx(em))
                rollbackTx(em);
        }
        endEm(em);

        ent = new CascadesEntity();
        em = (OpenJPAEntityManager) currentEntityManager();
        startTx(em);
        em.persist(ent);
        endTx(em);
        endEm(em);

        other = new CascadesEntity();
        ent.getNoneCollection().add(other);

        em = (OpenJPAEntityManager) currentEntityManager();
        startTx(em);
        try {
View Full Code Here

        endEm(em);
    }

  public void testCascadeNewPersisted ()
  {
    CascadesEntity ent = new CascadesEntity ();
    CascadesEntity rel1 = new CascadesEntity ();
    CascadesEntity rel2 = new CascadesEntity ();
    ent.setName ("ent");
    rel1.setName ("rel1");
    ent.setAll (rel1);
    rel2.setName ("rel2");
    ent.getAllCollection ().add (rel2);

    OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
    startTx(em);
    em.persist (ent);
    endTx(em);
    endEm(em);

    CascadesEntity other1 = new CascadesEntity ();
    CascadesEntity other2 = new CascadesEntity ();
    other1.setName ("other1");
    other2.setName ("other2");

    ent.setAll (other1);
    ent.getAllCollection ().remove (rel2);
    ent.getAllCollection ().add (other2);

    em = (OpenJPAEntityManager)currentEntityManager();
    startTx(em);
    ent = em.merge (ent);
    assertTrue (em.isDirty (ent));
    assertTrue (rel1 != ent.getAll ());
    assertTrue (other1 != ent.getAll ());
    other1 = ent.getAll ();
    assertEquals ("other1", other1.getName ());
    assertTrue (em.isNewlyPersistent (other1));
    assertEquals (1, ent.getAllCollection ().size ());
    other2 = ent.getAllCollection ().iterator ().next ();
    assertEquals ("other2", other2.getName ());
    assertTrue (em.isNewlyPersistent (other2));
    endTx(em);
    endEm(em);
  }
View Full Code Here

  }


  public void testCascadesDeleteNonPersistent ()
  {
    CascadesEntity all = new CascadesEntity ();
    CascadesEntity none = new CascadesEntity ();
    CascadesEntity manyAll = new CascadesEntity ();
    CascadesEntity manyNone = new CascadesEntity ();
    OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
    startTx(em);
    em.persist (all);
    em.persist (none);
    em.persist (manyAll);
    em.persist (manyNone);
    endTx(em);
    long allId = all.getId ();
    long noneId = none.getId ();
    long manyAllId = manyAll.getId ();
    long manyNoneId = manyNone.getId ();
    endEm(em);

    em = (OpenJPAEntityManager) currentEntityManager();
    startTx(em);
    CascadesEntity ent = new CascadesEntity ();
    ent.setAll (em.find (CascadesEntity.class, allId));
    ent.setNone (em.find (CascadesEntity.class, noneId));
    ent.getAllCollection ().add (em.find (CascadesEntity.class, manyAllId));
    ent.getNoneCollection ().add (em.find (CascadesEntity.class, manyNoneId));
    em.remove (ent);
    assertTrue (em.isRemoved (ent.getAll ()));
    assertFalse (em.isRemoved (ent.getNone ()));
    for (CascadesEntity rel : ent.getAllCollection ())
    assertTrue (em.isRemoved (rel));
    for (CascadesEntity rel : ent.getNoneCollection ())
      assertFalse (em.isRemoved (rel));
    assertFalse (em.contains (ent));
    endTx(em);
    endEm(em);
View Full Code Here

         endTx(em);
         endEm(em);
     }

    public void testNoCascadeNewCausesException() {
        CascadesEntity ent = new CascadesEntity();
        CascadesEntity rel = new CascadesEntity();
        ent.setNone(rel);

        OpenJPAEntityManager em =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(em);
        em.persistAll(ent, rel);
        endTx(em);
        endEm(em);

        CascadesEntity other = new CascadesEntity();
        ent.setNone(other);

        em = (OpenJPAEntityManager) currentEntityManager();
        startTx(em);
        try {
            ent = em.merge(ent);
            fail("Allowed merge of new instance in non-cascading relation.");
        }
        catch (RuntimeException re) {
            if (isActiveTx(em))
                rollbackTx(em);
        }
        endEm(em);

        ent = new CascadesEntity();
        em = (OpenJPAEntityManager) currentEntityManager();
        startTx(em);
        em.persist(ent);
        endTx(em);
        endEm(em);

        other = new CascadesEntity();
        ent.getNoneCollection().add(other);

        em = (OpenJPAEntityManager) currentEntityManager();
        startTx(em);
        try {
View Full Code Here

        endEm(em);
    }

  public void testCascadeNewPersisted ()
  {
    CascadesEntity ent = new CascadesEntity ();
    CascadesEntity rel1 = new CascadesEntity ();
    CascadesEntity rel2 = new CascadesEntity ();
    ent.setName ("ent");
    rel1.setName ("rel1");
    ent.setAll (rel1);
    rel2.setName ("rel2");
    ent.getAllCollection ().add (rel2);

        OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
    startTx(em);
    em.persist (ent);
    endTx(em);
    endEm(em);

    CascadesEntity other1 = new CascadesEntity ();
    CascadesEntity other2 = new CascadesEntity ();
    other1.setName ("other1");
    other2.setName ("other2");

    ent.setAll (other1);
    ent.getAllCollection ().remove (rel2);
    ent.getAllCollection ().add (other2);

    em = (OpenJPAEntityManager)currentEntityManager();
    startTx(em);
    ent = em.merge (ent);
    assertTrue (em.isDirty (ent));
    assertTrue (rel1 != ent.getAll ());
    assertTrue (other1 != ent.getAll ());
    other1 = ent.getAll ();
    assertEquals ("other1", other1.getName ());
    assertTrue (em.isNewlyPersistent (other1));
    assertEquals (1, ent.getAllCollection ().size ());
    other2 = ent.getAllCollection ().iterator ().next ();
    assertEquals ("other2", other2.getName ());
    assertTrue (em.isNewlyPersistent (other2));
    endTx(em);
    endEm(em);
  }
View Full Code Here

  }


  public void testCascadesDeleteNonPersistent ()
  {
    CascadesEntity all = new CascadesEntity ();
    CascadesEntity none = new CascadesEntity ();
    CascadesEntity manyAll = new CascadesEntity ();
    CascadesEntity manyNone = new CascadesEntity ();
        OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
    startTx(em);
    em.persist (all);
    em.persist (none);
    em.persist (manyAll);
    em.persist (manyNone);
    endTx(em);
    long allId = all.getId ();
    long noneId = none.getId ();
    long manyAllId = manyAll.getId ();
    long manyNoneId = manyNone.getId ();
    endEm(em);

    em = (OpenJPAEntityManager) currentEntityManager();
    startTx(em);
    CascadesEntity ent = new CascadesEntity ();
    ent.setAll (em.find (CascadesEntity.class, allId));
    ent.setNone (em.find (CascadesEntity.class, noneId));
        ent.getAllCollection().add(em.find(CascadesEntity.class, manyAllId));
        ent.getNoneCollection().add(em.find(CascadesEntity.class, manyNoneId));
    em.remove (ent);
    assertTrue (em.isRemoved (ent.getAll ()));
    assertFalse (em.isRemoved (ent.getNone ()));
    for (CascadesEntity rel : ent.getAllCollection ())
    assertTrue (em.isRemoved (rel));
    for (CascadesEntity rel : ent.getNoneCollection ())
      assertFalse (em.isRemoved (rel));
    assertFalse (em.contains (ent));
    endTx(em);
    endEm(em);
View Full Code Here

        deleteAll(CascadesEntity.class);
    }

    public void testNoCascadePersist ()
     {
         CascadesEntity ent = new CascadesEntity ();
         CascadesEntity rel = new CascadesEntity ();
         ent.setNone (rel);
         ent.getNoneCollection ().add (rel);

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
View Full Code Here

     }


     public void testCascadePersistIsImmediate ()
     {
         CascadesEntity ent = new CascadesEntity ();
         CascadesEntity rel1 = new CascadesEntity ();
         CascadesEntity rel2 = new CascadesEntity ();
         ent.setAll (rel1);
         ent.getAllCollection ().add (rel2);

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
View Full Code Here

     }


     public void testNoCascadePersistFlushWithDeletedCausesException ()
     {
         CascadesEntity rel = new CascadesEntity ();
         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persist (rel);
         endTx(em);
         long id = rel.getId ();
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         rel = em.find (CascadesEntity.class, id);
         assertNotNull (rel);
         CascadesEntity ent = new CascadesEntity ();
         ent.setNone (rel);
         startTx(em);
         em.remove (rel);
         em.persist (ent);
         try
         {
             endTx(em);
             fail ("Allowed flush with deleted object in non-cascade-persist "
                 + "relation field");
         }
         catch (RuntimeException re)
         {
         }
         catch (Exception e)
         {}

         assertTrue (!em.getTransaction().isActive ());
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         rel = em.find (CascadesEntity.class, id);
         assertNotNull (rel);
         ent = new CascadesEntity ();
         ent.getNoneCollection ().add (rel);
         startTx(em);
         em.remove (rel);
         em.persist (ent);
         try
         {
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.entityoperation.common.apps.CascadesEntity

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.