You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by aw...@apache.org on 2006/12/15 01:55:14 UTC

svn commit: r487410 - /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java

Author: awhite
Date: Thu Dec 14 16:55:14 2006
New Revision: 487410

URL: http://svn.apache.org/viewvc?view=rev&rev=487410
Log:
Allow configurable set of known unproxyable types.


Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java?view=diff&rev=487410&r1=487409&r2=487410
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java Thu Dec 14 16:55:14 2006
@@ -93,10 +93,15 @@
         _stdMaps.put(SortedMap.class, TreeMap.class);
     }
 
+    private final Set _unproxyable = new HashSet();
     private final Map _proxies = new ConcurrentHashMap();
     private boolean _trackChanges = true;
     private boolean _assertType = false;
 
+    public ProxyManagerImpl() {
+        _unproxyable.add(TimeZone.class.getName());
+    }
+
     /**
      * Whether proxies produced by this factory will use {@link ChangeTracker}s
      * to try to cut down on data store operations at the cost of some extra
@@ -133,6 +138,24 @@
         _assertType = assertType;
     }
 
+    /**
+     * Return a mutable view of class names we know cannot be proxied  
+     * correctly by this manager.
+     */
+    public Collection getUnproxyable() {
+        return _unproxyable;
+    }
+
+    /**
+     * Provided for auto-configuration.  Add the given semicolon-separated
+     * class names to the set of class names we know cannot be proxied correctly
+     * by this manager.
+     */
+    public void setUnproxyable(String clsNames) {
+        if (clsNames != null)
+            _unproxyable.addAll(Arrays.asList(Strings.split(clsNames, ";", 0)));
+    }
+
     public Object copyArray(Object orig) {
         if (orig == null)
             return null;
@@ -398,8 +421,11 @@
      * Return the cached factory proxy for the given bean type.
      */
     private ProxyBean getFactoryProxyBean(Object orig) {
-        // we don't lock here; ok if two proxies get generated for same type
         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 = getMostDerivedLoader(type, ProxyBean.class);
@@ -415,6 +441,18 @@
             _proxies.put(type, proxy);
         }
         return proxy;
+    }
+
+    /**
+     * Return whether the given type is known to be unproxyable.
+     */
+    protected boolean isUnproxyable(Class type) {
+        for (; type != null && type != Object.class; 
+            type = type.getSuperclass()) {
+            if (_unproxyable.contains(type.getName()))
+                return true;
+        }
+        return false;
     }
 
     /**