openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r923873 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/util/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/ openjpa-persistence-jdb...
Date Tue, 16 Mar 2010 17:09:45 GMT
Author: dwoods
Date: Tue Mar 16 17:09:45 2010
New Revision: 923873

URL: http://svn.apache.org/viewvc?rev=923873&view=rev
Log:
OPENJPA-1097 Revert previous DetachManager and TestProxyCollection changes in r919696.  New
code changes Proxies to always remove  classes on serialization if the entity is detachable
and one of our Proxy subclasses.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoProxy.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java?rev=923873&r1=923872&r2=923873&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachManager.java
Tue Mar 16 17:09:45 2010
@@ -567,9 +567,8 @@ public class DetachManager
                         if (proxy.getChangeTracker() != null)
                             proxy.getChangeTracker().stopTracking();
                         proxy.setOwner(dsm, (dsm == null) ? -1 : fmd.getIndex());
-                        objval = proxy.copy(proxy);
-                        sm.replaceField(getDetachedPersistenceCapable(), this, fmd.getIndex());
                     }
+                    sm.provideField(getDetachedPersistenceCapable(), this, fmd.getIndex());
                 }
             }
             clear();
@@ -710,7 +709,7 @@ public class DetachManager
          * Set the owner of the field's proxy to the detached state manager.
          */
         private Object reproxy(Object obj, int field) {
-            if (obj != null && _detSM != null && obj instanceof Proxy){
+            if (obj != null && _detSM != null && obj instanceof Proxy) {
                 ((Proxy) obj).setOwner(_detSM, field);
                 return ((Proxy) obj).copy(obj); 
             }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java?rev=923873&r1=923872&r2=923873&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/Proxies.java Tue Mar
16 17:09:45 2010
@@ -80,10 +80,16 @@ public class Proxies {
      * Used by proxy types to serialize non-proxy versions.
      */
     public static Object writeReplace(Proxy proxy, boolean detachable) {
-        if (detachable && (proxy == null || proxy.getOwner() == null 
-            || proxy.getOwner().isDetached()))
+        /* OPENJPA-1097 Always remove $proxy classes during serialization if detachable
+            if (detachable && (proxy == null || proxy.getOwner() == null 
+                || proxy.getOwner().isDetached()))
+                return proxy;
+        */
+        if (!detachable || proxy == null || proxy.getOwner() == null) {
             return proxy;
-        return proxy.copy(proxy);
+        } else {
+            return proxy.copy(proxy);
+        }
     }
 }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoProxy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoProxy.java?rev=923873&r1=923872&r2=923873&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoProxy.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestDetachNoProxy.java
Tue Mar 16 17:09:45 2010
@@ -44,17 +44,17 @@ public class TestDetachNoProxy extends S
         Compatibility compat = emf.getConfiguration().getCompatibilityInstance();
         assertNotNull(compat);
         if (log.isTraceEnabled()) {
-            log.info("Before set, FlushBeforeDetach=" + compat.getFlushBeforeDetach());
-            log.info("Before set, CopyOnDetach=" + compat.getCopyOnDetach());
-            log.info("Before set, CascadeWithDetach=" + compat.getCascadeWithDetach());
+            log.trace("Before set, FlushBeforeDetach=" + compat.getFlushBeforeDetach());
+            log.trace("Before set, CopyOnDetach=" + compat.getCopyOnDetach());
+            log.trace("Before set, CascadeWithDetach=" + compat.getCascadeWithDetach());
         }
         compat.setFlushBeforeDetach(false);
         compat.setCopyOnDetach(false);
         compat.setCascadeWithDetach(false);
         if (log.isTraceEnabled()) {
-            log.info("After set, FlushBeforeDetach=" + compat.getFlushBeforeDetach());
-            log.info("After set, CopyOnDetach=" + compat.getCopyOnDetach());
-            log.info("After set, CascadeWithDetach=" + compat.getCascadeWithDetach());
+            log.trace("After set, FlushBeforeDetach=" + compat.getFlushBeforeDetach());
+            log.trace("After set, CopyOnDetach=" + compat.getCopyOnDetach());
+            log.trace("After set, CascadeWithDetach=" + compat.getCascadeWithDetach());
         }
         createEntities(numEntities);
     }
@@ -76,7 +76,7 @@ public class TestDetachNoProxy extends S
      */
     public void testDetach() {
         if (log.isTraceEnabled())
-            log.info("***** testDetach() *****");
+            log.trace("***** testDetach() *****");
         Integer id = new Integer(0);
         OpenJPAEntityManager em = emf.createEntityManager();
         
@@ -85,6 +85,7 @@ public class TestDetachNoProxy extends S
         if (log.isTraceEnabled())
             log.trace("** after find");
         assertTrue(em.contains(e20));
+        assertFalse(em.isDetached(e20));
         verifySerializable(e20, true);
         
         // new openjpa-2.0.0 behavior, where detach() doesn't return updated entity, but
does it in-place
@@ -92,6 +93,7 @@ public class TestDetachNoProxy extends S
         if (log.isTraceEnabled())
             log.trace("** after detach");
         // in-place updated entity should not have any proxy classes and should be detached
+        assertFalse(em.contains(e20));
         assertTrue(em.isDetached(e20));
         verifySerializable(e20, false);
                
@@ -103,7 +105,7 @@ public class TestDetachNoProxy extends S
      */
     public void testDetachCopy() {
         if (log.isTraceEnabled())
-            log.info("***** testDetachCopy() *****");
+            log.trace("***** testDetachCopy() *****");
         Integer id = new Integer(0);
         OpenJPAEntityManager em = emf.createEntityManager();
         em.clear();
@@ -112,12 +114,19 @@ public class TestDetachNoProxy extends S
         if (log.isTraceEnabled())
             log.trace("** after find");
         assertTrue(em.contains(e20));
+        assertFalse(em.isDetached(e20));
         verifySerializable(e20, true);
         
         // Test new detachCopy() method added in 2.0.0
         Entity20 e20copy = em.detachCopy(e20);
         if (log.isTraceEnabled())
             log.trace("** after detachCopy");
+        // verify e20 is same as above
+        assertTrue(em.contains(e20));
+        assertFalse(em.isDetached(e20));
+        verifySerializable(e20, true);
+        // verify copy does not have any proxy classes (in-place updated) is detached
+        assertFalse(em.contains(e20copy));
         assertTrue(em.isDetached(e20copy));
         verifySerializable(e20copy, false);
         
@@ -129,7 +138,7 @@ public class TestDetachNoProxy extends S
      */
     public void testDetachAll() {
         if (log.isTraceEnabled())
-            log.info("***** testDetachAll() *****");
+            log.trace("***** testDetachAll() *****");
         OpenJPAEntityManager em = emf.createEntityManager();
         em.clear();
 
@@ -140,6 +149,7 @@ public class TestDetachNoProxy extends S
             if (log.isTraceEnabled())
                 log.trace("** after find Entity20(" + i + ")");
             assertTrue(em.contains(e20));
+            assertFalse(em.isDetached(e20));
             verifySerializable(e20, true);            
         }
 
@@ -151,7 +161,8 @@ public class TestDetachNoProxy extends S
             if (log.isTraceEnabled())
                 log.trace("** after EM.clear() verify Entity20(" + i + ")");
             Entity20 e20 = e20List.get(i);
-            // entity should not have any proxy classes and should be detached
+            // entity should not have any proxy classes (in-place updated) and is detached
+            assertFalse(em.contains(e20));
             assertTrue(em.isDetached(e20));
             verifySerializable(e20, false);
         }
@@ -164,7 +175,7 @@ public class TestDetachNoProxy extends S
      */
     public void testClear() {
         if (log.isTraceEnabled())
-            log.info("***** testClear() *****");
+            log.trace("***** testClear() *****");
         OpenJPAEntityManager em = emf.createEntityManager();
         em.clear();
 
@@ -175,6 +186,7 @@ public class TestDetachNoProxy extends S
             if (log.isTraceEnabled())
                 log.trace("** after find Entity20(" + i + ")");
             assertTrue(em.contains(e20));
+            assertFalse(em.isDetached(e20));
             verifySerializable(e20, true);            
         }
 
@@ -183,8 +195,11 @@ public class TestDetachNoProxy extends S
             if (log.isTraceEnabled())
                 log.trace("** after EM.clear() verify Entity20(" + i + ")");
             Entity20 e20 = e20List.get(i);
+            assertFalse(em.contains(e20));
             assertTrue(em.isDetached(e20));
-            verifySerializable(e20, false);
+            // entity should still have proxy classes and is detached,
+            // but once serialized the $proxy classes will be removed
+            verifySerializable(e20, true);
         }
 
         em.close();
@@ -215,7 +230,7 @@ public class TestDetachNoProxy extends S
             }
         }
         
-        // then deserialize
+        // then deserialize and assert no $proxy classes exist
         ByteArrayInputStream bais = new ByteArrayInputStream(e20bytes);
         ObjectInputStream ois = null;
         Entity20 e20new = null;
@@ -241,8 +256,8 @@ public class TestDetachNoProxy extends S
 
     private void verifyEntities(Entity20 e20, boolean usesProxy) {
         if (log.isTraceEnabled()) {
+            log.trace("verifyEntities() - asserting expected proxy usage is " + usesProxy);
             printClassNames(e20);
-            log.trace("asserting expected proxy usage");
         }
         assertTrue("Expected sqlDate endsWith($proxy) to return " + usesProxy,
             usesProxy == e20.getDate().getClass().getCanonicalName().endsWith(PROXY));
@@ -254,9 +269,10 @@ public class TestDetachNoProxy extends S
     }
     
     private void printClassNames(Entity20 e20) {
-        log.info("sqlDate = " + e20.getDate().getClass().getCanonicalName());
-        log.info("sqlTime = " + e20.getTime().getClass().getCanonicalName());
-        log.info("sqlTimestamp = " + e20.getTimestamp().getClass().getCanonicalName());
+        if (log.isTraceEnabled()) {
+            log.trace("sqlDate = " + e20.getDate().getClass().getCanonicalName());
+            log.trace("sqlTime = " + e20.getTime().getClass().getCanonicalName());
+            log.trace("sqlTimestamp = " + e20.getTimestamp().getClass().getCanonicalName());
+        }
     }
-    
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java?rev=923873&r1=923872&r2=923873&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/proxy/TestProxyCollection.java
Tue Mar 16 17:09:45 2010
@@ -125,11 +125,10 @@ public class TestProxyCollection extends
 		em.merge(modified);
 		em.getTransaction().commit();
 
-		// this was unproxied by EM.clear() in create() below
-		// assertProxyCollection(root.getNodes(), true);
-		assertNotProxyCollection(root.getNodes());
-
 		em.clear();
+
+		assertProxyCollection(root.getNodes(), false);
+
 		verify(root, modifier);
 	}
 	
@@ -147,11 +146,7 @@ public class TestProxyCollection extends
 		em.getTransaction().begin();
 		em.persist(root);
 		em.getTransaction().commit();
-		// OPENJPA-1097 Fixed behavior so entities will use the proxy classes until EM.clear()
is called
-		assertProxyCollection(root.getNodes(), true);
 		em.clear();
-		// OPENJPA-1097 All proxies are removed after EM.clear()
-		assertNotProxyCollection(root.getNodes());
 		
 		return root;
 	}



Mime
View raw message