Jacques, You might want to review this commit.
-Adrian --- On Sun, 9/27/09, jler...@apache.org <jler...@apache.org> wrote: > From: jler...@apache.org <jler...@apache.org> > Subject: svn commit: r819274 - in /ofbiz/trunk/framework: > base/src/org/ofbiz/base/util/cache/UtilCache.java > common/data/CommonTypeData.xml > To: comm...@ofbiz.apache.org > Date: Sunday, September 27, 2009, 1:55 AM > Author: jleroux > Date: Sun Sep 27 08:55:38 2009 > New Revision: 819274 > > URL: http://svn.apache.org/viewvc?rev=819274&view=rev > Log: > Add GeoData_CN and geoTypeId="MUNICIPALITY" from Terence NG > (https://issues.apache.org/jira/browse/OFBIZ-2970) - > OFBIZ-2970 > > Modified: > > ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java > > ofbiz/trunk/framework/common/data/CommonTypeData.xml > > Modified: > ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java?rev=819274&r1=819273&r2=819274&view=diff > ============================================================================== > --- > ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java > (original) > +++ > ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java > Sun Sep 27 08:55:38 2009 > @@ -19,6 +19,7 @@ > package org.ofbiz.base.util.cache; > > import java.io.Serializable; > +import java.util.ArrayList; > import java.util.Collection; > import java.util.List; > import java.util.Map; > @@ -115,7 +116,9 @@ > > > setPropertiesParams(cacheName); > > - utilCacheTable.put(name, > this); > + synchronized (utilCacheTable) > { > + > utilCacheTable.put(name, this); > + } > } > > public UtilCache(String cacheName, > int maxSize, long expireTime, boolean useSoftReference) { > @@ -143,8 +146,9 @@ > String name = > "specified" + this.getNextDefaultIndex("specified"); > > > setPropertiesParams(name); > - > - utilCacheTable.put(name, > this); > + synchronized (utilCacheTable) > { > + > utilCacheTable.put(name, this); > + } > } > > /** This constructor takes a name > for the cache, puts itself in the utilCacheTable. > @@ -157,8 +161,9 @@ > > > setPropertiesParams("default"); > > setPropertiesParams(cacheName); > - > - utilCacheTable.put(name, > this); > + synchronized (utilCacheTable) > { > + > utilCacheTable.put(name, this); > + } > } > > /** This constructor takes a name > for the cache, puts itself in the utilCacheTable. > @@ -170,8 +175,9 @@ > > > setPropertiesParams("default"); > > setPropertiesParams(cacheName); > - > - utilCacheTable.put(name, > this); > + synchronized (utilCacheTable) > { > + > utilCacheTable.put(name, this); > + } > } > > /** Default constructor, all > members stay at default values as defined in > cache.properties, or the defaults in this file if > cache.properties is not found, or there are no 'default' > entries in it. */ > @@ -179,7 +185,9 @@ > > setPropertiesParams("default"); > > name = "default" + > this.getNextDefaultIndex("default"); > - utilCacheTable.put(name, > this); > + synchronized (utilCacheTable) > { > + > utilCacheTable.put(name, this); > + } > } > > protected String > getNextDefaultIndex(String cacheName) { > @@ -398,10 +406,24 @@ > > /** Removes all elements from this > cache */ > public static void > clearAllCaches() { > - for (Map.Entry<String, > UtilCache<?, ?>> entry: utilCacheTable.entrySet()) > { > - UtilCache<?, > ?> utilCache = entry.getValue(); > - > utilCache.clear(); > + // We make a copy since clear > may take time > + > List<UtilCache<?,?>> list = > getUtilCacheTableValuesImage(); > + for (UtilCache<?,?> > cache : list) { > + cache.clear(); > + } > + list.clear(); > + } > + > + /** > + * Return an image of the values > at a time > + * @return {...@link List} > + */ > + private static List > getUtilCacheTableValuesImage() { > + List list = new > ArrayList(utilCacheTable.size()); > + synchronized (utilCacheTable) > { > + > list.addAll(utilCacheTable.values()); > } > + return list; > } > > /** Getter for the name of the > UtilCache instance. > @@ -632,10 +654,12 @@ > > /** Clears all expired cache > entries from all caches */ > public static void > clearExpiredFromAllCaches() { > - for (Map.Entry<String, > UtilCache<?, ?>> entry: utilCacheTable.entrySet()) > { > - UtilCache<?, > ?> utilCache = entry.getValue(); > + // We make a copy since clear > may take time > + > List<UtilCache<?,?>> list = > getUtilCacheTableValuesImage(); > + for (UtilCache<?,?> > utilCache : list) { > > utilCache.clearExpired(); > } > + list.clear(); > } > > /** Checks for a non-expired key > in a specific cache */ > @@ -650,13 +674,20 @@ > > public static void > clearCachesThatStartWith(String startsWith) { > synchronized > (utilCacheTable) { > - for > (Map.Entry<String, UtilCache<?, ?>> entry: > utilCacheTable.entrySet()) { > - > String name = entry.getKey(); > - if > (name.startsWith(startsWith)) { > - > UtilCache<?, ?> cache = > entry.getValue(); > - > cache.clear(); > + > List<UtilCache<?, ?>> cachesToClear = > FastList.newInstance(); > + synchronized > (utilCacheTable) { > + > for (Map.Entry<String, UtilCache<?, ?>> entry: > utilCacheTable.entrySet()) { > + > String name = entry.getKey(); > + > if (name.startsWith(startsWith)) { > + > UtilCache<?, ?> cache = > entry.getValue(); > + > cachesToClear.add(cache); > + > } > > } > } > + for > (UtilCache<?,?> cache : cachesToClear) { > + > cache.clear(); > + } > + > cachesToClear.clear(); > } > } > > @@ -668,8 +699,6 @@ > > �...@suppresswarnings("unchecked") > public static <K, V> > UtilCache<K, V> findCache(String cacheName) { > - synchronized > (UtilCache.utilCacheTable) { > - return > (UtilCache<K, V>) > UtilCache.utilCacheTable.get(cacheName); > - } > + return (UtilCache<K, V>) > UtilCache.utilCacheTable.get(cacheName); > } > } > > Modified: > ofbiz/trunk/framework/common/data/CommonTypeData.xml > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/data/CommonTypeData.xml?rev=819274&r1=819273&r2=819274&view=diff > ============================================================================== > --- ofbiz/trunk/framework/common/data/CommonTypeData.xml > (original) > +++ ofbiz/trunk/framework/common/data/CommonTypeData.xml > Sun Sep 27 08:55:38 2009 > @@ -71,6 +71,7 @@ > <GeoType description="Country" > geoTypeId="COUNTRY" hasTable="N" parentTypeId=""/> > <GeoType description="County" > geoTypeId="COUNTY" hasTable="N" parentTypeId=""/> > <GeoType > description="County-City" geoTypeId="COUNTY_CITY" > hasTable="N" parentTypeId=""/> > + <GeoType description="Municipality" > geoTypeId="MUNICIPALITY" hasTable="N" parentTypeId=""/> > <GeoType description="Province" > geoTypeId="PROVINCE" hasTable="N" parentTypeId=""/> > <GeoType description="Region" > geoTypeId="REGION" hasTable="N" parentTypeId=""/> > <GeoType > description="Territory" geoTypeId="TERRITORY" hasTable="N" > parentTypeId=""/> > > >