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

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


     }


     public void testCascadePersistFlushWithDeleted ()
     {
         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.setAll (rel);
         startTx(em);
         em.remove (rel);
         em.persist (ent);
         endTx(em);
         assertTrue (!em.getTransaction().isActive ());
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         rel = em.find (CascadesEntity.class, id);
         assertNotNull (rel);
         ent = new CascadesEntity ();
         ent.getAllCollection ().add (rel);
         startTx(em);
         em.remove (rel);
         em.persist (ent);
         endTx(em);
         assertTrue (!em.getTransaction().isActive ());
View Full Code Here


     }


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

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persist (ent);
         try
         {
             endTx(em);
             fail ("Allowed flush with transient object in non-cascade-persist "
                 + "relation field");
         }
         catch (RuntimeException re)
         {
         }
         catch (Exception re)
         {
         }


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

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

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

     }


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

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persist (ent);
         assertFalse(em.isPersistent (rel));
         em.persist (rel);
         endTx(em);
         long id = rel.getId ();
         endEm(em);

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

         em = (OpenJPAEntityManager)currentEntityManager();
         assertNotNull (em.find (CascadesEntity.class, id));
         startTx(em);
         em.persist (ent);
         assertFalse (em.isPersistent (rel));
         em.persist (rel);
         endTx(em);
         id = rel.getId ();
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         assertNotNull (em.find (CascadesEntity.class, id));
         endEm(em);
View Full Code Here

     }


     public void testCascadePersistFlushWithTransient ()
     {
         CascadesEntity ent = new CascadesEntity ();
         CascadesEntity rel = new CascadesEntity ();

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persist (ent);
         ent.setAll (rel);
         assertFalse (em.isPersistent (rel));
         endTx(em);
         long id = rel.getId ();
         endEm(em);

         ent = new CascadesEntity ();
         rel = new CascadesEntity ();

         em = (OpenJPAEntityManager)currentEntityManager();
         assertNotNull (em.find (CascadesEntity.class, id));
         startTx(em);
         em.persist (ent);
         ent.getAllCollection ().add (rel);
         assertFalse (em.isPersistent (rel));
         endTx(em);
         id = rel.getId ();
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         assertNotNull (em.find (CascadesEntity.class, id));
         endEm(em);
View Full Code Here

     }


     public void testCascadePersistFlushWithPersistent ()
     {
         CascadesEntity ent = new CascadesEntity ();
         CascadesEntity rel = new CascadesEntity ();
         ent.setAll (rel);

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persist (ent);
         assertTrue (em.isPersistent (rel));
         endTx(em);
         long id = rel.getId ();
         endEm(em);

         ent = new CascadesEntity ();
         rel = new CascadesEntity ();
         ent.getAllCollection ().add (rel);

         em = (OpenJPAEntityManager)currentEntityManager();
         assertNotNull (em.find (CascadesEntity.class, id));
         startTx(em);
         em.persist (ent);
         assertTrue (em.isPersistent (rel));
         endTx(em);
         id = rel.getId ();
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         assertNotNull (em.find (CascadesEntity.class, id));
         endEm(em);
View Full Code Here

     }


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

         em = (OpenJPAEntityManager)currentEntityManager();
         ent = em.find (CascadesEntity.class, id);
         CascadesEntity top = new CascadesEntity ();
         top.setAll (ent);
         CascadesEntity rel = new CascadesEntity ();

         startTx(em);
         ent.setAll (rel);
         rel.setAll (top);
         em.persist (top);
         assertTrue (em.isPersistent (top));
         assertTrue (em.isPersistent (ent));
         assertTrue (em.isPersistent (rel));
         rollbackTx(em);
View Full Code Here

     }


     public void testNoCascadeDelete ()
     {
         CascadesEntity ent = new CascadesEntity ();
         CascadesEntity rel = new CascadesEntity ();
         CascadesEntity depend = new CascadesEntity ();
         ent.setNone (rel);
         ent.setDependent (depend);
         ent.getNoneCollection ().add (rel);

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persistAll (ent, rel, depend);
         endTx(em);
         long id = ent.getId ();
         long relId = rel.getId ();
         long dependId = depend.getId ();
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         ent = em.find (CascadesEntity.class, id);
         rel = ent.getNone ();
         depend = ent.getDependent ();
         assertEquals (relId, rel.getId ());
         assertEquals (dependId, depend.getId ());
         assertEquals (1, ent.getNoneCollection ().size ());
         assertEquals (relId,
                 ent.getNoneCollection().iterator().next().getId());

         startTx(em);
View Full Code Here

     }


     public void testDeepCascadeDelete ()
     {
         CascadesEntity ent = new CascadesEntity ();
         CascadesEntity rel1 = new CascadesEntity ();
         CascadesEntity rel2 = new CascadesEntity ();
         CascadesEntity depend = new CascadesEntity ();
         CascadesEntity deep1 = new CascadesEntity ();
         CascadesEntity deep2 = new CascadesEntity ();
         CascadesEntity deep3 = new CascadesEntity ();
         ent.setAll (rel1);
         rel1.setAll (deep1);
         ent.getAllCollection ().add (rel2);
         rel2.getAllCollection ().add (deep2);
         ent.setDependent (depend);
         depend.setAll (deep3);

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persistAll (ent, depend);
         endTx(em);
         long id = ent.getId ();
         long rel1Id = rel1.getId ();
         long rel2Id = rel2.getId ();
         long deep1Id = deep1.getId ();
         long deep2Id = deep2.getId ();
         long deep3Id = deep3.getId ();
         long dependId = depend.getId ();
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         ent = em.find (CascadesEntity.class, id);
         rel1 = ent.getAll ();
         assertEquals (rel1Id, rel1.getId ());
         deep1 = rel1.getAll ();
         assertEquals (deep1Id, deep1.getId ());
         assertEquals (1, ent.getAllCollection ().size ());
         rel2 = ent.getAllCollection ().iterator ().next ();
         assertEquals (rel2Id, rel2.getId ());
         assertEquals (1, rel2.getAllCollection ().size ());
         deep2 = rel2.getAllCollection ().iterator ().next ();
         assertEquals (deep2Id, deep2.getId ());
         depend = ent.getDependent ();
         assertEquals (dependId, depend.getId ());
         deep3 = depend.getAll ();
         assertEquals (deep3Id, deep3.getId ());

         startTx(em);
         em.remove (ent);
         assertTrue (em.isRemoved (ent));
         assertTrue (em.isRemoved (rel1));
View Full Code Here

     }


     public void testCircularCascadeDelete ()
     {
         CascadesEntity ent = new CascadesEntity ();
         CascadesEntity rel = new CascadesEntity ();
         ent.setAll (rel);
         ent.getAllCollection ().add (rel);
         rel.setAll (ent);
         rel.getAllCollection ().add (ent);

         OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
         startTx(em);
         em.persist (ent);
         endTx(em);
         long id = ent.getId ();
         long relId = rel.getId ();
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         ent = em.find (CascadesEntity.class, id);
         rel = ent.getAll ();
         assertEquals (relId, rel.getId ());
         assertEquals (rel, ent.getAllCollection ().iterator ().next ());
         assertEquals (ent, rel.getAllCollection ().iterator ().next ());

         startTx(em);
         em.remove (ent);
         assertTrue (em.isRemoved (ent));
         assertTrue (em.isRemoved (rel));
View Full Code Here

     }


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

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

         em = (OpenJPAEntityManager)currentEntityManager();
         ent = em.find (CascadesEntity.class, id);
         rel = ent.getNone ();
         assertEquals (relId, rel.getId ());

         startTx(em);
         assertNull (ent.getDependent ());
         assertNull (rel.getDependent ());
         ent.setDependent (new CascadesEntity ());
         rel.setDependent (new CascadesEntity ());
         em.persist (ent.getDependent ());
         em.persist (rel.getDependent ());
         em.refresh (ent);
         assertNull (ent.getDependent ());
         assertNotNull (rel.getDependent ());
         endTx(em);
         endEm(em);

         em = (OpenJPAEntityManager)currentEntityManager();
         assertNull (em.find (CascadesEntity.class, id).getDependent ());
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.