You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2009/09/27 10:55:38 UTC

svn commit: r819274 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/cache/UtilCache.java common/data/CommonTypeData.xml

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=""/>



Re: svn commit: r819274 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/cache/UtilCache.java common/data/CommonTypeData.xml

Posted by Jacques Le Roux <ja...@les7arts.com>.
From: "Jacques Le Roux" <ja...@les7arts.com>
> Thanks Adrian,
>
> It have been already done this morning at r819277+819278, was just a wrong check box in Tortoise :/


It has BTW :/

Jacques

> Jacques
>
> From: "Adrian Crum" <ad...@yahoo.com>
>> Jacques,
>>
>> You might want to review this commit.
>>
>> -Adrian
>>
>> --- On Sun, 9/27/09, jleroux@apache.org <jl...@apache.org> wrote:
>>
>>> From: jleroux@apache.org <jl...@apache.org>
>>> Subject: svn commit: r819274 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/cache/UtilCache.java
>>> common/data/CommonTypeData.xml
>>> To: commits@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=""/>
>>>
>>>
>>>
>>
>>
>>
>>
>>
>
> 



Re: svn commit: r819274 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/cache/UtilCache.java common/data/CommonTypeData.xml

Posted by Jacques Le Roux <ja...@les7arts.com>.
Thanks Adrian,

It have been already done this morning at r819277+819278, was just a wrong check box in Tortoise :/

Jacques

From: "Adrian Crum" <ad...@yahoo.com>
> Jacques,
>
> You might want to review this commit.
>
> -Adrian
>
> --- On Sun, 9/27/09, jleroux@apache.org <jl...@apache.org> wrote:
>
>> From: jleroux@apache.org <jl...@apache.org>
>> Subject: svn commit: r819274 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/cache/UtilCache.java
>> common/data/CommonTypeData.xml
>> To: commits@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=""/>
>>
>>
>>
>
>
>
>
>



Re: svn commit: r819274 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/cache/UtilCache.java common/data/CommonTypeData.xml

Posted by Adrian Crum <ad...@yahoo.com>.
Jacques,

You might want to review this commit.

-Adrian

--- On Sun, 9/27/09, jleroux@apache.org <jl...@apache.org> wrote:

> From: jleroux@apache.org <jl...@apache.org>
> Subject: svn commit: r819274 - in /ofbiz/trunk/framework: base/src/org/ofbiz/base/util/cache/UtilCache.java common/data/CommonTypeData.xml
> To: commits@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=""/>
> 
> 
>