openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1580903 - in /openjpa/branches/2.1.x: ./ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/TestCascadePersist.java
Date Mon, 24 Mar 2014 16:29:41 GMT
Author: hthomann
Date: Mon Mar 24 16:29:40 2014
New Revision: 1580903

URL: http://svn.apache.org/r1580903
Log:
OPENJPA-1986: Extra queries being generated when cascading a persist - added another/similar
check to the ones added by Rick.

Modified:
    openjpa/branches/2.1.x/   (props changed)
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/TestCascadePersist.java

Propchange: openjpa/branches/2.1.x/
------------------------------------------------------------------------------
  Merged /openjpa/branches/2.2.x:r1580898

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java?rev=1580903&r1=1580902&r2=1580903&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
Mon Mar 24 16:29:40 2014
@@ -256,7 +256,7 @@ class SingleFieldManager extends Transfe
         switch (fmd.getDeclaredTypeCode()) {
             case JavaTypes.PC:
             case JavaTypes.PC_UNTYPED:
-                if (!_broker.isDetachedNew() && _broker.isDetached(objval))
+                if (!_broker.isDetachedNew() && _broker.isDetached(objval, _checkDbOnCascadePersist))
                     return; // allow but ignore
                 _broker.persist(objval, true, call);
                 break;

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/TestCascadePersist.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/TestCascadePersist.java?rev=1580903&r1=1580902&r2=1580903&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/TestCascadePersist.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cascade/TestCascadePersist.java
Mon Mar 24 16:29:40 2014
@@ -21,12 +21,13 @@ package org.apache.openjpa.persistence.c
 import javax.persistence.EntityManager;
 import javax.persistence.RollbackException;
 
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestCascadePersist extends SingleEMFTestCase {
+public class TestCascadePersist extends SQLListenerTestCase {
     @Override
     public void setUp() throws Exception {
-        setUp(DROP_TABLES, CascadePersistEntity.class);
+        setUp(DROP_TABLES, CascadePersistEntity.class, "openjpa.Compatibility",
+            "CheckDatabaseForCascadePersistToDetachedEntity=false");
     }
 
     public void testCascadePersistToDetachedFailure() {
@@ -66,4 +67,29 @@ public class TestCascadePersist extends 
         // Since cpe1 is managed, it should be ignored by the cascaded persist operation.
         em.getTransaction().commit();
     }
+    
+    /*
+     * Prior to OPENJPA-1986, an extra SELECT was executed in this scenario.
+     */
+    public void testCascaseExtraneousSQL(){
+        long id = System.currentTimeMillis();
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+
+        CascadePersistEntity cpe = new CascadePersistEntity(id);
+        CascadePersistEntity cpe2 = new CascadePersistEntity(id+1);
+        cpe.setOther(cpe2);
+
+        //Clear all SQL statements to make sure that during
+        //the persist we don't execute a select.
+        resetSQL();
+        em.persist(cpe);
+
+        em.getTransaction().commit();
+        em.close();        
+
+        //There should be no selects at this point, only
+        //inserts.
+        assertNotSQL("SELECT .*");
+    }    
 }



Mime
View raw message