cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1164790 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: BaseContext.java ObjectContext.java
Date Sat, 03 Sep 2011 02:00:53 GMT
Author: aadamchik
Date: Sat Sep  3 02:00:53 2011
New Revision: 1164790

URL: http://svn.apache.org/viewvc?rev=1164790&view=rev
Log:
replacing context properties with a concurrent map

it really costs us nothing to support, and frees the user from synchronization headache

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java?rev=1164790&r1=1164789&r2=1164790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
Sat Sep  3 02:00:53 2011
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.cayenne.cache.NestedQueryCache;
 import org.apache.cayenne.cache.QueryCache;
@@ -109,7 +110,7 @@ public abstract class BaseContext implem
      * 
      * @since 3.0
      */
-    protected Map<String, Object> userProperties;
+    protected volatile Map<String, Object> userProperties;
 
     protected BaseContext() {
         graphAction = new ObjectContextGraphAction(this);
@@ -449,10 +450,15 @@ public abstract class BaseContext implem
      * @since 3.0
      */
     protected Map<String, Object> getUserProperties() {
+
         // as not all users will take advantage of properties, creating the
-        // map on demand to keep DataContext lean...
+        // map on demand to keep the context lean...
         if (userProperties == null) {
-            userProperties = new HashMap<String, Object>();
+            synchronized (this) {
+                if (userProperties == null) {
+                    userProperties = new ConcurrentHashMap<String, Object>();
+                }
+            }
         }
 
         return userProperties;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java?rev=1164790&r1=1164789&r2=1164790&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
Sat Sep  3 02:00:53 2011
@@ -223,18 +223,18 @@ public interface ObjectContext extends S
     <T> void invalidateObjects(T... objects);
 
     /**
-     * Returns a user-defined property previously set via 'setUserProperty'. Note that it
-     * is a caller responsibility to synchronize access to properties.
+     * Returns a user-defined property previously set via 'setUserProperty'. Concurrent
+     * access to properties does not require any special synchronization
      * 
      * @since 3.0
      */
-    public Object getUserProperty(String key);
+    Object getUserProperty(String key);
 
     /**
-     * Sets a user-defined property. Note that it is a caller responsibility to
-     * synchronize access to properties.
+     * Sets a user-defined property. Concurrent access to properties does not require any
+     * special synchronization
      * 
      * @since 3.0
      */
-    public void setUserProperty(String key, Object value);
+    void setUserProperty(String key, Object value);
 }



Mime
View raw message