openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dez...@apache.org
Subject svn commit: r802195 - in /openjpa/branches/1.1.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/
Date Fri, 07 Aug 2009 21:16:07 GMT
Author: dezzio
Date: Fri Aug  7 21:15:47 2009
New Revision: 802195

URL: http://svn.apache.org/viewvc?rev=802195&view=rev
Log:
OpenJPA-235: merged fix from trunk 673258, "SQL reordering to avoid non-nullable foreign key
constraint violations"

Added:
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/EntityF.java
      - copied unchanged from r673258, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/EntityF.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/EntityG.java
      - copied unchanged from r673258, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/EntityG.java
Modified:
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
  (contents, props changed)
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
  (contents, props changed)
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/TestNoForeignKeyViolation.java

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=802195&r1=802194&r2=802195&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
Fri Aug  7 21:15:47 2009
@@ -248,7 +248,8 @@
             if (rel != null) {
                 ForeignKey fk = field.getForeignKey((ClassMapping)
                     rel.getMetaData());
-                if (fk.getDeleteAction() == ForeignKey.ACTION_RESTRICT) {
+                if (fk.getDeleteAction() == ForeignKey.ACTION_RESTRICT ||
+                    fk.getDeleteAction() == ForeignKey.ACTION_CASCADE) {
                     Row row = field.getRow(sm, store, rm, Row.ACTION_DELETE);
                     row.setForeignKey(fk, null, rel);
                 }

Propchange: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Aug  7 21:15:47 2009
@@ -0,0 +1 @@
+/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java:673258,774580

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java?rev=802195&r1=802194&r2=802195&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
Fri Aug  7 21:15:47 2009
@@ -192,10 +192,10 @@
     }
 
     /**
-     * If this is a delete, delay foreign keys to other deleted objects if
-     * the key is restricted. If this is an update or insert, delay foreign
-     * keys to other inserts if the key is not logical. If the foreign key
-     * is to a new record and the columns are auto-inc, record it.
+     * If this is a delete, delay foreign keys to other deleted objects if the 
+     * key is restricted or cascade. If this is an update or insert, delay 
+     * foreign keys to other inserts if the key is not logical. If the foreign 
+     * key is to a new record and the columns are auto-inc, record it.
      */
     private boolean delayForeignKey(ForeignKey fk, OpenJPAStateManager sm,
         boolean set) {
@@ -204,7 +204,8 @@
 
         if (getAction() == ACTION_DELETE)
             return sm.isDeleted() && !fk.isDeferred()
-                && fk.getDeleteAction() == ForeignKey.ACTION_RESTRICT;
+                && (fk.getDeleteAction() == ForeignKey.ACTION_RESTRICT ||
+                    fk.getDeleteAction() == ForeignKey.ACTION_CASCADE);
 
         if (!sm.isNew() || sm.isFlushed())
             return false;

Propchange: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Aug  7 21:15:47 2009
@@ -0,0 +1 @@
+/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PrimaryRow.java:673258,774580

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/TestNoForeignKeyViolation.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/TestNoForeignKeyViolation.java?rev=802195&r1=802194&r2=802195&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/TestNoForeignKeyViolation.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/TestNoForeignKeyViolation.java
Fri Aug  7 21:15:47 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.openjpa.jdbc.kernel;
 
+import java.util.ArrayList;
+import java.util.List;
 import javax.persistence.EntityManager;
 
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@@ -37,7 +39,8 @@
     private EntityD entityD;
 
     public void setUp() {
-        setUp(EntityA.class, EntityB.class, EntityC.class, EntityD.class, EntityE.class);
+        setUp(EntityA.class, EntityB.class, EntityC.class, EntityD.class, 
+              EntityE.class, EntityF.class, EntityG.class);
 
         createTestData();
     }
@@ -154,4 +157,55 @@
             em.close();
         }
     }
+    
+    public void testForeignKeyCascade() {
+        EntityManager em = emf.createEntityManager();
+        try {
+            EntityF f = new EntityF();
+            f.setId(1);
+
+            List<EntityG> listG = new ArrayList<EntityG>();
+            EntityG g1 = new EntityG();
+            g1.setId(1);
+            listG.add(g1);
+            g1.setEntityF(f);
+            
+            EntityG g2 = new EntityG();
+            g2.setId(2);
+            listG.add(g2);
+            g2.setEntityF(f);
+
+            EntityG g3 = new EntityG();
+            g3.setId(3);
+            listG.add(g3);
+            g3.setEntityF(f);
+
+            EntityG g4 = new EntityG();
+            g4.setId(4);
+            listG.add(g4);
+            g4.setEntityF(f);
+            
+            f.setListG(listG);
+            em.getTransaction().begin();
+            em.persist(f);
+            em.persist(g1);
+            em.persist(g2);
+            em.persist(g3);
+            em.persist(g4);
+            em.getTransaction().commit();
+
+            em.getTransaction().begin();
+            em.remove(f);
+            em.getTransaction().commit();
+        }
+        catch (Exception e) {
+            fail("Fail to delete EntityF");
+        }
+        finally {
+            if (em.getTransaction().isActive())
+                em.getTransaction().rollback();
+            em.close();
+        }
+    }
+    
 }



Mime
View raw message