openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r509793 - /incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java
Date Tue, 20 Feb 2007 22:51:50 GMT
Author: pcl
Date: Tue Feb 20 14:51:50 2007
New Revision: 509793

URL: http://svn.apache.org/viewvc?view=rev&rev=509793
Log:
OPENJPA-156. Applied Michael Dick's patch (thanks). Updated symbolic constant to use OpenJPA
norms, changed references to external symbolic constants to use constants from the map impl
being used, and reduced if-else statements for readability.

Modified:
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java?view=diff&rev=509793&r1=509792&r2=509793
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java
Tue Feb 20 14:51:50 2007
@@ -23,6 +23,7 @@
 import java.util.MissingResourceException;
 import java.util.Properties;
 import java.util.TreeSet;
+
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -34,6 +35,9 @@
 import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.lib.util.ParseException;
 import org.apache.openjpa.lib.util.StringDistance;
+import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
+import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
+
 import serp.util.Strings;
 
 /**
@@ -46,6 +50,12 @@
 
     private static final Localizer _loc = Localizer.forPackage
         (Configurations.class);
+    
+    private static ConcurrentReferenceHashMap _loaders = new 
+        ConcurrentReferenceHashMap(ConcurrentReferenceHashMap.WEAK, 
+                ConcurrentReferenceHashMap.HARD);
+
+    private static final Object NULL_LOADER = "null-loader";
 
     /**
      * Return the class name from the given plugin string, or null if none.
@@ -163,18 +173,33 @@
         if (StringUtils.isEmpty(clsName))
             return null;
 
-        Class cls = null;
-        try {
-            cls = Strings.toClass(clsName, findDerivedLoader(conf, loader));
-        } catch (RuntimeException re) {
-            if (val != null)
-                re = getCreateException(clsName, val, re);
-            if (fatal)
-                throw re;
-            Log log = (conf == null) ? null : conf.getConfigurationLog();
-            if (log != null && log.isErrorEnabled())
-                log.error(_loc.get("plugin-creation-exception", val), re);
-            return null;
+        Class cls = null; 
+
+        // can't have a null reference in the map, so use symbolic 
+        // constant as key
+        Object key = loader == null ? NULL_LOADER : loader;
+        Map loaderCache = (Map) _loaders.get(key);
+        if (loaderCache == null) { // We don't have a cache for this loader.
+            loaderCache = new ConcurrentHashMap();
+            _loaders.put(key, loaderCache);
+        } else {  // We have a cache for this loader.
+            cls = (Class) loaderCache.get(clsName);
+        }
+
+        if (cls == null) { // we haven't cached this.
+            try {
+                cls = Strings.toClass(clsName, findDerivedLoader(conf, loader));
+                loaderCache.put(clsName, cls);
+            } catch (RuntimeException re) {
+                if (val != null)
+                    re = getCreateException(clsName, val, re);
+                if (fatal)
+                    throw re;
+                Log log = (conf == null) ? null : conf.getConfigurationLog();
+                if (log != null && log.isErrorEnabled())
+                    log.error(_loc.get("plugin-creation-exception", val), re);
+                return null;
+            }
         }
 
         try {



Mime
View raw message