cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r940354 - in /cayenne/main/trunk: framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ framework/cayenne-jdk1.5-...
Date Mon, 03 May 2010 03:28:44 GMT
Author: aadamchik
Date: Mon May  3 03:28:43 2010
New Revision: 940354

URL: http://svn.apache.org/viewvc?rev=940354&view=rev
Log:
CayenneRuntime cleanup/improvements:

* removing redundant location property from the Runtime object
* renaming 'newContext' to 'getContext'

Modified:
    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/rop/server/ROPHessianServlet.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.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/configuration/web/CayenneFilterTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebUtilTest.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java

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=940354&r1=940353&r2=940354&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
Mon May  3 03:28:43 2010
@@ -25,7 +25,6 @@ import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.Module;
-import org.apache.cayenne.resource.ResourceLocator;
 
 /**
  * A superclass of possible Cayenne runtime objects. A CayenneRuntime is the main access
@@ -36,38 +35,28 @@ import org.apache.cayenne.resource.Resou
  */
 public abstract class CayenneRuntime {
 
-    protected String configurationLocation;
     protected Injector injector;
     protected Module[] modules;
 
     /**
-     * Creates a CayenneRuntime with configuration based on supplied array of DI modules.
+     * Creates a CayenneRuntime with configuration based on the supplied array of DI
+     * modules.
      */
-    public CayenneRuntime(String configurationLocation, Module... modules) {
-
-        if (configurationLocation == null) {
-            throw new NullPointerException("Null runtime configurationLocation");
-        }
+    public CayenneRuntime(Module... modules) {
 
         if (modules == null) {
             modules = new Module[0];
         }
 
-        this.configurationLocation = configurationLocation;
         this.modules = modules;
         this.injector = DIBootstrap.createInjector(modules);
     }
 
     /**
-     * Creates a CayenneRuntime with configuration based on supplied array of DI modules.
+     * Creates a CayenneRuntime with configuration based on the supplied collection of DI
+     * modules.
      */
-    public CayenneRuntime(String configurationLocation, Collection<Module> modules)
{
-
-        if (configurationLocation == null) {
-            throw new NullPointerException("Null runtime configurationLocation");
-        }
-
-        this.configurationLocation = configurationLocation;
+    public CayenneRuntime(Collection<Module> modules) {
 
         if (modules == null) {
             this.modules = new Module[0];
@@ -80,14 +69,6 @@ public abstract class CayenneRuntime {
     }
 
     /**
-     * Returns location of the runtime configuration resource. E.g. "cayenne-xyz.xml".
-     * Configuration URL is passing this location to {@link ResourceLocator}.
-     */
-    public String getConfigurationLocation() {
-        return configurationLocation;
-    }
-
-    /**
      * Returns an array of modules used to initialize this runtime.
      */
     public Module[] getModules() {
@@ -109,9 +90,11 @@ public abstract class CayenneRuntime {
     }
 
     /**
-     * Creates and returns an ObjectContext based on the runtime DataChannel.
+     * 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 newContext() {
+    public ObjectContext getContext() {
         return injector.getInstance(ObjectContext.class);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java?rev=940354&r1=940353&r2=940354&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
Mon May  3 03:28:43 2010
@@ -74,9 +74,7 @@ public class ROPHessianServlet extends H
                         new CayenneServerModule(configurationLocation),
                         new CayenneROPServerModule(eventBridgeParameters));
 
-        CayenneServerRuntime runtime = new CayenneServerRuntime(
-                configurationLocation,
-                modules);
+        CayenneServerRuntime runtime = new CayenneServerRuntime(modules);
 
         DataChannel channel = runtime.getDataChannel();
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java?rev=940354&r1=940353&r2=940354&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java
Mon May  3 03:28:43 2010
@@ -39,29 +39,29 @@ public class CayenneServerRuntime extend
      * services contained in {@link CayenneServerModule}.
      */
     public CayenneServerRuntime(String configurationLocation) {
-        super(configurationLocation, new CayenneServerModule(configurationLocation));
+        super(new CayenneServerModule(configurationLocation));
     }
 
     /**
      * Creates a server runtime object based on an array of custom DI modules. When
      * implementing custom modules, refer to {@link CayenneServerModule} for the minimal
-     * set of services required by Cayenne. The easiest way to do it is to pass
+     * set of services expected by Cayenne. The easiest way to do it is to pass
      * {@link CayenneServerModule} or its subclass as one of the modules to this
      * constructor.
      */
-    public CayenneServerRuntime(String configurationLocation, Module... modules) {
-        super(configurationLocation, modules);
+    public CayenneServerRuntime(Module... modules) {
+        super(modules);
     }
 
     /**
      * Creates a server runtime object based on a collection of DI modules. When
      * implementing custom modules, refer to {@link CayenneServerModule} for the minimal
-     * set of services required by Cayenne. The easiest way to do it is to pass
+     * set of services expected by Cayenne. The easiest way to do it is to pass
      * {@link CayenneServerModule} or its subclass as one of the modules to this
      * constructor.
      */
-    public CayenneServerRuntime(String configurationLocation, Collection<Module> modules)
{
-        super(configurationLocation, modules);
+    public CayenneServerRuntime(Collection<Module> modules) {
+        super(modules);
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java?rev=940354&r1=940353&r2=940354&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
Mon May  3 03:28:43 2010
@@ -71,9 +71,7 @@ public class CayenneFilter implements Fi
         Collection<Module> modules = configAdapter.createModules(new CayenneServerModule(
                 configurationLocation), new CayenneWebModule());
 
-        CayenneServerRuntime runtime = new CayenneServerRuntime(
-                configurationLocation,
-                modules);
+        CayenneServerRuntime runtime = new CayenneServerRuntime(modules);
         WebUtil.setCayenneRuntime(config.getServletContext(), runtime);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java?rev=940354&r1=940353&r2=940354&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/server/ROPHessianServletTest.java
Mon May  3 03:28:43 2010
@@ -21,6 +21,7 @@ package org.apache.cayenne.configuration
 import junit.framework.TestCase;
 
 import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.configuration.server.CayenneServerModule;
 import org.apache.cayenne.configuration.web.MockModule1;
 import org.apache.cayenne.configuration.web.MockModule2;
@@ -52,7 +53,8 @@ public class ROPHessianServletTest exten
 
         assertEquals(
                 "cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml",
-                runtime.getConfigurationLocation());
+                runtime.getInjector().getInstance(RuntimeProperties.class).get(
+                        RuntimeProperties.CONFIGURATION_LOCATION));
     }
 
     public void testInitWithLocation() throws Exception {
@@ -71,7 +73,10 @@ public class ROPHessianServletTest exten
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals(location, runtime.getConfigurationLocation());
+        assertEquals(location, runtime
+                .getInjector()
+                .getInstance(RuntimeProperties.class)
+                .get(RuntimeProperties.CONFIGURATION_LOCATION));
     }
 
     public void testInitWithStandardModules() throws Exception {
@@ -90,7 +95,8 @@ public class ROPHessianServletTest exten
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("cayenne-" + name + ".xml", runtime.getConfigurationLocation());
+        assertEquals("cayenne-" + name + ".xml", runtime.getInjector().getInstance(
+                RuntimeProperties.class).get(RuntimeProperties.CONFIGURATION_LOCATION));
         assertEquals(2, runtime.getModules().length);
         assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
         assertTrue(runtime.getModules()[1] instanceof CayenneROPServerModule);

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=940354&r1=940353&r2=940354&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
Mon May  3 03:28:43 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.RuntimeProperties;
 import org.apache.cayenne.configuration.server.CayenneServerRuntime;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
@@ -37,10 +38,16 @@ public class CayenneServerRuntimeTest ex
     public void testDefaultConstructor() {
         CayenneServerRuntime runtime = new CayenneServerRuntime("xxxx");
 
-        assertEquals("xxxx", runtime.getConfigurationLocation());
+        assertEquals("xxxx", runtime
+                .getInjector()
+                .getInstance(RuntimeProperties.class)
+                .get(RuntimeProperties.CONFIGURATION_LOCATION));
 
         assertEquals(1, runtime.getModules().length);
-        assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
+
+        Module m0 = runtime.getModules()[0];
+        assertTrue(m0 instanceof CayenneServerModule);
+        assertEquals("xxxx", ((CayenneServerModule) m0).configurationLocation);
     }
 
     public void testConstructor_Modules() {
@@ -61,9 +68,7 @@ public class CayenneServerRuntimeTest ex
             }
         };
 
-        CayenneServerRuntime runtime = new CayenneServerRuntime("yyyy", m1, m2);
-
-        assertEquals("yyyy", runtime.getConfigurationLocation());
+        CayenneServerRuntime runtime = new CayenneServerRuntime(m1, m2);
         assertEquals(2, runtime.getModules().length);
 
         for (int i = 0; i < configured.length; i++) {
@@ -101,11 +106,11 @@ public class CayenneServerRuntimeTest ex
             }
         };
 
-        CayenneServerRuntime runtime = new CayenneServerRuntime("name", module);
+        CayenneServerRuntime runtime = new CayenneServerRuntime(module);
         assertSame(channel, runtime.getDataChannel());
     }
 
-    public void testNewObjectContext() {
+    public void testGetObjectContext() {
         final ObjectContext context = new DataContext();
 
         Module module = new Module() {
@@ -115,8 +120,8 @@ public class CayenneServerRuntimeTest ex
             }
         };
 
-        CayenneServerRuntime runtime = new CayenneServerRuntime("name", module);
-        assertSame(context, runtime.newContext());
-        assertSame(context, runtime.newContext());
+        CayenneServerRuntime runtime = new CayenneServerRuntime(module);
+        assertSame(context, runtime.getContext());
+        assertSame(context, runtime.getContext());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java?rev=940354&r1=940353&r2=940354&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
Mon May  3 03:28:43 2010
@@ -21,6 +21,7 @@ package org.apache.cayenne.configuration
 import junit.framework.TestCase;
 
 import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.configuration.server.CayenneServerModule;
 
 import com.mockrunner.mock.web.MockFilterChain;
@@ -47,16 +48,15 @@ public class CayenneFilterTest extends T
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("cayenne-abc.xml", runtime.getConfigurationLocation());
+        assertEquals("cayenne-abc.xml", runtime.getInjector().getInstance(
+                RuntimeProperties.class).get(RuntimeProperties.CONFIGURATION_LOCATION));
     }
 
     public void testInitWithLocation() throws Exception {
 
         MockFilterConfig config = new MockFilterConfig();
         config.setFilterName("abc");
-        config.setInitParameter(
-                WebConfiguration.CONFIGURATION_LOCATION_PARAMETER,
-                "xyz");
+        config.setInitParameter(WebConfiguration.CONFIGURATION_LOCATION_PARAMETER, "xyz");
 
         MockServletContext context = new MockServletContext();
         config.setupServletContext(context);
@@ -67,7 +67,10 @@ public class CayenneFilterTest extends T
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("xyz", runtime.getConfigurationLocation());
+        assertEquals("xyz", runtime
+                .getInjector()
+                .getInstance(RuntimeProperties.class)
+                .get(RuntimeProperties.CONFIGURATION_LOCATION));
     }
 
     public void testInitWithStandardModules() throws Exception {
@@ -86,7 +89,8 @@ public class CayenneFilterTest extends T
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("cayenne-abc.xml", runtime.getConfigurationLocation());
+        assertEquals("cayenne-abc.xml", runtime.getInjector().getInstance(
+                RuntimeProperties.class).get(RuntimeProperties.CONFIGURATION_LOCATION));
         assertEquals(2, runtime.getModules().length);
         assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
         assertTrue(runtime.getModules()[1] instanceof CayenneWebModule);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebUtilTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebUtilTest.java?rev=940354&r1=940353&r2=940354&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebUtilTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/WebUtilTest.java
Mon May  3 03:28:43 2010
@@ -31,13 +31,13 @@ public class WebUtilTest extends TestCas
 
         assertNull(WebUtil.getCayenneRuntime(context));
 
-        CayenneRuntime runtime = new CayenneRuntime("xx") {
+        CayenneRuntime runtime = new CayenneRuntime() {
         };
 
         WebUtil.setCayenneRuntime(context, runtime);
         assertSame(runtime, WebUtil.getCayenneRuntime(context));
 
-        CayenneRuntime runtime1 = new CayenneRuntime("yy") {
+        CayenneRuntime runtime1 = new CayenneRuntime() {
         };
 
         WebUtil.setCayenneRuntime(context, runtime1);

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java?rev=940354&r1=940353&r2=940354&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
(original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
Mon May  3 03:28:43 2010
@@ -75,9 +75,7 @@ public class DataPortTask extends Cayenn
             }
         };
 
-        CayenneServerRuntime runtime = new CayenneServerRuntime(
-                projectFileLocation,
-                module);
+        CayenneServerRuntime runtime = new CayenneServerRuntime(module);
         DataDomain domain;
 
         ClassLoader threadContextClassLoader = Thread

Modified: cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java?rev=940354&r1=940353&r2=940354&view=diff
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
(original)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
Mon May  3 03:28:43 2010
@@ -48,10 +48,10 @@ public class CayenneServerRuntimeIntegra
 
 	public void testNewContext_notSingleton() {
 
-		ObjectContext context1 = runtime.newContext();
+		ObjectContext context1 = runtime.getContext();
 		assertNotNull(context1);
 
-		ObjectContext context2 = runtime.newContext();
+		ObjectContext context2 = runtime.getContext();
 		assertNotNull(context2);
 
 		assertNotSame(context1, context2);
@@ -65,8 +65,8 @@ public class CayenneServerRuntimeIntegra
 
 		SelectQuery query = new SelectQuery(Table1.class);
 
-		ObjectContext context1 = runtime.newContext();
-		ObjectContext context2 = runtime.newContext();
+		ObjectContext context1 = runtime.getContext();
+		ObjectContext context2 = runtime.getContext();
 
 		Table1 o1 = (Table1) Cayenne.objectForQuery(context1, query);
 		Table1 o2 = (Table1) Cayenne.objectForQuery(context2, query);



Mime
View raw message