openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1570261 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/util/ openjpa-kernel/src/test/java/org/apache/o...
Date Thu, 20 Feb 2014 16:33:31 GMT
Author: curtisr7
Date: Thu Feb 20 16:33:30 2014
New Revision: 1570261

URL: http://svn.apache.org/r1570261
Log:
OPENJPA-2441: Remove usage of NullSafeConcurrentHashMap. Patch contributed by Dalia Abo Sheasha.

Removed:
    openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/concurrent/TestConcurrentMap.java
    openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/concurrent/TestNullSafeConcurrentHashMap.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
    openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/NullSafeConcurrentHashMap.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/SizedConcurrentHashMap.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java?rev=1570261&r1=1570260&r2=1570261&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/AbstractQueryCache.java
Thu Feb 20 16:33:30 2014
@@ -40,9 +40,10 @@ import org.apache.openjpa.lib.conf.Confi
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.ReferenceMap;
 import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
+import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
 import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
-import org.apache.openjpa.lib.util.concurrent.SizedConcurrentHashMap;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.util.Id;
@@ -480,11 +481,27 @@ public abstract class AbstractQueryCache
         
         private long[] astat = new long[ARRAY_SIZE];
         private long[] stat  = new long[ARRAY_SIZE];
-        private Map<T, long[]> stats  = new SizedConcurrentHashMap(FIXED_SIZE, LOAD_FACTOR,
CONCURRENCY);
-        private Map<T, long[]> astats = new SizedConcurrentHashMap(FIXED_SIZE, LOAD_FACTOR,
CONCURRENCY);
+        private Map<T, long[]> stats;
+        private Map<T, long[]> astats;
         private Date start = new Date();
         private Date since = start;
-        
+
+        public Default() {
+            initializeMaps();
+        }
+
+        private void initializeMaps() {
+            ConcurrentReferenceHashMap statsMap =
+                new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY,
LOAD_FACTOR);
+            statsMap.setMaxSize(FIXED_SIZE);
+            stats = statsMap;
+
+            ConcurrentReferenceHashMap aStatsMap =
+                new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY,
LOAD_FACTOR);
+            aStatsMap.setMaxSize(FIXED_SIZE);
+            astats = aStatsMap;
+        }
+
         public Set<T> keys() {
             return stats.keySet();
         }
@@ -552,8 +569,7 @@ public abstract class AbstractQueryCache
         public synchronized void clear() {
            astat = new long[ARRAY_SIZE];
            stat  = new long[ARRAY_SIZE];
-           stats = new SizedConcurrentHashMap(FIXED_SIZE, LOAD_FACTOR, CONCURRENCY);
-           astats = new SizedConcurrentHashMap(FIXED_SIZE, LOAD_FACTOR, CONCURRENCY);
+           initializeMaps();
            start  = new Date();
            since  = start;
         }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java?rev=1570261&r1=1570260&r2=1570261&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryStatistics.java
Thu Feb 20 16:33:30 2014
@@ -25,7 +25,8 @@ import java.util.Date;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.openjpa.lib.util.concurrent.SizedConcurrentHashMap;
+import org.apache.openjpa.lib.util.ReferenceMap;
+import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
 
 /**
  * Records query execution statistics.
@@ -153,11 +154,27 @@ public interface QueryStatistics<T> exte
         
 		private long[] astat = new long[ARRAY_SIZE];
 		private long[] stat  = new long[ARRAY_SIZE];
-		private Map<T, long[]> stats  = new SizedConcurrentHashMap(FIXED_SIZE, LOAD_FACTOR,
CONCURRENCY);
-		private Map<T, long[]> astats = new SizedConcurrentHashMap(FIXED_SIZE, LOAD_FACTOR,
CONCURRENCY);
+		private Map<T, long[]> stats;
+		private Map<T, long[]> astats;
 		private Date start = new Date();
 		private Date since = start;
 		
+		public Default() {
+            initializeMaps();
+        }
+
+        private void initializeMaps() {
+            ConcurrentReferenceHashMap statsMap =
+                new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY,
LOAD_FACTOR);
+            statsMap.setMaxSize(FIXED_SIZE);
+            stats = statsMap;
+
+            ConcurrentReferenceHashMap aStatsMap =
+                new ConcurrentReferenceHashMap(ReferenceMap.HARD, ReferenceMap.HARD, CONCURRENCY,
LOAD_FACTOR);
+            aStatsMap.setMaxSize(FIXED_SIZE);
+            astats = aStatsMap;
+        }
+        
 		public Set<T> keys() {
 		    return stats.keySet();
 		}
@@ -216,8 +233,7 @@ public interface QueryStatistics<T> exte
 	    public synchronized void clear() {
 	       astat = new long[ARRAY_SIZE];
 	       stat  = new long[ARRAY_SIZE];
-	       stats = new SizedConcurrentHashMap(FIXED_SIZE, LOAD_FACTOR, CONCURRENCY);
-	       astats = new SizedConcurrentHashMap(FIXED_SIZE, LOAD_FACTOR, CONCURRENCY);
+	       initializeMaps();
 	       start  = new Date();
 	       since  = start;
 	    }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java?rev=1570261&r1=1570260&r2=1570261&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
Thu Feb 20 16:33:30 2014
@@ -56,8 +56,8 @@ import org.apache.openjpa.lib.util.Files
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
-import org.apache.openjpa.lib.util.concurrent.NullSafeConcurrentHashMap;
 
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
 import serp.bytecode.BCClass;
@@ -94,8 +94,8 @@ public class ProxyManagerImpl
         _stdMaps.put(SortedMap.class, TreeMap.class);
     }
 
-    private final Set _unproxyable = new HashSet();
-    private final Map _proxies = new NullSafeConcurrentHashMap();
+    private final Set<String> _unproxyable = new HashSet<String>();
+    private final Map<Class<?>, Proxy> _proxies = new ConcurrentHashMap<Class<?>,
Proxy>();
     private boolean _trackChanges = true;
     private boolean _assertType = false;
     private boolean _delayedCollectionLoading = false;
@@ -453,31 +453,32 @@ public class ProxyManagerImpl
      * Return the cached factory proxy for the given bean type.
      */
     private ProxyBean getFactoryProxyBean(Object orig) {
-        final Class type = orig.getClass();
+        final Class<?> type = orig.getClass();
         if (isUnproxyable(type))
             return null;
 
         // we don't lock here; ok if two proxies get generated for same type
         ProxyBean proxy = (ProxyBean) _proxies.get(type);
-        if (proxy == null && !_proxies.containsKey(type)) {
-            ClassLoader l = GeneratedClasses.getMostDerivedLoader(type,
-                ProxyBean.class);
-            Class pcls = loadBuildTimeProxy(type, l);
+        if (proxy == null) {
+            ClassLoader l = GeneratedClasses.getMostDerivedLoader(type, ProxyBean.class);
+            Class<?> pcls = loadBuildTimeProxy(type, l);
             if (pcls == null) {
-                // TODO Move this to J2DOPrivHelper? 
-                BCClass bc = AccessController
-                    .doPrivileged(new PrivilegedAction<BCClass>() {
-                        public BCClass run() {
-                            return generateProxyBeanBytecode(type, true);
-                        }
-                    });
+                // TODO Move this to J2DOPrivHelper?
+                BCClass bc = AccessController.doPrivileged(new PrivilegedAction<BCClass>()
{
+                    public BCClass run() {
+                        return generateProxyBeanBytecode(type, true);
+                    }
+                });
                 if (bc != null)
                     pcls = GeneratedClasses.loadBCClass(bc, l);
             }
             if (pcls != null)
-                proxy = (ProxyBean) instantiateProxy(pcls,
-                    findCopyConstructor(type), new Object[] {orig});
-            _proxies.put(type, proxy);
+                proxy = (ProxyBean) instantiateProxy(pcls, findCopyConstructor(type), new
Object[] { orig });
+            if (proxy == null) {
+                _unproxyable.add(type.getName());
+            } else {
+                _proxies.put(type, proxy);
+            }
         }
         return proxy;
     }

Modified: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java?rev=1570261&r1=1570260&r2=1570261&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java
Thu Feb 20 16:33:30 2014
@@ -740,8 +740,35 @@ public class TestProxyManager extends Te
         NonproxyableBean orig = new NonproxyableBean(1);
         populate(orig);
         assertNull(_mgr.copyCustom(orig));
+        assertNull(_mgr.copyCustom(orig));
         assertNull(_mgr.newCustomProxy(orig, true));
     }
+    
+    public void testIsUnproxyable() {
+        CustomBean validBean = new CustomBean();
+        populate(validBean);
+        assertNotNull(_mgr.copyCustom(validBean));
+        assertNotNull(_mgr.newCustomProxy(validBean, true));
+        assertFalse(_mgr.isUnproxyable(CustomBean.class));
+        
+        NonproxyableBean bean1 = new NonproxyableBean(1);
+        populate(bean1);
+        
+        NonproxyableBean2 bean2 = new NonproxyableBean2();
+        populate(bean2);
+
+        assertFalse(_mgr.isUnproxyable(NonproxyableBean.class));
+        assertNull(_mgr.copyCustom(bean1));
+        assertTrue(_mgr.isUnproxyable(NonproxyableBean.class));
+        assertNull(_mgr.newCustomProxy(bean1, true));
+        assertTrue(_mgr.isUnproxyable(NonproxyableBean.class));
+        
+        assertFalse(_mgr.isUnproxyable(NonproxyableBean2.class));
+        assertNull(_mgr.newCustomProxy(bean2, true));
+        assertTrue(_mgr.isUnproxyable(NonproxyableBean2.class));
+        assertNull(_mgr.copyCustom(bean2));
+        assertTrue(_mgr.isUnproxyable(NonproxyableBean2.class));
+    }
 
     /**
      * Assert that the given beans are exactly the same.
@@ -949,6 +976,13 @@ public class TestProxyManager extends Te
     }
 
     /**
+     * Used to non-proxyable custom bean handling.
+     */
+    public class NonproxyableBean2 extends CustomBean {
+        // class is not static
+    }
+
+    /**
      * Used to test custom calendar handling.
      */
     public static class CustomCalendar extends GregorianCalendar {

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/NullSafeConcurrentHashMap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/NullSafeConcurrentHashMap.java?rev=1570261&r1=1570260&r2=1570261&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/NullSafeConcurrentHashMap.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/NullSafeConcurrentHashMap.java
Thu Feb 20 16:33:30 2014
@@ -31,12 +31,15 @@ import java.util.HashSet;
 import org.apache.commons.collections.set.MapBackedSet;
 
 /**
- * A subclass of {@link ConcurrentHashMap} that allows null keys and values.
- * In exchange, it weakens the contract of {@link #putIfAbsent} and the other
- * concurrent methods added in {@link #ConcurrentHashMap}.
- *
+ * A subclass of {@link ConcurrentHashMap} that allows null keys and values. In exchange,
it weakens the contract of
+ * {@link #putIfAbsent} and the other concurrent methods added in {@link #ConcurrentHashMap}.
+ * 
  * @since 1.1.0
+ * @deprecated In Java 8, java.util.ConcurrentHashMap received an overhauled and this extension
was not updated. This
+ *             class will fail to compile on Java 8. If it is compiled at a lower level and
run on Java 8 it will not
+ *             work properly. For more information: https://issues.apache.org/jira/browse/OPENJPA-2441
  */
+@Deprecated
 public class NullSafeConcurrentHashMap extends ConcurrentHashMap {
 
     private enum Markers {

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/SizedConcurrentHashMap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/SizedConcurrentHashMap.java?rev=1570261&r1=1570260&r2=1570261&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/SizedConcurrentHashMap.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/SizedConcurrentHashMap.java
Thu Feb 20 16:33:30 2014
@@ -28,9 +28,13 @@ import org.apache.openjpa.lib.util.Sized
 
 /**
  * An implementation of {@link SizedMap} that uses JDK1.5 concurrency primitives
- *
+ * 
  * @since 1.1.0
+ * @deprecated In Java 8, java.util.ConcurrentHashMap received an overhauled and this extension
was not updated. This
+ *             class will fail to compile on Java 8. If it is compiled at a lower level and
run on Java 8 it will not
+ *             work properly. For more information: https://issues.apache.org/jira/browse/OPENJPA-2441
  */
+@Deprecated
 public class SizedConcurrentHashMap
     extends NullSafeConcurrentHashMap
     implements SizedMap, ConcurrentMap, Serializable {



Mime
View raw message