cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r952695 - in /cayenne/main/trunk/framework: cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/ cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/ cayenne-...
Date Tue, 08 Jun 2010 15:35:11 GMT
Author: aadamchik
Date: Tue Jun  8 15:35:10 2010
New Revision: 952695

URL: http://svn.apache.org/viewvc?rev=952695&view=rev
Log:
CAY-1421 CayenneRuntime shutdown functionality

* scopes are now themselves mnaged by Injector... no more static scopes

Added:
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/NoScope.java
      - copied, changed from r952012, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonProvider.java
      - copied, changed from r952012, cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/SingletonProvider.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonScope.java
      - copied, changed from r952012, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java
Removed:
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Scopes.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/SingletonProvider.java
Modified:
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/BindingBuilder.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/Binding.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultBindingBuilder.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.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/web/CayenneWebModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/ServletContextHandlerTest.java

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/BindingBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/BindingBuilder.java?rev=952695&r1=952694&r2=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/BindingBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/BindingBuilder.java
Tue Jun  8 15:35:10 2010
@@ -40,8 +40,19 @@ public interface BindingBuilder<T> {
 
     /**
      * Sets the scope of a bound instance. This method is used to change the default scope
-     * (which is normally {@link Scopes#SINGLETON}) to something else, e.g.
-     * {@link Scopes#NO_SCOPE}.
+     * which is usually a singleton to a custom scope.
      */
     void in(Scope scope);
+
+    /**
+     * Sets the scope of a bound instance to singleton. Singleton is normally the default,
+     * so calling this method explicitly is rarely needed.
+     */
+    void inSingletonScope();
+
+    /**
+     * Sets the scope of a bound instance to "no scope". This means that a new instance of
+     * an object will be created on every call to {@link Injector#getInstance(Class)}.
+     */
+    void withoutScope();
 }

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/Binding.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/Binding.java?rev=952695&r1=952694&r2=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/Binding.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/Binding.java
Tue Jun  8 15:35:10 2010
@@ -20,7 +20,6 @@ package org.apache.cayenne.di.spi;
 
 import org.apache.cayenne.di.Provider;
 import org.apache.cayenne.di.Scope;
-import org.apache.cayenne.di.Scopes;
 
 /**
  * A binding encapsulates DI provider scoping settings and allows to change them as many
@@ -40,7 +39,7 @@ class Binding<T> {
 
     void changeScope(Scope scope) {
         if (scope == null) {
-            scope = Scopes.NO_SCOPE;
+            scope = NoScope.SINGLETON;
         }
 
         scoped = scope.scope(unscoped);

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultBindingBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultBindingBuilder.java?rev=952695&r1=952694&r2=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultBindingBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultBindingBuilder.java
Tue Jun  8 15:35:10 2010
@@ -105,4 +105,12 @@ class DefaultBindingBuilder<T> implement
     public void in(Scope scope) {
         injector.changeBindingScope(bindingKey, scope);
     }
+
+    public void withoutScope() {
+        in(injector.getNoScope());
+    }
+
+    public void inSingletonScope() {
+        in(injector.getSingletonScope());
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java?rev=952695&r1=952694&r2=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java
Tue Jun  8 15:35:10 2010
@@ -27,7 +27,6 @@ import org.apache.cayenne.di.Key;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.Provider;
 import org.apache.cayenne.di.Scope;
-import org.apache.cayenne.di.Scopes;
 
 /**
  * A default Cayenne implementations of a DI injector.
@@ -36,14 +35,20 @@ import org.apache.cayenne.di.Scopes;
  */
 public class DefaultInjector implements Injector {
 
+    private Scope singletonScope;
+    private Scope noScope;
+
     private Map<Key<?>, Binding<?>> bindings;
     private InjectionStack injectionStack;
     private Scope defaultScope;
 
     public DefaultInjector(Module... modules) throws ConfigurationException {
 
+        this.singletonScope = new SingletonScope();
+        this.noScope = NoScope.SINGLETON;
+
         // this is intentionally hardcoded and is not configurable
-        this.defaultScope = Scopes.SINGLETON;
+        this.defaultScope = singletonScope;
 
         this.bindings = new HashMap<Key<?>, Binding<?>>();
         this.injectionStack = new InjectionStack();
@@ -83,7 +88,7 @@ public class DefaultInjector implements 
 
     <T> void changeBindingScope(Key<T> bindingKey, Scope scope) {
         if (scope == null) {
-            scope = Scopes.NO_SCOPE;
+            scope = noScope;
         }
 
         Binding<?> binding = bindings.get(bindingKey);
@@ -131,4 +136,12 @@ public class DefaultInjector implements 
                 Key.get(object.getClass()));
         provider1.get();
     }
+
+    Scope getSingletonScope() {
+        return singletonScope;
+    }
+
+    Scope getNoScope() {
+        return noScope;
+    }
 }

Copied: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/NoScope.java
(from r952012, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/NoScope.java?p2=cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/NoScope.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java&r1=952012&r2=952695&rev=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/NoScope.java
Tue Jun  8 15:35:10 2010
@@ -16,19 +16,19 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.configuration.web;
+package org.apache.cayenne.di.spi;
 
-import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.Scopes;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.di.Scope;
 
 /**
  * @since 3.1
  */
-public class CayenneWebModule implements Module {
+final class NoScope implements Scope {
 
-    public void configure(Binder binder) {
-        binder.bind(RequestHandler.class).to(SessionContextRequestHandler.class).in(
-                Scopes.NO_SCOPE);
+    static final Scope SINGLETON = new NoScope();
+
+    public <T> Provider<T> scope(Provider<T> unscoped) {
+        return unscoped;
     }
 }

Copied: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonProvider.java
(from r952012, cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/SingletonProvider.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonProvider.java?p2=cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonProvider.java&p1=cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/SingletonProvider.java&r1=952012&r2=952695&rev=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/SingletonProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonProvider.java
Tue Jun  8 15:35:10 2010
@@ -16,7 +16,9 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.di;
+package org.apache.cayenne.di.spi;
+
+import org.apache.cayenne.di.Provider;
 
 /**
  * @since 3.1

Copied: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonScope.java
(from r952012, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonScope.java?p2=cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonScope.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java&r1=952012&r2=952695&rev=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/SingletonScope.java
Tue Jun  8 15:35:10 2010
@@ -16,19 +16,17 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.configuration.web;
+package org.apache.cayenne.di.spi;
 
-import org.apache.cayenne.di.Binder;
-import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.Scopes;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.di.Scope;
 
 /**
  * @since 3.1
  */
-public class CayenneWebModule implements Module {
+class SingletonScope implements Scope {
 
-    public void configure(Binder binder) {
-        binder.bind(RequestHandler.class).to(SessionContextRequestHandler.class).in(
-                Scopes.NO_SCOPE);
+    public <T> Provider<T> scope(Provider<T> unscoped) {
+        return new SingletonProvider<T>(unscoped);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java?rev=952695&r1=952694&r2=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorScopeTest.java
Tue Jun  8 15:35:10 2010
@@ -22,7 +22,6 @@ import junit.framework.TestCase;
 
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.Scopes;
 import org.apache.cayenne.di.mock.MockImplementation1;
 import org.apache.cayenne.di.mock.MockInterface1;
 
@@ -56,8 +55,10 @@ public class DefaultInjectorScopeTest ex
         Module module = new Module() {
 
             public void configure(Binder binder) {
-                binder.bind(MockInterface1.class).to(MockImplementation1.class).in(
-                        Scopes.NO_SCOPE);
+                binder
+                        .bind(MockInterface1.class)
+                        .to(MockImplementation1.class)
+                        .withoutScope();
             }
         };
 
@@ -81,8 +82,10 @@ public class DefaultInjectorScopeTest ex
         Module module = new Module() {
 
             public void configure(Binder binder) {
-                binder.bind(MockInterface1.class).to(MockImplementation1.class).in(
-                        Scopes.SINGLETON);
+                binder
+                        .bind(MockInterface1.class)
+                        .to(MockImplementation1.class)
+                        .inSingletonScope();
             }
         };
 

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=952695&r1=952694&r2=952695&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
Tue Jun  8 15:35:10 2010
@@ -49,7 +49,6 @@ import org.apache.cayenne.dba.sqlserver.
 import org.apache.cayenne.dba.sybase.SybaseSniffer;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.Scopes;
 import org.apache.cayenne.event.EventManager;
 import org.apache.cayenne.resource.ClassLoaderResourceLocator;
 import org.apache.cayenne.resource.ResourceLocator;
@@ -106,8 +105,10 @@ 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).in(
-                Scopes.NO_SCOPE);
+        binder
+                .bind(ObjectContext.class)
+                .toProvider(DataContextProvider.class)
+                .withoutScope();
 
         // a service to load project XML descriptors
         binder.bind(DataChannelDescriptorLoader.class).to(

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java?rev=952695&r1=952694&r2=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneWebModule.java
Tue Jun  8 15:35:10 2010
@@ -20,7 +20,6 @@ package org.apache.cayenne.configuration
 
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.Scopes;
 
 /**
  * @since 3.1
@@ -28,7 +27,9 @@ import org.apache.cayenne.di.Scopes;
 public class CayenneWebModule implements Module {
 
     public void configure(Binder binder) {
-        binder.bind(RequestHandler.class).to(SessionContextRequestHandler.class).in(
-                Scopes.NO_SCOPE);
+        binder
+                .bind(RequestHandler.class)
+                .to(SessionContextRequestHandler.class)
+                .withoutScope();
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchModule.java?rev=952695&r1=952694&r2=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilter_DispatchModule.java
Tue Jun  8 15:35:10 2010
@@ -20,14 +20,10 @@ package org.apache.cayenne.configuration
 
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
-import org.apache.cayenne.di.Scopes;
 
 public class CayenneFilter_DispatchModule implements Module {
 
     public void configure(Binder binder) {
-        binder
-                .bind(RequestHandler.class)
-                .to(CayenneFilter_DispatchRequestHandler.class)
-                .in(Scopes.SINGLETON);
+        binder.bind(RequestHandler.class).to(CayenneFilter_DispatchRequestHandler.class);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/ServletContextHandlerTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/ServletContextHandlerTest.java?rev=952695&r1=952694&r2=952695&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/ServletContextHandlerTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/ServletContextHandlerTest.java
Tue Jun  8 15:35:10 2010
@@ -29,7 +29,6 @@ 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.di.Scopes;
 
 import com.mockrunner.mock.web.MockHttpServletRequest;
 import com.mockrunner.mock.web.MockHttpServletResponse;
@@ -42,8 +41,10 @@ public class ServletContextHandlerTest e
         Module module = new Module() {
 
             public void configure(Binder binder) {
-                binder.bind(ObjectContext.class).to(MockObjectContext.class).in(
-                        Scopes.NO_SCOPE);
+                binder
+                        .bind(ObjectContext.class)
+                        .to(MockObjectContext.class)
+                        .withoutScope();
                 binder.bind(DataChannel.class).to(MockDataChannel.class);
             }
         };



Mime
View raw message