cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r953516 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ framework/caye...
Date Fri, 11 Jun 2010 00:38:08 GMT
Author: aadamchik
Date: Fri Jun 11 00:38:07 2010
New Revision: 953516

URL: http://svn.apache.org/viewvc?rev=953516&view=rev
Log:
CAY-1446 Remove DataContextFactory, replace it with DI-enabled ObjectContextFactory

* removed DCF, added an internal one provided via DI
* deprecate DD.createDataContext factory method as this should be done via injection
* cleaning up unit tests to remove calls to deprecated methods... CayenneCase superclass is still using the deprecated method
  for context creation until we figure out unit test injection

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ObjectContextFactory.java
      - copied, changed from r953514, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataContextProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/MockDataContextFactory.java
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/access/ClientServerChannel.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectInCtxtTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectRelTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextQueryCachingTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSerializationTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSharedCacheTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/InheritanceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentPeerEventsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/BindDirectiveTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.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=953516&r1=953515&r2=953516&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 Jun 11 00:38:07 2010
@@ -44,6 +44,7 @@ CAY-1425 Remove Configuration sharedConf
 CAY-1433 Change #chunk behaviour to skipe only null arguments (don't skip 0 or false)
 CAY-1438 refactoring EntityInheritanceTree lookups
 CAY-1439 ClassDescriptor refactoring - replacing returned iterators with collections
+CAY-1446 Remove DataContextFactory, replace it with DI-enabled ObjectContextFactory
 
 Bug Fixes Since 3.0:
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ClientServerChannel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ClientServerChannel.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ClientServerChannel.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ClientServerChannel.java Fri Jun 11 00:38:07 2010
@@ -38,6 +38,10 @@ public class ClientServerChannel impleme
 
     protected DataContext serverContext;
 
+    /**
+     * @deprecated since 3.1 as context creation is now factory based.
+     */
+    @Deprecated
     public ClientServerChannel(DataDomain domain) {
         this(domain.createDataContext());
     }

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=953516&r1=953515&r2=953516&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 Jun 11 00:38:07 2010
@@ -142,15 +142,12 @@ public class DataContext extends BaseCon
      * @since 3.0
      */
     public ObjectContext createChildContext() {
-        DataContextFactory factory = getParentDataDomain().getDataContextFactory();
 
         // child ObjectStore should not have direct access to snapshot cache, so do not
         // pass it in constructor.
         ObjectStore objectStore = new ObjectStore();
 
-        DataContext child = factory != null
-                ? factory.createDataContext(this, objectStore)
-                : new DataContext(this, objectStore);
+        DataContext child = new DataContext(this, objectStore);
 
         child.setValidatingObjectsOnCommit(isValidatingObjectsOnCommit());
         child.usingSharedSnaphsotCache = isUsingSharedSnapshotCache();
@@ -1071,6 +1068,13 @@ public class DataContext extends BaseCon
     public boolean isUsingSharedSnapshotCache() {
         return usingSharedSnaphsotCache;
     }
+    
+    /**
+     * @since 3.1
+     */
+    public void setUsingSharedSnapshotCache(boolean flag) {
+        this.usingSharedSnaphsotCache = flag;
+    }
 
     /**
      * Returns whether this DataContext performs object validation before commit is

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java Fri Jun 11 00:38:07 2010
@@ -35,6 +35,8 @@ import org.apache.cayenne.access.jdbc.Ba
 import org.apache.cayenne.cache.MapQueryCacheFactory;
 import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.cache.QueryCacheFactory;
+import org.apache.cayenne.configuration.ObjectContextFactory;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.event.EventManager;
 import org.apache.cayenne.graph.CompoundDiff;
 import org.apache.cayenne.graph.GraphDiff;
@@ -45,7 +47,6 @@ import org.apache.cayenne.map.EntitySort
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.QueryChain;
 import org.apache.cayenne.util.ToStringBuilder;
-import org.apache.cayenne.util.Util;
 import org.apache.commons.collections.Transformer;
 
 /**
@@ -66,13 +67,6 @@ public class DataDomain implements Query
     public static final boolean USING_EXTERNAL_TRANSACTIONS_DEFAULT = false;
 
     /**
-     * Defines a property name for storing an optional DataContextFactory.
-     * 
-     * @since 1.2
-     */
-    public static final String DATA_CONTEXT_FACTORY_PROPERTY = "cayenne.DataDomain.dataContextFactory";
-
-    /**
      * Defines a property name for storing optional {@link QueryCacheFactory}.
      * 
      * @since 3.0
@@ -89,12 +83,12 @@ public class DataDomain implements Query
      * Properties configured for DataDomain. These include properties of the DataRowStore
      * and remote notifications.
      */
-    protected Map<String, String> properties = Collections.synchronizedMap(new TreeMap<String, String>());
+    protected Map<String, String> properties = Collections
+            .synchronizedMap(new TreeMap<String, String>());
 
     protected EntityResolver entityResolver;
     protected DataRowStore sharedSnapshotCache;
     protected TransactionDelegate transactionDelegate;
-    protected DataContextFactory dataContextFactory;
     protected QueryCacheFactory queryCacheFactory;
     protected String name;
 
@@ -106,6 +100,7 @@ public class DataDomain implements Query
     /**
      * @since 1.2
      */
+    @Inject
     protected EventManager eventManager;
 
     /**
@@ -119,9 +114,9 @@ public class DataDomain implements Query
     protected QueryCache queryCache;
 
     protected boolean stopped;
-    
+
     /**
-     * Factory for creating QueryBuilders. Might be null, then default one will be used. 
+     * Factory for creating QueryBuilders. Might be null, then default one will be used.
      * Server-only.
      */
     private BatchQueryBuilderFactory queryBuilderFactory;
@@ -207,7 +202,6 @@ public class DataDomain implements Query
         sharedCacheEnabled = SHARED_CACHE_ENABLED_DEFAULT;
         validatingObjectsOnCommit = VALIDATING_OBJECTS_ON_COMMIT_DEFAULT;
         usingExternalTransactions = USING_EXTERNAL_TRANSACTIONS_DEFAULT;
-        dataContextFactory = null;
     }
 
     /**
@@ -230,7 +224,6 @@ public class DataDomain implements Query
         String usingExternalTransactions = localMap
                 .get(USING_EXTERNAL_TRANSACTIONS_PROPERTY);
 
-        String dataContextFactory = localMap.get(DATA_CONTEXT_FACTORY_PROPERTY);
         String queryCacheFactoryName = localMap.get(QUERY_CACHE_FACTORY_PROPERTY);
 
         // init ivars from properties
@@ -243,18 +236,7 @@ public class DataDomain implements Query
                 ? "true".equalsIgnoreCase(usingExternalTransactions)
                 : USING_EXTERNAL_TRANSACTIONS_DEFAULT;
 
-        if (dataContextFactory != null && !Util.isEmptyString(dataContextFactory)) {
-            this.dataContextFactory = createInstance(
-                    dataContextFactory,
-                    DataContextFactory.class);
-        }
-        else {
-            this.dataContextFactory = null;
-        }
-
-        if (queryCacheFactoryName != null
-                && dataContextFactory != null
-                && !Util.isEmptyString(dataContextFactory)) {
+        if (queryCacheFactoryName != null) {
             queryCacheFactory = createInstance(
                     queryCacheFactoryName,
                     QueryCacheFactory.class);
@@ -456,14 +438,6 @@ public class DataDomain implements Query
         }
     }
 
-    public DataContextFactory getDataContextFactory() {
-        return dataContextFactory;
-    }
-
-    public void setDataContextFactory(DataContextFactory dataContextFactory) {
-        this.dataContextFactory = dataContextFactory;
-    }
-
     /** Registers new DataMap with this domain. */
     public void addMap(DataMap map) {
         getEntityResolver().addDataMap(map);
@@ -576,7 +550,11 @@ public class DataDomain implements Query
      * Creates and returns a new DataContext. If this DataDomain is configured to use
      * shared cache, returned DataContext will use shared cache as well. Otherwise a new
      * instance of DataRowStore will be used as its local cache.
+     * 
+     * @deprecated since 3.1 as context creation is done via {@link ObjectContextFactory}
+     *             and injection.
      */
+    @Deprecated
     public DataContext createDataContext() {
         return createDataContext(isSharedCacheEnabled());
     }
@@ -588,7 +566,10 @@ public class DataDomain implements Query
      *            vs. local cache. This setting overrides default behavior configured for
      *            this DataDomain via {@link #SHARED_CACHE_ENABLED_PROPERTY}.
      * @since 1.1
+     * @deprecated since 3.1 as context creation is done via {@link ObjectContextFactory}
+     *             and injection.
      */
+    @Deprecated
     public DataContext createDataContext(boolean useSharedCache) {
         // for new dataRowStores use the same name for all stores
         // it makes it easier to track the event subject
@@ -596,14 +577,8 @@ public class DataDomain implements Query
                 ? nonNullSharedSnapshotCache()
                 : new DataRowStore(name, properties, eventManager);
 
-        DataContext context;
-        if (null == dataContextFactory) {
-            context = new DataContext(this, new ObjectStore(snapshotCache));
-        }
-        else {
-            context = dataContextFactory.createDataContext(this, new ObjectStore(
-                    snapshotCache));
-        }
+        DataContext context = new DataContext(this, new ObjectStore(snapshotCache));
+
         context.setValidatingObjectsOnCommit(isValidatingObjectsOnCommit());
         return context;
     }
@@ -923,14 +898,14 @@ public class DataDomain implements Query
     QueryCache getQueryCacheInternal() {
         return queryCache;
     }
-    
+
     /**
      * Sets factory for creating QueryBuilders
      */
     public void setQueryBuilderFactory(BatchQueryBuilderFactory queryBuilderFactory) {
         this.queryBuilderFactory = queryBuilderFactory;
     }
-    
+
     /**
      * @return factory for creating QueryBuilders. Might be null
      */

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java Fri Jun 11 00:38:07 2010
@@ -92,9 +92,19 @@ public abstract class CayenneRuntime {
     /**
      * Returns an ObjectContext based on the runtime DataChannel. Default configuration
      * will return a new instance of the ObjectContext on every call, as the corresponding
-     * factory is bound using NO_SCOPE scope. Custom modules may change this behavior.
+     * factory is bound using "no scope" scope. Custom modules may change this behavior.
      */
     public ObjectContext getContext() {
-        return injector.getInstance(ObjectContext.class);
+        return injector.getInstance(ObjectContextFactory.class).createContext();
+    }
+
+    /**
+     * Returns an ObjectContext based on the runtime DataChannel. Default configuration
+     * will return a new instance of the ObjectContext on every call, as the corresponding
+     * factory is bound using "no scope" scope. Custom modules may change this behavior.
+     */
+    public ObjectContext getContext(DataChannel parentChannel) {
+        return injector.getInstance(ObjectContextFactory.class).createContext(
+                parentChannel);
     }
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ObjectContextFactory.java (from r953514, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextFactory.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ObjectContextFactory.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ObjectContextFactory.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextFactory.java&r1=953514&r2=953516&rev=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContextFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ObjectContextFactory.java Fri Jun 11 00:38:07 2010
@@ -16,24 +16,26 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-
-package org.apache.cayenne.access;
+package org.apache.cayenne.configuration;
 
 import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
 
 /**
- * An interface for creating DataContexts.
+ * A factory for regular and nested contexts.
  * 
- * @since 1.2
+ * @since 3.1
  */
-public interface DataContextFactory {
+public interface ObjectContextFactory {
+
+    /**
+     * Creates an ObjectContext attached to a default DataChannel.
+     */
+    ObjectContext createContext();
+
     /**
-     * Creates a DataContext with parent QueryEngine and a DataRowStore that should be
-     * used by the ObjectStore.
-     * 
-     * @since 1.2
-     * @param parent parent QueryEngine used to communicate with the data source.
-     * @param objectStore ObjectStore used by DataContext.
+     * Creates an ObjectContext attached to a provided channel. This is often used for
+     * nested context creation.
      */
-    DataContext createDataContext(DataChannel parent, ObjectStore objectStore);
+    ObjectContext createContext(DataChannel parent);
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java Fri Jun 11 00:38:07 2010
@@ -19,7 +19,6 @@
 package org.apache.cayenne.configuration.server;
 
 import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
 import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
@@ -31,6 +30,7 @@ import org.apache.cayenne.configuration.
 import org.apache.cayenne.configuration.DefaultAdhocObjectFactory;
 import org.apache.cayenne.configuration.DefaultConfigurationNameMapper;
 import org.apache.cayenne.configuration.DefaultRuntimeProperties;
+import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader;
 import org.apache.cayenne.configuration.XMLDataMapLoader;
@@ -105,10 +105,7 @@ public class CayenneServerModule impleme
         // will return DataDomain for request for a DataChannel
         binder.bind(DataChannel.class).toProvider(DomainDataChannelProvider.class);
 
-        binder
-                .bind(ObjectContext.class)
-                .toProvider(DataContextProvider.class)
-                .withoutScope();
+        binder.bind(ObjectContextFactory.class).to(DataContextFactory.class);
 
         // a service to load project XML descriptors
         binder.bind(DataChannelDescriptorLoader.class).to(

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java?rev=953516&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataContextFactory.java Fri Jun 11 00:38:07 2010
@@ -0,0 +1,113 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.configuration.server;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.DataRowStore;
+import org.apache.cayenne.access.ObjectStore;
+import org.apache.cayenne.configuration.ObjectContextFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.event.EventManager;
+
+/**
+ * @since 3.1
+ */
+public class DataContextFactory implements ObjectContextFactory {
+
+    @Inject
+    protected DataDomain dataDomain;
+
+    @Inject
+    protected EventManager eventManager;
+
+    @Inject
+    protected Injector injector;
+
+    public ObjectContext createContext() {
+        return createdFromDataDomain(dataDomain);
+    }
+
+    public ObjectContext createContext(DataChannel parent) {
+
+        // this switch may go away once we figure out clean property configuration...
+        if (parent instanceof DataDomain) {
+            return createdFromDataDomain((DataDomain) parent);
+        }
+        else if (parent instanceof DataContext) {
+            return createFromDataContext((DataContext) parent);
+        }
+        else {
+            return createFromGenericChannel(parent);
+        }
+    }
+
+    protected ObjectContext createFromGenericChannel(DataChannel parent) {
+
+        // for new dataRowStores use the same name for all stores
+        // it makes it easier to track the event subject
+        DataRowStore snapshotCache = (dataDomain.isSharedCacheEnabled()) ? dataDomain
+                .getSharedSnapshotCache() : new DataRowStore(
+                dataDomain.getName(),
+                dataDomain.getProperties(),
+                eventManager);
+
+        DataContext context = new DataContext(parent, new ObjectStore(snapshotCache));
+        context.setValidatingObjectsOnCommit(dataDomain.isValidatingObjectsOnCommit());
+
+        injector.injectMembers(context);
+
+        return context;
+    }
+
+    protected ObjectContext createFromDataContext(DataContext parent) {
+        // child ObjectStore should not have direct access to snapshot cache, so do not
+        // pass it in constructor.
+        ObjectStore objectStore = new ObjectStore();
+
+        DataContext context = new DataContext(parent, objectStore);
+
+        context.setValidatingObjectsOnCommit(parent.isValidatingObjectsOnCommit());
+        context.setUsingSharedSnapshotCache(parent.isUsingSharedSnapshotCache());
+
+        injector.injectMembers(context);
+
+        return context;
+    }
+
+    protected ObjectContext createdFromDataDomain(DataDomain parent) {
+
+        // for new dataRowStores use the same name for all stores
+        // it makes it easier to track the event subject
+        DataRowStore snapshotCache = (parent.isSharedCacheEnabled()) ? parent
+                .getSharedSnapshotCache() : new DataRowStore(parent.getName(), parent
+                .getProperties(), eventManager);
+
+        DataContext context = new DataContext(parent, new ObjectStore(snapshotCache));
+        context.setValidatingObjectsOnCommit(parent.isValidatingObjectsOnCommit());
+
+        injector.injectMembers(context);
+
+        return context;
+    }
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java Fri Jun 11 00:38:07 2010
@@ -34,8 +34,8 @@ import org.apache.cayenne.configuration.
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.event.EventManager;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.resource.Resource;
 import org.apache.cayenne.resource.ResourceLocator;
@@ -72,9 +72,9 @@ public class DataDomainProvider implemen
 
     @Inject
     protected AdhocObjectFactory objectFactory;
-    
+
     @Inject
-    protected EventManager eventManager;
+    protected Injector injector;
 
     protected volatile DataDomain dataDomain;
 
@@ -158,7 +158,8 @@ public class DataDomainProvider implemen
 
         DataChannelDescriptor descriptor = tree.getRootNode();
         DataDomain dataDomain = new DataDomain(descriptor.getName());
-        dataDomain.setEventManager(eventManager);
+        injector.injectMembers(dataDomain);
+
         dataDomain.initWithProperties(descriptor.getProperties());
 
         for (DataMap dataMap : descriptor.getDataMaps()) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/hessian/service/HessianService.java Fri Jun 11 00:38:07 2010
@@ -24,7 +24,7 @@ import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
-import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.remote.service.HttpRemoteService;
 
@@ -46,9 +46,9 @@ public class HessianService extends Http
     /**
      * @since 3.1
      */
-    public HessianService(@Inject DataDomain domain,
+    public HessianService(@Inject ObjectContextFactory contextFactory,
             @Inject(EVENT_BRIDGE_PROPERTIES_MAP) Map<String, String> eventBridgeProperties) {
-        super(domain, eventBridgeProperties);
+        super(contextFactory, eventBridgeProperties);
     }
 
     @Override

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/BaseRemoteService.java Fri Jun 11 00:38:07 2010
@@ -26,7 +26,8 @@ import java.util.Map;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.access.ClientServerChannel;
-import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.remote.ClientMessage;
 import org.apache.cayenne.remote.RemoteService;
 import org.apache.cayenne.remote.RemoteSession;
@@ -47,21 +48,22 @@ public abstract class BaseRemoteService 
     // keep logger non-static so that it could be garbage collected with this instance.
     protected final Log logger;
 
-    protected DataDomain domain;
+    protected ObjectContextFactory contextFactory;
     protected String eventBridgeFactoryName;
     protected Map<String, String> eventBridgeParameters;
 
     /**
      * @since 3.1
      */
-    public BaseRemoteService(DataDomain domain, Map<String, String> eventBridgeProperties) {
+    public BaseRemoteService(ObjectContextFactory contextFactory,
+            Map<String, String> eventBridgeProperties) {
 
         logger = LogFactory.getLog(getClass());
 
         // start Cayenne service
         logger.debug("ROP service is starting");
 
-        this.domain = domain;
+        this.contextFactory = contextFactory;
         initEventBridgeParameters(eventBridgeProperties);
 
         logger.debug(getClass().getName() + " started");
@@ -77,15 +79,6 @@ public abstract class BaseRemoteService 
     }
 
     /**
-     * Returns a DataChannel that is a parent of all session DataChannels.
-     * 
-     * @deprecated unused since 3.1
-     */
-    public DataChannel getRootChannel() {
-        return domain;
-    }
-
-    /**
      * Creates a new ServerSession with a dedicated DataChannel.
      */
     protected abstract ServerSession createServerSession();
@@ -184,7 +177,7 @@ public abstract class BaseRemoteService 
      * security.
      */
     protected DataChannel createChannel() {
-        return new ClientServerChannel(domain);
+        return new ClientServerChannel((DataContext) contextFactory.createContext());
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/service/HttpRemoteService.java Fri Jun 11 00:38:07 2010
@@ -26,7 +26,7 @@ import java.util.Map;
 import javax.servlet.http.HttpSession;
 
 import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.remote.RemoteSession;
 
 /**
@@ -45,8 +45,9 @@ public abstract class HttpRemoteService 
     /**
      * @since 3.1
      */
-    public HttpRemoteService(DataDomain domain, Map<String, String> eventBridgeProperties) {
-        super(domain, eventBridgeProperties);
+    public HttpRemoteService(ObjectContextFactory contextFactory,
+            Map<String, String> eventBridgeProperties) {
+        super(contextFactory, eventBridgeProperties);
         this.sharedChannels = new HashMap<String, WeakReference<DataChannel>>();
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectInCtxtTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectInCtxtTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectInCtxtTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectInCtxtTest.java Fri Jun 11 00:38:07 2010
@@ -256,7 +256,7 @@ public class CayenneDataObjectInCtxtTest
         getDomain().getEventManager().removeAllListeners(
                 getDomain().getSharedSnapshotCache().getSnapshotEventSubject());
         getDomain().getSharedSnapshotCache().clear();
-        context = getDomain().createDataContext();
+        context = createDataContext();
 
         List artists = context.performQuery(new SelectQuery(Artist.class));
         Artist artist = (Artist) artists.get(0);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectRelTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectRelTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectRelTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneDataObjectRelTest.java Fri Jun 11 00:38:07 2010
@@ -210,7 +210,7 @@ public class CayenneDataObjectRelTest ex
     }
 
     public void testCrossContextRelationshipException() {
-        DataContext otherContext = getDomain().createDataContext();
+        DataContext otherContext = createDataContext();
         // Create this object in one context...
         Artist artist = (Artist) ctxt.newObject("Artist");
         // ...and this object in another context

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsTest.java Fri Jun 11 00:38:07 2010
@@ -101,7 +101,7 @@ public class DataContextDataChannelEvent
         final MockChannelListener listener = new MockChannelListener();
         EventUtil.listenForChannelEvents(context, listener);
 
-        DataContext peer = context.getParentDataDomain().createDataContext();
+        DataContext peer = createDataContextWithSharedCache(false);
         Artist a1 = (Artist) peer.localObject(a.getObjectId(), a);
 
         a1.setArtistName("Y");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateSharedCacheTest.java Fri Jun 11 00:38:07 2010
@@ -39,7 +39,7 @@ public class DataContextDelegateSharedCa
     protected void setUp() throws Exception {
         super.setUp();
 
-        context = createDataContextWithSharedCache();
+        context = createDataContextWithSharedCache(true);
 
         // prepare a single artist record
         artist = (Artist) context.newObject("Artist");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDelegateTest.java Fri Jun 11 00:38:07 2010
@@ -44,7 +44,7 @@ public class DataContextDelegateTest ext
     protected void setUp() throws Exception {
         super.setUp();
 
-        context = createDataContextWithSharedCache();
+        context = createDataContextWithSharedCache(true);
 
         // prepare a single gallery record
         gallery = (Gallery) context.newObject("Gallery");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDeleteRulesTest.java Fri Jun 11 00:38:07 2010
@@ -44,7 +44,7 @@ public class DataContextDeleteRulesTest 
         super.setUp();
 
         deleteTestData();
-        context = getDomain().createDataContext();
+        context = createDataContext();
     }
 
     public void testNullifyToOne() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLDeleteTest.java Fri Jun 11 00:38:07 2010
@@ -34,7 +34,7 @@ public class DataContextEJBQLDeleteTest 
     @Override
     protected void setUp() throws Exception {
         deleteTestData();
-        context = getDomain().createDataContext();
+        context = createDataContext();
     }
     
     public void testDeleteNoIdVar() throws Exception {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEntityWithMeaningfulPKTest.java Fri Jun 11 00:38:07 2010
@@ -41,7 +41,7 @@ public class DataContextEntityWithMeanin
         super.setUp();
 
         deleteTestData();
-        context = getDomain().createDataContext();
+        context = createDataContext();
     }
 
     public void testInsertWithMeaningfulPK() throws Exception {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPerformQueryAPITest.java Fri Jun 11 00:38:07 2010
@@ -17,7 +17,6 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.access;
 
 import java.math.BigDecimal;
@@ -63,7 +62,7 @@ public class DataContextPerformQueryAPIT
                 33018), null);
         Map parameters = Collections.singletonMap("artist", a);
 
-        List paintings = createDataContext()
+        List paintings = createDataContextWithSharedCache(false)
                 .performQuery("ObjectQuery", parameters, true);
         assertNotNull(paintings);
         assertEquals(1, paintings.size());
@@ -190,10 +189,9 @@ public class DataContextPerformQueryAPIT
         blockQueries();
 
         try {
-            List artists1 = context
-                    .getParentDataDomain()
-                    .createDataContext()
-                    .performQuery("QueryWithSharedCache", false);
+            List artists1 = createDataContextWithSharedCache(false).performQuery(
+                    "QueryWithSharedCache",
+                    false);
             assertEquals(25, artists1.size());
         }
         finally {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextQueryCachingTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextQueryCachingTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextQueryCachingTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextQueryCachingTest.java Fri Jun 11 00:38:07 2010
@@ -30,8 +30,6 @@ import org.apache.cayenne.query.QueryMet
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.unit.CayenneCase;
 
-/**
- */
 public class DataContextQueryCachingTest extends CayenneCase {
 
     protected DataContext context;
@@ -40,11 +38,7 @@ public class DataContextQueryCachingTest
     protected void setUp() throws Exception {
         super.setUp();
 
-        context = createDataContextWithSharedCache();
-    }
-
-    protected DataContext createDataContextNoCacheClear() {
-        return getDomain().createDataContext();
+        context = createDataContextWithSharedCache(true);
     }
 
     public void testLocalCacheDataRowsRefresh() throws Exception {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSerializationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSerializationTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSerializationTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSerializationTest.java Fri Jun 11 00:38:07 2010
@@ -45,7 +45,7 @@ public class DataContextSerializationTes
 
     public void testSerializeResolver() throws Exception {
 
-        DataContext context = createDataContextWithSharedCache();
+        DataContext context = createDataContextWithSharedCache(true);
 
         DataContext deserializedContext = (DataContext) Util
                 .cloneViaSerialization(context);
@@ -56,7 +56,7 @@ public class DataContextSerializationTes
 
     public void testSerializeChannel() throws Exception {
 
-        DataContext context = createDataContextWithSharedCache();
+        DataContext context = createDataContextWithSharedCache(true);
 
         DataContext deserializedContext = (DataContext) Util
                 .cloneViaSerialization(context);
@@ -66,7 +66,7 @@ public class DataContextSerializationTes
     }
 
     public void testSerializeNestedChannel() throws Exception {
-        DataContext context = createDataContextWithSharedCache();
+        DataContext context = createDataContextWithSharedCache(true);
         ObjectContext child = context.createChildContext();
 
         ObjectContext deserializedContext = (ObjectContext) Util
@@ -80,7 +80,7 @@ public class DataContextSerializationTes
 
         createTestData("prepare");
 
-        DataContext context = createDataContextWithSharedCache();
+        DataContext context = createDataContextWithSharedCache(true);
 
         DataContext deserializedContext = (DataContext) Util
                 .cloneViaSerialization(context);
@@ -140,7 +140,7 @@ public class DataContextSerializationTes
 
     public void testSerializeNew() throws Exception {
 
-        DataContext context = createDataContextWithSharedCache();
+        DataContext context = createDataContextWithSharedCache(true);
 
         Artist artist = (Artist) context.newObject("Artist");
         artist.setArtistName("artist1");
@@ -166,7 +166,7 @@ public class DataContextSerializationTes
 
     public void testSerializeCommitted() throws Exception {
 
-        DataContext context = createDataContextWithSharedCache();
+        DataContext context = createDataContextWithSharedCache(true);
 
         Artist artist = (Artist) context.newObject("Artist");
         artist.setArtistName("artist1");
@@ -201,7 +201,7 @@ public class DataContextSerializationTes
 
     public void testSerializeModified() throws Exception {
 
-        DataContext context = createDataContextWithSharedCache();
+        DataContext context = createDataContextWithSharedCache(true);
 
         Artist artist = (Artist) context.newObject("Artist");
         artist.setArtistName("artist1");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSharedCacheTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSharedCacheTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSharedCacheTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextSharedCacheTest.java Fri Jun 11 00:38:07 2010
@@ -52,7 +52,7 @@ public class DataContextSharedCacheTest 
     protected void setUp() throws Exception {
         super.setUp();
 
-        context = createDataContextWithSharedCache();
+        context = createDataContextWithSharedCache(true);
 
         // prepare a single artist record
         artist = (Artist) context.newObject("Artist");
@@ -70,8 +70,8 @@ public class DataContextSharedCacheTest 
         final String newName = "version2";
 
         // create alternative context making sure that no cache is flushed
-        DataContext altContext = context.getParentDataDomain().createDataContext(true);
-
+        DataContext altContext = createDataContextWithSharedCache(false);
+        
         // update artist using raw SQL
         SQLTemplate query = getSQLTemplateBuilder().createSQLTemplate(
                 Artist.class,
@@ -345,7 +345,7 @@ public class DataContextSharedCacheTest 
         assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
 
         // create independent context and fetch artist in it
-        DataContext context3 = getDomain().createDataContext(false);
+        DataContext context3 = createDataContextWithDedicatedCache();
         List artists = context3.performQuery(new ObjectIdQuery(id));
         assertEquals(1, artists.size());
         Artist artist3 = (Artist) artists.get(0);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java Fri Jun 11 00:38:07 2010
@@ -23,8 +23,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.cache.MapQueryCacheFactory;
 import org.apache.cayenne.cache.MockQueryCache;
 import org.apache.cayenne.cache.MockQueryCacheFactory;
@@ -37,7 +35,6 @@ import org.apache.cayenne.unit.CayenneCa
 
 /**
  * DataDomain unit tests.
- * 
  */
 public class DataDomainTest extends CayenneCase {
 
@@ -48,48 +45,6 @@ public class DataDomainTest extends Caye
         assertEquals("tst_name", domain.getName());
     }
 
-    public void testDataContextFactory() throws Exception {
-        DataDomain domain = new DataDomain("dom1");
-        DataContextFactory dataContextFactory = new DataContextFactory() {
-
-            public DataContext createDataContext(
-                    DataChannel parent,
-                    ObjectStore objectStore) {
-                return null;
-            }
-        };
-        domain.setDataContextFactory(null);
-        assertNull(domain.getDataContextFactory());
-        domain.setDataContextFactory(dataContextFactory);
-        assertSame(dataContextFactory, domain.getDataContextFactory());
-    }
-
-    public void testCreateDataContextWithDefaultDataContextFactory() throws Exception {
-        DataDomain domain = new DataDomain("dom1");
-        assertNotNull(domain.createDataContext());
-    }
-
-    public void testCreateDataContextWithNullDataContextFactory() throws Exception {
-        DataDomain domain = new DataDomain("dom1");
-        domain.setDataContextFactory(null);
-        assertNotNull(domain.createDataContext());
-    }
-
-    public void testCreateDataContextWithCustomDataContextFactory() throws Exception {
-        DataDomain domain = new DataDomain("dom1");
-        final DataContext dataContext = new DataContext();
-        DataContextFactory dataContextFactory = new DataContextFactory() {
-
-            public DataContext createDataContext(
-                    DataChannel parent,
-                    ObjectStore objectStore) {
-                return dataContext;
-            }
-        };
-        domain.setDataContextFactory(dataContextFactory);
-        assertEquals(dataContext, domain.createDataContext());
-    }
-
     public void testNodes() throws java.lang.Exception {
         DataDomain domain = new DataDomain("dom1");
         assertEquals(0, domain.getDataNodes().size());
@@ -159,79 +114,39 @@ public class DataDomainTest extends Caye
         assertNotNull(domain.getEntityResolver());
     }
 
-    public void testCreateDataContextWithSharedCache() throws Exception {
+    public void testInitDataDomainWithSharedCache() throws Exception {
         Map properties = new HashMap();
         properties.put(DataDomain.SHARED_CACHE_ENABLED_PROPERTY, Boolean.TRUE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertTrue(domain.isSharedCacheEnabled());
-
-        DataContext c1 = domain.createDataContext();
-        assertSame(c1.getObjectStore().getDataRowCache(), domain.getSharedSnapshotCache());
-
-        DataContext c2 = domain.createDataContext(true);
-        assertSame(c2.getObjectStore().getDataRowCache(), domain.getSharedSnapshotCache());
-
-        DataContext c3 = domain.createDataContext(false);
-        assertNotSame(c3.getObjectStore().getDataRowCache(), domain
-                .getSharedSnapshotCache());
     }
 
-    public void testCreateDataContextWithDedicatedCache() throws Exception {
+    public void testInitDataDomainWithDedicatedCache() throws Exception {
         Map properties = new HashMap();
         properties
                 .put(DataDomain.SHARED_CACHE_ENABLED_PROPERTY, Boolean.FALSE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertFalse(domain.isSharedCacheEnabled());
-        assertNull(domain.getSharedSnapshotCache());
-
-        DataContext c3 = domain.createDataContext(false);
-        assertNotNull(c3.getObjectStore().getDataRowCache());
-        assertNull(domain.getSharedSnapshotCache());
-        assertNotSame(c3.getObjectStore().getDataRowCache(), domain
-                .getSharedSnapshotCache());
-
-        DataContext c1 = domain.createDataContext();
-        assertNotNull(c1.getObjectStore().getDataRowCache());
-        assertNull(domain.getSharedSnapshotCache());
-        assertNotSame(c1.getObjectStore().getDataRowCache(), domain
-                .getSharedSnapshotCache());
-
-        // this should trigger shared cache creation
-        DataContext c2 = domain.createDataContext(true);
-        assertNotNull(c2.getObjectStore().getDataRowCache());
-        assertNotNull(domain.getSharedSnapshotCache());
-        assertSame(c2.getObjectStore().getDataRowCache(), domain.getSharedSnapshotCache());
-
-        DataContext c4 = domain.createDataContext();
-        assertNotSame(c4.getObjectStore().getDataRowCache(), c1
-                .getObjectStore()
-                .getDataRowCache());
     }
 
-    public void testCreateDataContextValidation() throws Exception {
+    public void testInitDataDomainValidation() throws Exception {
         Map properties = new HashMap();
         properties.put(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY, Boolean.TRUE
                 .toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertTrue(domain.isValidatingObjectsOnCommit());
-
-        DataContext c1 = domain.createDataContext(true);
-        assertTrue(c1.isValidatingObjectsOnCommit());
     }
 
-    public void testCreateDataContextNoValidation() throws Exception {
+    public void testInitDataDomainNoValidation() throws Exception {
         Map properties = new HashMap();
         properties.put(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY, Boolean.FALSE
                 .toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertFalse(domain.isValidatingObjectsOnCommit());
-
-        DataContext c1 = domain.createDataContext(true);
-        assertFalse(c1.isValidatingObjectsOnCommit());
     }
 
     public void testDataDomainInternalTransactions() throws Exception {
@@ -258,33 +173,6 @@ public class DataDomainTest extends Caye
         assertTrue(transaction instanceof ExternalTransaction);
     }
 
-    public void testDataDomainDataContextFactory() {
-
-        // null
-        DataDomain d1 = new DataDomain("d1", new HashMap());
-        assertNull(d1.getDataContextFactory());
-
-        // not null
-        DataDomain d2 = new DataDomain("d2", Collections.singletonMap(
-                DataDomain.DATA_CONTEXT_FACTORY_PROPERTY,
-                MockDataContextFactory.class.getName()));
-
-        assertNotNull(d2.getDataContextFactory());
-        assertTrue(d2.getDataContextFactory() instanceof MockDataContextFactory);
-
-        // invalid
-
-        try {
-            new DataDomain("d2", Collections.singletonMap(
-                    DataDomain.DATA_CONTEXT_FACTORY_PROPERTY,
-                    Object.class.getName()));
-            fail("Bogus DataContextFactrory went through unnoticed...");
-        }
-        catch (CayenneRuntimeException e) {
-            // expected
-        }
-    }
-
     public void testQueryCache() {
         DataDomain domain = new DataDomain("X");
         QueryCache cache = domain.getQueryCache();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/InheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/InheritanceTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/InheritanceTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/InheritanceTest.java Fri Jun 11 00:38:07 2010
@@ -268,7 +268,7 @@ public class InheritanceTest extends Peo
 
         // CAY-592 - make sure modification of the address in a parallel context
         // doesn't mess up the Manager
-        DataContext c2 = context.getParentDataDomain().createDataContext();
+        DataContext c2 = createDataContext();
         e = (Employee) Cayenne.objectForPK(c2, e.getObjectId());
         address = e.getAddresses().get(0);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentPeerEventsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentPeerEventsTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentPeerEventsTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/NestedDataContextParentPeerEventsTest.java Fri Jun 11 00:38:07 2010
@@ -34,7 +34,7 @@ public class NestedDataContextParentPeer
         a.setArtistName("X");
         context.commitChanges();
 
-        DataContext parentPeer = context.getParentDataDomain().createDataContext();
+        DataContext parentPeer = createDataContextWithSharedCache(false);
         Artist a1 = (Artist) parentPeer.localObject(a.getObjectId(), a);
 
         final ObjectContext peer2 = context.createChildContext();
@@ -70,7 +70,7 @@ public class NestedDataContextParentPeer
         altA.setArtistName("Y");
         context.commitChanges();
 
-        DataContext parentPeer = context.getParentDataDomain().createDataContext();
+        DataContext parentPeer = createDataContextWithSharedCache(false);
         Painting p1 = (Painting) parentPeer.localObject(p.getObjectId(), p);
         Artist altA1 = (Artist) parentPeer.localObject(altA.getObjectId(), altA);
 
@@ -111,7 +111,7 @@ public class NestedDataContextParentPeer
 
         context.commitChanges();
 
-        DataContext parentPeer = context.getParentDataDomain().createDataContext();
+        DataContext parentPeer = createDataContextWithSharedCache(false);
         Painting py1 = (Painting) parentPeer.localObject(py.getObjectId(), py);
         Artist a1 = (Artist) parentPeer.localObject(a.getObjectId(), a);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/BindDirectiveTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/BindDirectiveTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/BindDirectiveTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/BindDirectiveTest.java Fri Jun 11 00:38:07 2010
@@ -117,7 +117,7 @@ public class BindDirectiveTest extends C
         SQLTemplate query = new SQLTemplate(Artist.class, sql);
         query.setColumnNamesCapitalization(CapsStrategy.UPPER);
         query.setParameters(Collections.singletonMap("ARTISTNAMES", artistNames));
-        List<DataRow> result = getDomain().createDataContext().performQuery(query);
+        List<DataRow> result = createDataContext().performQuery(query);
         assertEquals(2, result.size());
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java Fri Jun 11 00:38:07 2010
@@ -36,7 +36,7 @@ public class SelectActionTest extends Ca
     protected void setUp() throws Exception {
         super.setUp();
         deleteTestData();
-        context = getDomain().createDataContext();
+        context = createDataContext();
     }
 
     public void testFetchLimit_DistinctResultIterator() throws Exception {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java Fri Jun 11 00:38:07 2010
@@ -24,6 +24,7 @@ import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.QueryResponse;
 import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.configuration.server.CayenneServerRuntime;
 import org.apache.cayenne.di.Binder;
@@ -112,11 +113,21 @@ public class CayenneServerRuntimeTest ex
 
     public void testGetObjectContext() {
         final ObjectContext context = new DataContext();
+        final ObjectContextFactory factory = new ObjectContextFactory() {
+            
+            public ObjectContext createContext(DataChannel parent) {
+                return context;
+            }
+            
+            public ObjectContext createContext() {
+                return context;
+            }
+        };
 
         Module module = new Module() {
 
             public void configure(Binder binder) {
-                binder.bind(ObjectContext.class).toInstance(context);
+                binder.bind(ObjectContextFactory.class).toInstance(factory);
             }
         };
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java?rev=953516&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataContextFactoryTest.java Fri Jun 11 00:38:07 2010
@@ -0,0 +1,89 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.configuration.server;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.event.MockEventManager;
+
+public class DataContextFactoryTest extends TestCase {
+
+    public void testCreateDataContextWithDedicatedCache() throws Exception {
+
+        final EventManager eventManager = new MockEventManager();
+        final DataDomain domain = new DataDomain("d1");
+
+        domain.setSharedCacheEnabled(false);
+
+        Module testModule = new Module() {
+
+            public void configure(Binder binder) {
+                binder.bind(DataDomain.class).toInstance(domain);
+                binder.bind(EventManager.class).toInstance(eventManager);
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(testModule);
+
+        DataContextFactory factory = new DataContextFactory();
+        injector.injectMembers(factory);
+
+        DataContext c3 = (DataContext) factory.createContext();
+        assertNotNull(c3.getObjectStore().getDataRowCache());
+        assertNull(domain.getSharedSnapshotCache());
+        assertNotSame(c3.getObjectStore().getDataRowCache(), domain
+                .getSharedSnapshotCache());
+    }
+
+    public void testCreateDataContextValidation() throws Exception {
+        final EventManager eventManager = new MockEventManager();
+        final DataDomain domain = new DataDomain("d1");
+
+        domain.setValidatingObjectsOnCommit(true);
+
+        Module testModule = new Module() {
+
+            public void configure(Binder binder) {
+                binder.bind(DataDomain.class).toInstance(domain);
+                binder.bind(EventManager.class).toInstance(eventManager);
+            }
+        };
+
+        Injector injector = DIBootstrap.createInjector(testModule);
+
+        DataContextFactory factory = new DataContextFactory();
+        injector.injectMembers(factory);
+
+        DataContext c1 = (DataContext) factory.createContext();
+        assertTrue(c1.isValidatingObjectsOnCommit());
+
+        domain.setValidatingObjectsOnCommit(false);
+
+        DataContext c2 = (DataContext) factory.createContext();
+        assertFalse(c2.isValidatingObjectsOnCommit());
+    }
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/hessian/service/HessianServiceTest.java Fri Jun 11 00:38:07 2010
@@ -24,15 +24,17 @@ import java.util.Map;
 
 import javax.servlet.http.HttpSession;
 
-import org.apache.cayenne.access.DataDomain;
+import junit.framework.TestCase;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.event.MockEventBridgeFactory;
 
 import com.caucho.services.server.ServiceContext;
 import com.mockrunner.mock.web.MockHttpServletRequest;
 import com.mockrunner.mock.web.MockHttpSession;
 
-import junit.framework.TestCase;
-
 public class HessianServiceTest extends TestCase {
 
     public void testGetSession() throws Exception {
@@ -42,9 +44,17 @@ public class HessianServiceTest extends 
                 HessianService.EVENT_BRIDGE_FACTORY_PROPERTY,
                 MockEventBridgeFactory.class.getName());
 
-        DataDomain domain = new DataDomain("test");
+        ObjectContextFactory factory = new ObjectContextFactory() {
 
-        HessianService service = new HessianService(domain, map);
+            public ObjectContext createContext(DataChannel parent) {
+                return null;
+            }
+
+            public ObjectContext createContext() {
+                return null;
+            }
+        };
+        HessianService service = new HessianService(factory, map);
 
         MockHttpServletRequest request = new MockHttpServletRequest();
         HttpSession session = new MockHttpSession();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/remote/service/BaseRemoteServiceTest.java Fri Jun 11 00:38:07 2010
@@ -24,7 +24,9 @@ import java.util.Map;
 import junit.framework.TestCase;
 
 import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.ObjectContextFactory;
 import org.apache.cayenne.event.MockEventBridgeFactory;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.remote.QueryMessage;
@@ -41,8 +43,17 @@ public class BaseRemoteServiceTest exten
                 HessianService.EVENT_BRIDGE_FACTORY_PROPERTY,
                 MockEventBridgeFactory.class.getName());
 
-        DataDomain domain = new DataDomain("test");
-        BaseRemoteService service = new BaseRemoteService(domain, map) {
+        ObjectContextFactory factory = new ObjectContextFactory() {
+
+            public ObjectContext createContext(DataChannel parent) {
+                return null;
+            }
+
+            public ObjectContext createContext() {
+                return null;
+            }
+        };
+        BaseRemoteService service = new BaseRemoteService(factory, map) {
 
             @Override
             protected ServerSession createServerSession() {
@@ -61,16 +72,24 @@ public class BaseRemoteServiceTest exten
         };
         assertEquals(MockEventBridgeFactory.class.getName(), service
                 .getEventBridgeFactoryName());
-        assertSame(domain, service.domain);
+        assertSame(factory, service.contextFactory);
 
     }
 
     public void testProcessMessageExceptionSerializability() throws Throwable {
 
         Map<String, String> map = new HashMap<String, String>();
-        DataDomain domain = new DataDomain("test");
+        ObjectContextFactory factory = new ObjectContextFactory() {
 
-        BaseRemoteService service = new BaseRemoteService(domain, map) {
+            public ObjectContext createContext(DataChannel parent) {
+                return null;
+            }
+
+            public ObjectContext createContext() {
+                return null;
+            }
+        };
+        BaseRemoteService service = new BaseRemoteService(factory, map) {
 
             @Override
             protected ServerSession createServerSession() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/CayenneCase.java Fri Jun 11 00:38:07 2010
@@ -119,21 +119,23 @@ public abstract class CayenneCase extend
     }
 
     protected DataContext createDataContext() {
-        return createDataContextWithSharedCache();
+        return createDataContextWithSharedCache(true);
     }
 
     /**
      * Creates a DataContext that uses shared snapshot cache and is based on default test
      * domain.
      */
-    protected DataContext createDataContextWithSharedCache() {
+    protected DataContext createDataContextWithSharedCache(boolean clearCache) {
         // remove listeners for snapshot events
-        getDomain().getEventManager().removeAllListeners(
-                getDomain().getSharedSnapshotCache().getSnapshotEventSubject());
-
-        // clear cache...
-        getDomain().getSharedSnapshotCache().clear();
-        getDomain().getQueryCache().clear();
+        if (clearCache) {
+            getDomain().getEventManager().removeAllListeners(
+                    getDomain().getSharedSnapshotCache().getSnapshotEventSubject());
+
+            // clear cache...
+            getDomain().getSharedSnapshotCache().clear();
+            getDomain().getQueryCache().clear();
+        }
         DataContext context = getDomain().createDataContext(true);
 
         assertSame(getDomain().getSharedSnapshotCache(), context

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java?rev=953516&r1=953515&r2=953516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainView.java Fri Jun 11 00:38:07 2010
@@ -36,8 +36,8 @@ import org.apache.cayenne.access.DataDom
 import org.apache.cayenne.access.DataRowStore;
 import org.apache.cayenne.cache.MapQueryCacheFactory;
 import org.apache.cayenne.cache.OSQueryCacheFactory;
-import org.apache.cayenne.configuration.event.DomainEvent;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.configuration.event.DomainEvent;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.dialog.datadomain.CacheSyncConfigController;
@@ -69,7 +69,6 @@ public class DataDomainView extends JPan
     protected TextAdapter cacheSize;
     protected JCheckBox objectValidation;
     protected JCheckBox externalTransactions;
-    protected TextAdapter dataContextFactory;
     protected JComboBox queryCacheFactory;
     protected JCheckBox sharedCache;
     protected JCheckBox remoteUpdates;
@@ -102,13 +101,6 @@ public class DataDomainView extends JPan
             }
         };
 
-        this.dataContextFactory = new TextAdapter(new JTextField()) {
-
-            protected void updateModel(String text) {
-                setDomainProperty(DataDomain.DATA_CONTEXT_FACTORY_PROPERTY, text, null);
-            }
-        };
-
         this.objectValidation = new JCheckBox();
         this.externalTransactions = new JCheckBox();
 
@@ -123,7 +115,7 @@ public class DataDomainView extends JPan
         CellConstraints cc = new CellConstraints();
         FormLayout layout = new FormLayout(
                 "right:pref, 3dlu, fill:50dlu, 3dlu, fill:47dlu, 3dlu, fill:100",
-                "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p");
+                "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p");
 
         PanelBuilder builder = new PanelBuilder(layout);
         builder.setDefaultDialogBorder();
@@ -132,28 +124,25 @@ public class DataDomainView extends JPan
         builder.addLabel("DataDomain Name:", cc.xy(1, 3));
         builder.add(name.getComponent(), cc.xywh(3, 3, 5, 1));
 
-        builder.addLabel("DataContext Factory:", cc.xy(1, 5));
-        builder.add(dataContextFactory.getComponent(), cc.xywh(3, 5, 5, 1));
-
-        builder.addLabel("Object Validation:", cc.xy(1, 7));
-        builder.add(objectValidation, cc.xy(3, 7));
+        builder.addLabel("Object Validation:", cc.xy(1, 5));
+        builder.add(objectValidation, cc.xy(3, 5));
 
-        builder.addLabel("Container-Managed Transactions:", cc.xy(1, 9));
-        builder.add(externalTransactions, cc.xy(3, 9));
+        builder.addLabel("Container-Managed Transactions:", cc.xy(1, 7));
+        builder.add(externalTransactions, cc.xy(3, 7));
 
-        builder.addSeparator("Cache Configuration", cc.xywh(1, 11, 7, 1));
-        builder.addLabel("Query Cache Factory:", cc.xy(1, 13));
-        builder.add(queryCacheFactory, cc.xywh(3, 13, 5, 1));
+        builder.addSeparator("Cache Configuration", cc.xywh(1, 9, 7, 1));
+        builder.addLabel("Query Cache Factory:", cc.xy(1, 11));
+        builder.add(queryCacheFactory, cc.xywh(3, 11, 5, 1));
 
-        builder.addLabel("Size of Object Cache:", cc.xy(1, 15));
-        builder.add(cacheSize.getComponent(), cc.xy(3, 15));
+        builder.addLabel("Size of Object Cache:", cc.xy(1, 13));
+        builder.add(cacheSize.getComponent(), cc.xy(3, 13));
 
-        builder.addLabel("Use Shared Cache:", cc.xy(1, 17));
-        builder.add(sharedCache, cc.xy(3, 17));
+        builder.addLabel("Use Shared Cache:", cc.xy(1, 15));
+        builder.add(sharedCache, cc.xy(3, 15));
 
-        builder.addLabel("Remote Change Notifications:", cc.xy(1, 19));
-        builder.add(remoteUpdates, cc.xy(3, 19));
-        builder.add(configRemoteUpdates, cc.xy(7, 19));
+        builder.addLabel("Remote Change Notifications:", cc.xy(1, 17));
+        builder.add(remoteUpdates, cc.xy(3, 17));
+        builder.add(configRemoteUpdates, cc.xy(7, 17));
 
         this.setLayout(new BorderLayout());
         this.add(builder.getPanel(), BorderLayout.CENTER);
@@ -325,9 +314,6 @@ public class DataDomainView extends JPan
         externalTransactions.setSelected(getDomainBooleanProperty(
                 DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY,
                 Boolean.toString(DataDomain.USING_EXTERNAL_TRANSACTIONS_DEFAULT)));
-        dataContextFactory.setText(getDomainProperty(
-                DataDomain.DATA_CONTEXT_FACTORY_PROPERTY,
-                null));
 
         sharedCache.setSelected(getDomainBooleanProperty(
                 DataDomain.SHARED_CACHE_ENABLED_PROPERTY,



Mime
View raw message