cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmen...@apache.org
Subject svn commit: r686321 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/
Date Fri, 15 Aug 2008 19:02:29 GMT
Author: kmenard
Date: Fri Aug 15 12:02:28 2008
New Revision: 686321

URL: http://svn.apache.org/viewvc?rev=686321&view=rev
Log:
Fixed CAY-1096: CayenneContext should support ThreadLocal operations

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    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/access/DataContext.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=686321&r1=686320&r2=686321&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Fri Aug 15 12:02:28 2008
@@ -30,6 +30,7 @@
 CAY-1070 Generating SelectQuery Access Code
 CAY-1085 Use standard JDBC API for writing Oracle LOBs
 CAY-1091 Upgrade to Hessian 3.1.6
+CAY-1096 CayenneContext should support ThreadLocal operations
 
 Bug fixes since M4:
 

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=686321&r1=686320&r2=686321&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
Fri Aug 15 12:02:28 2008
@@ -18,22 +18,17 @@
  ****************************************************************/
 package org.apache.cayenne;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
 import org.apache.cayenne.cache.MapQueryCache;
 import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.graph.GraphManager;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.ObjectIdQuery;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.reflect.AttributeProperty;
-import org.apache.cayenne.reflect.ClassDescriptor;
-import org.apache.cayenne.reflect.Property;
-import org.apache.cayenne.reflect.PropertyVisitor;
-import org.apache.cayenne.reflect.ToManyProperty;
-import org.apache.cayenne.reflect.ToOneProperty;
+import org.apache.cayenne.reflect.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 
 /**
  * A common base superclass for Cayenne ObjectContext implementors.
@@ -43,6 +38,42 @@
  */
 public abstract class BaseContext implements ObjectContext {
 
+    /**
+     * A holder of a ObjectContext bound to the current thread.
+     *
+     * @since 3.0
+     */
+    protected static final ThreadLocal<ObjectContext> threadObjectContext = new ThreadLocal<ObjectContext>();
+
+    /**
+     * Returns the ObjectContext bound to the current thread.
+     *
+     * @since 3.0
+     * @return the ObjectContext associated with caller thread.
+     * @throws IllegalStateException if there is no ObjectContext bound to the current
+     *             thread.
+     * @see org.apache.cayenne.conf.WebApplicationContextFilter
+     */
+    public static ObjectContext getThreadObjectContext() throws IllegalStateException {
+        ObjectContext context = threadObjectContext.get();
+        if (context == null) {
+            throw new IllegalStateException("Current thread has no bound DataContext.");
+        }
+
+        return context;
+    }
+
+    /**
+     * Binds a ObjectContext to the current thread. ObjectContext can later be retrieved
by
+     * users in the same thread by calling {@link BaseContext#getThreadObjectContext}.
+     * Using null parameter will unbind currently bound ObjectContext.
+     *
+     * @since 3.0
+     */
+    public static void bindThreadObjectContext(ObjectContext context) {
+        threadObjectContext.set(context);
+    }
+
     // if we are to pass the context around, channel should be left alone and
     // reinjected later if needed
     protected transient DataChannel channel;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java?rev=686321&r1=686320&r2=686321&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
Fri Aug 15 12:02:28 2008
@@ -19,31 +19,7 @@
 
 package org.apache.cayenne.access;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cayenne.BaseContext;
-import org.apache.cayenne.CayenneException;
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.DataObject;
-import org.apache.cayenne.DataObjectUtils;
-import org.apache.cayenne.DataRow;
-import org.apache.cayenne.DeleteDenyException;
-import org.apache.cayenne.Fault;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.Persistent;
-import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.*;
 import org.apache.cayenne.access.util.IteratedSelectObserver;
 import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.cache.QueryCacheFactory;
@@ -53,28 +29,19 @@
 import org.apache.cayenne.graph.GraphDiff;
 import org.apache.cayenne.graph.GraphEvent;
 import org.apache.cayenne.graph.GraphManager;
-import org.apache.cayenne.map.DbJoin;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.map.LifecycleEvent;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.query.NamedQuery;
-import org.apache.cayenne.query.ObjectIdQuery;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.QueryMetadata;
-import org.apache.cayenne.query.RefreshQuery;
-import org.apache.cayenne.reflect.AttributeProperty;
-import org.apache.cayenne.reflect.ClassDescriptor;
-import org.apache.cayenne.reflect.PropertyVisitor;
-import org.apache.cayenne.reflect.ToManyProperty;
-import org.apache.cayenne.reflect.ToOneProperty;
+import org.apache.cayenne.map.*;
+import org.apache.cayenne.query.*;
+import org.apache.cayenne.reflect.*;
 import org.apache.cayenne.util.EventUtil;
 import org.apache.cayenne.util.GenericResponse;
 import org.apache.cayenne.util.ObjectContextGraphAction;
 import org.apache.cayenne.util.Util;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.*;
+
 /**
  * The most common implementation of {@link ObjectContext}. DataContext is an isolated
  * container of an object graph, in a sense that any uncommitted changes to persistent
@@ -85,13 +52,6 @@
  */
 public class DataContext extends BaseContext implements DataChannel {
 
-    /**
-     * A holder of a DataContext bound to the current thread.
-     * 
-     * @since 1.1
-     */
-    protected static final ThreadLocal<DataContext> threadDataContext = new ThreadLocal<DataContext>();
-
     // Set of DataContextDelegates to be notified.
     private DataContextDelegate delegate;
 
@@ -130,14 +90,15 @@
      * @throws IllegalStateException if there is no DataContext bound to the current
      *             thread.
      * @see org.apache.cayenne.conf.WebApplicationContextFilter
+     * @deprecated since 3.0, replaced by BaseContex#getThreadObjectContext().
      */
     public static DataContext getThreadDataContext() throws IllegalStateException {
-        DataContext dc = threadDataContext.get();
-        if (dc == null) {
+        try {
+            return (DataContext) BaseContext.getThreadObjectContext();
+        }
+        catch(final IllegalStateException ex) {
             throw new IllegalStateException("Current thread has no bound DataContext.");
         }
-
-        return dc;
     }
 
     /**
@@ -146,9 +107,10 @@
      * Using null parameter will unbind currently bound DataContext.
      * 
      * @since 1.1
+     * @deprecated since 3.0, replaced by BaseContex#getThreadObjectContext().
      */
     public static void bindThreadDataContext(DataContext context) {
-        threadDataContext.set(context);
+        BaseContext.bindThreadObjectContext(context);
     }
 
     /**



Mime
View raw message