You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2010/06/12 16:32:54 UTC
svn commit: r954012 [1/2] - in /cayenne/main/trunk:
framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/
framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/
framework/cayenne-jdk1.5-unpublished/src/main/java/org/...
Author: aadamchik
Date: Sat Jun 12 14:32:52 2010
New Revision: 954012
URL: http://svn.apache.org/viewvc?rev=954012&view=rev
Log:
CAY-1447 Switch ROP client to dependency injection
* adding shutdown method to CayenneRuntime
* dropping "Cayenne*" prefix from runtime and module names
* moving CONFIGURATION_LOCATION property to ServerModule
* implementing ClientModule, ClientRuntime, ClientLocalRuntime
* unifying constructors of runtime objects on the client and server
Added:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/Runtime.java
- copied, changed from r953778, 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/client/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/CayenneContextFactory.java
- copied, changed from r953778, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientChannelProvider.java
- copied, changed from r953778, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/EventManagerProvider.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntime.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/HessianConnectionProvider.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java
- copied, changed from r953778, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
- copied, changed from r953778, 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/ServerRuntime.java
- copied, changed from r953778, 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/test/java/org/apache/cayenne/configuration/rop/client/
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntimeTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeTest.java
- copied, changed from r953778, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java
cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/configuration/server/ServerRuntimeCase.java
- copied, changed from r953778, cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeCase.java
cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/configuration/
cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/configuration/server/
cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/configuration/server/ServerRuntimeIntegrationTest.java
- copied, changed from r953778, cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
Removed:
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/CayenneROPServerModule.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/CayenneServerRuntime.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/EventManagerProvider.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java
cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeCase.java
cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
Modified:
cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ConstructorInjectingProvider.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java
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/configuration/DefaultRuntimeProperties.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.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/DataDomainProvider.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/main/java/org/apache/cayenne/configuration/web/WebUtil.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.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/DataDomainProviderTest.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-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/jira/CAY_743Test.java
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ConstructorInjectingProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ConstructorInjectingProvider.java?rev=954012&r1=954011&r2=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ConstructorInjectingProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ConstructorInjectingProvider.java Sat Jun 12 14:32:52 2010
@@ -97,8 +97,9 @@ class ConstructorInjectingProvider<T> im
}
if (lastMatch == null) {
- throw new IllegalStateException(
- "No applicable constructor is found for constructor injection");
+ throw new ConfigurationException(
+ "No applicable constructor is found for constructor injection in class '%s'",
+ implementation.getName());
}
// the cast is lame, but Class.getDeclaredConstructors() is not using
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java?rev=954012&r1=954011&r2=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneContext.java Sat Jun 12 14:32:52 2010
@@ -69,17 +69,15 @@ public class CayenneContext extends Base
}
/**
- * Creates a new CayenneContext, initializing it with a channel. If
- * <code>graphEventsEnabled</code> is true, this context will broadcast GraphEvents
- * using ObjectContext.GRAPH_CHANGE_SUBJECT.
+ * Creates a new CayenneContext, initializing it with a channel.
*/
public CayenneContext(DataChannel channel, boolean changeEventsEnabled,
- boolean syncEventsEnabled) {
-
+ boolean lifecyleEventsEnabled) {
+
this.graphManager = new CayenneContextGraphManager(
this,
changeEventsEnabled,
- syncEventsEnabled);
+ lifecyleEventsEnabled);
setChannel(channel);
}
@@ -497,15 +495,16 @@ public class CayenneContext extends Base
if (childContext) {
-// PropertyChangeProcessingStrategy oldStrategy = getPropertyChangeProcessingStrategy();
-// setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.RECORD);
+ // PropertyChangeProcessingStrategy oldStrategy =
+ // getPropertyChangeProcessingStrategy();
+ // setPropertyChangeProcessingStrategy(PropertyChangeProcessingStrategy.RECORD);
try {
changes.apply(new CayenneContextChildDiffLoader(this));
}
finally {
-// setPropertyChangeProcessingStrategy(oldStrategy);
+ // setPropertyChangeProcessingStrategy(oldStrategy);
}
-
+
fireDataChannelChanged(originatingContext, changes);
}
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=954012&r1=954011&r2=954012&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 Sat Jun 12 14:32:52 2010
@@ -63,7 +63,10 @@ public class ClientServerChannel impleme
return serverContext.getQueryCache();
}
- DataChannel getParentChannel() {
+ /**
+ * @since 3.1
+ */
+ public DataChannel getParentChannel() {
return serverContext;
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java?rev=954012&r1=954011&r2=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java Sat Jun 12 14:32:52 2010
@@ -32,6 +32,9 @@ import org.apache.cayenne.di.Inject;
*/
public class DefaultRuntimeProperties implements RuntimeProperties {
+ /**
+ * A name of the map created via DI and used to initialize this service.
+ */
public static final String PROPERTIES_MAP = "org.apache.cayenne.configuration.DefaultRuntimeProperties.properties";
protected Map<String, String> properties;
@@ -50,4 +53,9 @@ public class DefaultRuntimeProperties im
return properties.get(key);
}
+
+ public boolean getBoolean(String key, boolean defaultValue) {
+ String string = get(key);
+ return string != null ? "true".equalsIgnoreCase(string) : defaultValue;
+ }
}
Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/Runtime.java (from r953778, 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/Runtime.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/Runtime.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java&r1=953778&r2=954012&rev=954012&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/Runtime.java Sat Jun 12 14:32:52 2010
@@ -27,22 +27,59 @@ import org.apache.cayenne.di.Injector;
import org.apache.cayenne.di.Module;
/**
- * A superclass of possible Cayenne runtime objects. A CayenneRuntime is the main access
- * point to a given Cayenne stack. It provides a default Cayenne configuration as well as
- * a way to customize this configuration via a built in dependency injection container.
+ * A superclass of various Cayenne runtime stacks. A Runtime is the main access point to
+ * Cayenne for a user application. It provides a default Cayenne configuration as well as
+ * a way to customize this configuration via a built-in dependency injection container.
*
* @since 3.1
*/
-public abstract class CayenneRuntime {
+public abstract class Runtime {
protected Injector injector;
protected Module[] modules;
/**
+ * Internal helper method to add special extra modules in subclass constructors.
+ */
+ protected static Module[] mergeModules(Module mainModule, Module... extraModules) {
+
+ if (extraModules == null || extraModules.length == 0) {
+ return new Module[] {
+ mainModule
+ };
+ }
+
+ Module[] allModules = new Module[extraModules.length + 1];
+ allModules[0] = mainModule;
+ System.arraycopy(extraModules, 0, allModules, 1, extraModules.length);
+
+ return allModules;
+ }
+
+ /**
+ * Internal helper method to add special extra modules in subclass constructors.
+ */
+ protected static Module[] mergeModules(
+ Module mainModule,
+ Collection<Module> extraModules) {
+
+ if (extraModules == null || extraModules.isEmpty()) {
+ return new Module[] {
+ mainModule
+ };
+ }
+
+ Module[] allModules = new Module[extraModules.size() + 1];
+ allModules[0] = mainModule;
+ System.arraycopy(extraModules.toArray(), 0, allModules, 1, extraModules.size());
+ return allModules;
+ }
+
+ /**
* Creates a CayenneRuntime with configuration based on the supplied array of DI
* modules.
*/
- public CayenneRuntime(Module... modules) {
+ public Runtime(Module... modules) {
if (modules == null) {
modules = new Module[0];
@@ -56,7 +93,7 @@ public abstract class CayenneRuntime {
* Creates a CayenneRuntime with configuration based on the supplied collection of DI
* modules.
*/
- public CayenneRuntime(Collection<Module> modules) {
+ public Runtime(Collection<Module> modules) {
if (modules == null) {
this.modules = new Module[0];
@@ -83,9 +120,17 @@ public abstract class CayenneRuntime {
}
/**
+ * Shuts down the DI injector of this runtime, giving all services that need to
+ * release some resources a chance to do that.
+ */
+ public void shutdown() {
+ injector.shutdown();
+ }
+
+ /**
* Returns the runtime {@link DataChannel}.
*/
- public DataChannel getDataChannel() {
+ public DataChannel getChannel() {
return injector.getInstance(DataChannel.class);
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java?rev=954012&r1=954011&r2=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java Sat Jun 12 14:32:52 2010
@@ -19,19 +19,16 @@
package org.apache.cayenne.configuration;
/**
- * Represents a properties map for a given {@link CayenneRuntime}.
+ * Represents a properties map for a given {@link Runtime}.
*
* @since 3.1
*/
public interface RuntimeProperties {
/**
- * A property defining the name of the current runtime.
- */
- public static final String CONFIGURATION_LOCATION = "cayenne.config.location";
-
- /**
- * Returns property value for a given key.
+ * Returns a String property value for a given key.
*/
String get(String key);
+
+ boolean getBoolean(String key, boolean defaultValue);
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java?rev=954012&r1=954011&r2=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoader.java Sat Jun 12 14:32:52 2010
@@ -384,7 +384,7 @@ public class XMLDataChannelDescriptorLoa
.equals(DataSourceInfo.PASSWORD_LOCATION_EXECUTABLE)) {
if (passwordSource != null) {
try {
- Process process = Runtime.getRuntime().exec(
+ Process process = java.lang.Runtime.getRuntime().exec(
passwordSource);
password = passwordFromInputStream(process
.getInputStream());
Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/CayenneContextFactory.java (from r953778, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/CayenneContextFactory.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/CayenneContextFactory.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java&r1=953778&r2=954012&rev=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DefaultRuntimeProperties.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/CayenneContextFactory.java Sat Jun 12 14:32:52 2010
@@ -16,38 +16,36 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-package org.apache.cayenne.configuration;
-
-import java.util.Map;
+package org.apache.cayenne.configuration.rop.client;
+import org.apache.cayenne.CayenneContext;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.ObjectContextFactory;
+import org.apache.cayenne.configuration.RuntimeProperties;
import org.apache.cayenne.di.Inject;
-/**
- * An implementation of {@link RuntimeProperties} that returns properties that were
- * injected via a map in constructor. Each property can be overridden via -D command line
- * option (i.e. in this implementation JVM system properties take precedence over any
- * other property configuration mechanism).
- *
- * @since 3.1
- */
-public class DefaultRuntimeProperties implements RuntimeProperties {
+public class CayenneContextFactory implements ObjectContextFactory {
- public static final String PROPERTIES_MAP = "org.apache.cayenne.configuration.DefaultRuntimeProperties.properties";
+ @Inject
+ protected DataChannel dataChannel;
- protected Map<String, String> properties;
+ @Inject
+ protected RuntimeProperties properties;
- public DefaultRuntimeProperties(@Inject(PROPERTIES_MAP) Map<String, String> properties) {
- this.properties = properties;
+ public ObjectContext createContext() {
+ return createContext(dataChannel);
}
- public String get(String key) {
-
- String property = System.getProperty(key);
-
- if (property != null) {
- return property;
- }
+ public ObjectContext createContext(DataChannel parent) {
+ boolean changeEvents = properties.getBoolean(
+ ClientModule.CONTEXT_CHANGE_EVENTS,
+ false);
+
+ boolean lifecycleEvents = properties.getBoolean(
+ ClientModule.CONTEXT_LIFECYCLE_EVENTS,
+ false);
- return properties.get(key);
+ return new CayenneContext(parent, changeEvents, lifecycleEvents);
}
}
Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientChannelProvider.java (from r953778, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/EventManagerProvider.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientChannelProvider.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientChannelProvider.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/EventManagerProvider.java&r1=953778&r2=954012&rev=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/EventManagerProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientChannelProvider.java Sat Jun 12 14:32:52 2010
@@ -16,21 +16,42 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-package org.apache.cayenne.configuration.server;
+package org.apache.cayenne.configuration.rop.client;
import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.di.Inject;
import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.event.DefaultEventManager;
import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.remote.ClientChannel;
+import org.apache.cayenne.remote.ClientConnection;
-/**
- * Creates an EventManager.
- *
- * @since 3.1
- */
-public class EventManagerProvider implements Provider<EventManager> {
+public class ClientChannelProvider implements Provider<DataChannel> {
- public EventManager get() throws ConfigurationException {
- return new DefaultEventManager();
+ @Inject
+ protected ClientConnection connection;
+
+ @Inject
+ protected EventManager eventManager;
+
+ @Inject
+ protected RuntimeProperties properties;
+
+ public DataChannel get() throws ConfigurationException {
+
+ boolean channelEvents = properties.getBoolean(
+ ClientModule.CHANNEL_EVENTS,
+ false);
+
+ boolean remoteEventsOptional = properties.getBoolean(
+ ClientModule.CHANNEL_REMOTE_EVENTS_OPTIONAL,
+ false);
+
+ return new ClientChannel(
+ connection,
+ channelEvents,
+ eventManager,
+ remoteEventsOptional);
}
}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java?rev=954012&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntime.java Sat Jun 12 14:32:52 2010
@@ -0,0 +1,57 @@
+/*****************************************************************
+ * 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.rop.client;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.remote.ClientConnection;
+
+/**
+ * A {@link ClientRuntime} that provides an ROP stack based on a local connection
+ * on top of a server stack.
+ *
+ * @since 3.1
+ */
+public class ClientLocalRuntime extends ClientRuntime {
+
+ private static Module mainModuleOverride(final Injector serverInjector) {
+ return new Module() {
+
+ public void configure(Binder binder) {
+ binder.bind(ClientConnection.class).toProviderInstance(
+ new LocalConnectionProvider(serverInjector));
+ }
+ };
+ }
+
+ public ClientLocalRuntime(Injector serverInjector,
+ Map<String, String> properties, Collection<Module> extraModules) {
+ super(properties, mergeModules(mainModuleOverride(serverInjector), extraModules));
+ }
+
+ public ClientLocalRuntime(Injector serverInjector,
+ Map<String, String> properties, Module... extraModules) {
+ super(properties, mergeModules(mainModuleOverride(serverInjector), extraModules));
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java?rev=954012&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientModule.java Sat Jun 12 14:32:52 2010
@@ -0,0 +1,74 @@
+/*****************************************************************
+ * 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.rop.client;
+
+import java.util.Map;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.configuration.DefaultRuntimeProperties;
+import org.apache.cayenne.configuration.ObjectContextFactory;
+import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.event.DefaultEventManager;
+import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.remote.ClientConnection;
+
+/**
+ * A DI module containing all Cayenne ROP client runtime configurations.
+ *
+ * @since 3.1
+ */
+public class ClientModule implements Module {
+
+ public static final String ROP_SERVICE_URL = "cayenne.config.rop.service.url";
+ public static final String ROP_SERVICE_USER_NAME = "cayenne.config.rop.service.username";
+ public static final String ROP_SERVICE_PASSWORD = "cayenne.config.rop.service.password";
+ public static final String ROP_SERVICE_SHARED_SESSION = "cayenne.config.rop.service.shared_session";
+
+ public static final String CHANNEL_EVENTS = "cayenne.config.rop.client.channel.events";
+ public static final String CHANNEL_REMOTE_EVENTS_OPTIONAL = "cayenne.config.rop.client.channel.events";
+
+ public static final String CONTEXT_CHANGE_EVENTS = "cayenne.config.rop.client.context.change_events";
+ public static final String CONTEXT_LIFECYCLE_EVENTS = "cayenne.config.rop.client.context.lifecycle_events";
+
+ protected Map<String, String> properties;
+
+ public ClientModule(Map<String, String> properties) {
+ if (properties == null) {
+ throw new NullPointerException("Null 'properties' map");
+ }
+
+ this.properties = properties;
+ }
+
+ public void configure(Binder binder) {
+
+ // expose this module properties to DefaultRuntimeProperties
+ binder.<String> bindMap(DefaultRuntimeProperties.PROPERTIES_MAP).putAll(
+ properties);
+
+ binder.bind(ObjectContextFactory.class).to(CayenneContextFactory.class);
+ binder.bind(ClientConnection.class).toProvider(HessianConnectionProvider.class);
+ binder.bind(EventManager.class).to(DefaultEventManager.class);
+ binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
+ binder.bind(DataChannel.class).toProvider(ClientChannelProvider.class);
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntime.java?rev=954012&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntime.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/ClientRuntime.java Sat Jun 12 14:32:52 2010
@@ -0,0 +1,65 @@
+/*****************************************************************
+ * 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.rop.client;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.cayenne.configuration.Runtime;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.remote.ClientConnection;
+
+/**
+ * A user application entry point to Cayenne stack on the ROP client.
+ *
+ * @since 3.1
+ */
+public class ClientRuntime extends Runtime {
+
+ private static Module mainModule(Map<String, String> properties) {
+ return new ClientModule(properties);
+ }
+
+ /**
+ * Creates a client runtime configuring it with a standard set of services contained
+ * in {@link ClientModule}. CayenneClientModule is created based on a set of
+ * properties that contain things like connection information, etc. Recognized
+ * property keys are defined in {@link ClientModule}. An optional array of
+ * extra modules may contain service overrides and/or user services.
+ */
+ public ClientRuntime(Map<String, String> properties, Collection<Module> extraModules) {
+ super(mergeModules(mainModule(properties), extraModules));
+ }
+
+ /**
+ * Creates a client runtime configuring it with a standard set of services contained
+ * in {@link ClientModule}. CayenneClientModule is created based on a set of
+ * properties that contain things like connection information, etc. Recognized
+ * property keys are defined in {@link ClientModule}. An optional collection of
+ * extra modules may contain service overrides and/or user services.
+ */
+ public ClientRuntime(Map<String, String> properties, Module... extraModules) {
+ super(mergeModules(mainModule(properties), extraModules));
+ }
+
+ public ClientConnection getConnection() {
+ return injector.getInstance(ClientConnection.class);
+ }
+
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/HessianConnectionProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/HessianConnectionProvider.java?rev=954012&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/HessianConnectionProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/HessianConnectionProvider.java Sat Jun 12 14:32:52 2010
@@ -0,0 +1,50 @@
+/*****************************************************************
+ * 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.rop.client;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.remote.ClientConnection;
+import org.apache.cayenne.remote.hessian.HessianConnection;
+
+public class HessianConnectionProvider implements Provider<ClientConnection> {
+
+ @Inject
+ protected RuntimeProperties runtimeProperties;
+
+ public ClientConnection get() throws ConfigurationException {
+
+ String url = runtimeProperties.get(ClientModule.ROP_SERVICE_URL);
+ if (url == null) {
+ throw new ConfigurationException(
+ "No property defined for '%s', can't initialize HessianConnection",
+ ClientModule.ROP_SERVICE_URL);
+ }
+
+ String userName = runtimeProperties
+ .get(ClientModule.ROP_SERVICE_USER_NAME);
+ String password = runtimeProperties.get(ClientModule.ROP_SERVICE_PASSWORD);
+ String sharedSession = runtimeProperties
+ .get(ClientModule.ROP_SERVICE_SHARED_SESSION);
+
+ return new HessianConnection(url, userName, password, sharedSession);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java?rev=954012&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/client/LocalConnectionProvider.java Sat Jun 12 14:32:52 2010
@@ -0,0 +1,54 @@
+/*****************************************************************
+ * 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.rop.client;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.configuration.ObjectContextFactory;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.remote.ClientConnection;
+import org.apache.cayenne.remote.service.LocalConnection;
+
+/**
+ * @since 3.1
+ */
+public class LocalConnectionProvider implements Provider<ClientConnection> {
+
+ protected Injector serverInjector;
+
+ public LocalConnectionProvider(Injector serverInjector) {
+ this.serverInjector = serverInjector;
+ }
+
+ public ClientConnection get() throws ConfigurationException {
+
+ ObjectContextFactory factory = serverInjector
+ .getInstance(ObjectContextFactory.class);
+
+ // TODO: ugly cast
+ DataContext serverContext = (DataContext) factory.createContext();
+ DataChannel clientServerChannel = new ClientServerChannel(serverContext);
+ return new LocalConnection(
+ clientServerChannel,
+ LocalConnection.HESSIAN_SERIALIZATION);
+ }
+}
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=954012&r1=954011&r2=954012&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 Sat Jun 12 14:32:52 2010
@@ -26,9 +26,8 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.cayenne.DataChannel;
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.server.CayenneServerModule;
-import org.apache.cayenne.configuration.server.CayenneServerRuntime;
+import org.apache.cayenne.configuration.Runtime;
+import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.configuration.web.RequestHandler;
import org.apache.cayenne.configuration.web.WebConfiguration;
import org.apache.cayenne.configuration.web.WebUtil;
@@ -76,14 +75,12 @@ public class ROPHessianServlet extends H
String configurationLocation = configAdapter.getConfigurationLocation();
Map<String, String> eventBridgeParameters = configAdapter.getOtherParameters();
- Collection<Module> modules = configAdapter
- .createModules(
- new CayenneServerModule(configurationLocation),
- new CayenneROPServerModule(eventBridgeParameters));
+ Collection<Module> modules = configAdapter.createModules(new ROPServerModule(
+ eventBridgeParameters));
- CayenneServerRuntime runtime = new CayenneServerRuntime(modules);
+ ServerRuntime runtime = new ServerRuntime(configurationLocation, modules);
- DataChannel channel = runtime.getDataChannel();
+ DataChannel channel = runtime.getChannel();
RemoteService service = runtime.getInjector().getInstance(RemoteService.class);
@@ -111,9 +108,9 @@ public class ROPHessianServlet extends H
public void destroy() {
super.destroy();
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
+ Runtime runtime = WebUtil.getCayenneRuntime(servletContext);
if (runtime != null) {
- runtime.getInjector().shutdown();
+ runtime.shutdown();
}
}
}
Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java (from r953778, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java&r1=953778&r2=954012&rev=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/CayenneROPServerModule.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPServerModule.java Sat Jun 12 14:32:52 2010
@@ -32,11 +32,11 @@ import org.apache.cayenne.remote.hessian
*
* @since 3.1
*/
-public class CayenneROPServerModule implements Module {
+public class ROPServerModule implements Module {
protected Map<String, String> eventBridgeProperties;
- public CayenneROPServerModule(Map<String, String> eventBridgeProperties) {
+ public ROPServerModule(Map<String, String> eventBridgeProperties) {
this.eventBridgeProperties = eventBridgeProperties;
}
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=954012&r1=954011&r2=954012&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 Sat Jun 12 14:32:52 2010
@@ -92,14 +92,14 @@ public class DataDomainProvider implemen
protected DataDomain createDataDomain() throws Exception {
String configurationLocation = configurationProperties
- .get(RuntimeProperties.CONFIGURATION_LOCATION);
+ .get(ServerModule.CONFIGURATION_LOCATION);
if (configurationLocation == null) {
throw new DataDomainLoadException(
"No configuration location available. "
+ "You can specify when creating Cayenne runtime "
+ "or via a system property '%s'",
- RuntimeProperties.CONFIGURATION_LOCATION);
+ ServerModule.CONFIGURATION_LOCATION);
}
long t0 = System.currentTimeMillis();
Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java (from r953778, 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/ServerModule.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java&r1=953778&r2=954012&rev=954012&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/ServerModule.java Sat Jun 12 14:32:52 2010
@@ -23,7 +23,6 @@ import org.apache.cayenne.access.DataDom
import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
import org.apache.cayenne.configuration.AdhocObjectFactory;
-import org.apache.cayenne.configuration.CayenneRuntime;
import org.apache.cayenne.configuration.ConfigurationNameMapper;
import org.apache.cayenne.configuration.DataChannelDescriptorLoader;
import org.apache.cayenne.configuration.DataMapLoader;
@@ -49,22 +48,26 @@ 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.event.DefaultEventManager;
import org.apache.cayenne.event.EventManager;
import org.apache.cayenne.resource.ClassLoaderResourceLocator;
import org.apache.cayenne.resource.ResourceLocator;
/**
- * A DI module containing all Cayenne server runtime configurations. To customize Cayenne
- * runtime configuration, either extend this module, or supply an extra custom module when
- * creating {@link CayenneRuntime}.
+ * A DI module containing all Cayenne server runtime configuration.
*
* @since 3.1
*/
-public class CayenneServerModule implements Module {
+public class ServerModule implements Module {
+
+ /**
+ * A property defining the location of the runtime configuration XML resource or file.
+ */
+ public static final String CONFIGURATION_LOCATION = "cayenne.config.location";
protected String configurationLocation;
- public CayenneServerModule(String configurationLocation) {
+ public ServerModule(String configurationLocation) {
this.configurationLocation = configurationLocation;
}
@@ -72,7 +75,7 @@ public class CayenneServerModule impleme
// configure global stack properties
binder.bindMap(DefaultRuntimeProperties.PROPERTIES_MAP).put(
- RuntimeProperties.CONFIGURATION_LOCATION,
+ ServerModule.CONFIGURATION_LOCATION,
configurationLocation);
// configure known DbAdapter detectors in reverse order of popularity. Users can
@@ -97,7 +100,7 @@ public class CayenneServerModule impleme
binder.bind(ConfigurationNameMapper.class).to(
DefaultConfigurationNameMapper.class);
- binder.bind(EventManager.class).toProvider(EventManagerProvider.class);
+ binder.bind(EventManager.class).to(DefaultEventManager.class);
// a service to provide the main stack DataDomain
binder.bind(DataDomain.class).toProvider(DataDomainProvider.class);
Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java (from r953778, 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/ServerRuntime.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java&r1=953778&r2=954012&rev=954012&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/ServerRuntime.java Sat Jun 12 14:32:52 2010
@@ -21,52 +21,48 @@ package org.apache.cayenne.configuration
import java.util.Collection;
import org.apache.cayenne.access.DataDomain;
-import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.Runtime;
+import org.apache.cayenne.configuration.rop.client.ClientRuntime;
import org.apache.cayenne.di.Module;
/**
- * A runtime representing Cayenne server-stack that connects directly to the database via
- * JDBC. The term "server" is used as opposed to ROP "client". Any application, desktop,
- * server, etc. that has a direct JDBC connection should be using this runtime.
+ * An object representing Cayenne server-stack that connects directly to the database via
+ * JDBC. This is an entry point for user applications to access Cayenne, which
+ * encapsulates the dependency injection internals. The term "server" is used as opposed
+ * to ROP "client" (see {@link ClientRuntime}). Any application, desktop, server, etc.
+ * that has a direct JDBC connection should be using this runtime.
*
* @since 3.1
*/
-public class CayenneServerRuntime extends CayenneRuntime {
+public class ServerRuntime extends Runtime {
- /**
- * Creates a server runtime object based on XML configuration file specified via
- * 'configurationLocation' parameter. Configures the runtime with a standard set of
- * services contained in {@link CayenneServerModule}.
- */
- public CayenneServerRuntime(String configurationLocation) {
- super(new CayenneServerModule(configurationLocation));
+ private static Module mainModule(String configurationLocation) {
+ return new ServerModule(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 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.
+ * Creates a server runtime configuring it with a standard set of services contained
+ * in {@link ServerModule}. CayenneServerModule is created with provided
+ * 'configurationLocation'. An optional array of extra modules may contain service
+ * overrides and/or user services.
*/
- public CayenneServerRuntime(Module... modules) {
- super(modules);
+ public ServerRuntime(String configurationLocation, Module... extraModules) {
+ super(mergeModules(mainModule(configurationLocation), extraModules));
}
/**
- * 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 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.
+ * Creates a server runtime configuring it with a standard set of services contained
+ * in {@link ServerModule}. CayenneServerModule is created with provided
+ * 'configurationLocation'. An optional array of extra modules may contain service
+ * overrides and/or user services.
*/
- public CayenneServerRuntime(Collection<Module> modules) {
- super(modules);
+ public ServerRuntime(String configurationLocation, Collection<Module> extraModules) {
+ super(mergeModules(mainModule(configurationLocation), extraModules));
}
/**
* Returns the main runtime DataDomain. Note that by default the returned DataDomain
- * is the same as the main DataChannel returned by {@link #getDataChannel()}. Although
+ * is the same as the main DataChannel returned by {@link #getChannel()}. Although
* users may redefine DataChannel provider in the DI registry, for instance to
* decorate this DataDomain with a custom wrapper.
*/
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=954012&r1=954011&r2=954012&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 Sat Jun 12 14:32:52 2010
@@ -29,14 +29,14 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
-import org.apache.cayenne.configuration.CayenneRuntime;
-import org.apache.cayenne.configuration.server.CayenneServerModule;
-import org.apache.cayenne.configuration.server.CayenneServerRuntime;
+import org.apache.cayenne.configuration.Runtime;
+import org.apache.cayenne.configuration.server.ServerModule;
+import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.di.Module;
/**
* A filter that creates a Cayenne server runtime, possibly including custom modules. By
- * default runtime includes {@link CayenneServerModule} and {@link CayenneWebModule}. Any
+ * default runtime includes {@link ServerModule} and {@link CayenneWebModule}. Any
* custom modules are loaded after the two standard ones to allow custom service
* overrides. Filter initialization parameters:
* <ul>
@@ -67,19 +67,19 @@ public class CayenneFilter implements Fi
WebConfiguration configAdapter = new WebConfiguration(config);
String configurationLocation = configAdapter.getConfigurationLocation();
+ Collection<Module> modules = configAdapter.createModules(new CayenneWebModule());
- Collection<Module> modules = configAdapter.createModules(new CayenneServerModule(
- configurationLocation), new CayenneWebModule());
-
- CayenneServerRuntime runtime = new CayenneServerRuntime(modules);
+ ServerRuntime runtime = new ServerRuntime(
+ configurationLocation,
+ modules);
WebUtil.setCayenneRuntime(config.getServletContext(), runtime);
}
public void destroy() {
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
+ Runtime runtime = WebUtil.getCayenneRuntime(servletContext);
if (runtime != null) {
- runtime.getInjector().shutdown();
+ runtime.shutdown();
}
}
@@ -88,7 +88,7 @@ public class CayenneFilter implements Fi
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
+ Runtime runtime = WebUtil.getCayenneRuntime(servletContext);
RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
handler.requestStart(request, response);
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java?rev=954012&r1=954011&r2=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/WebUtil.java Sat Jun 12 14:32:52 2010
@@ -20,11 +20,11 @@ package org.apache.cayenne.configuration
import javax.servlet.ServletContext;
-import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.Runtime;
import org.apache.cayenne.configuration.rop.server.ROPHessianServlet;
/**
- * A helper class to retrieve and store {@link CayenneRuntime} in the
+ * A helper class to retrieve and store {@link Runtime} in the
* {@link ServletContext}. All Cayenne web configuration objects, such as
* {@link CayenneFilter} and {@link ROPHessianServlet}, are using this class to access
* runtime.
@@ -38,18 +38,18 @@ public class WebUtil {
/**
* Retrieves CayenneRuntime previously stored in provided context via
- * {@link #setCayenneRuntime(ServletContext, CayenneRuntime)}. May return null if no
+ * {@link #setCayenneRuntime(ServletContext, Runtime)}. May return null if no
* runtime was stored.
*/
- public static CayenneRuntime getCayenneRuntime(ServletContext context) {
- return (CayenneRuntime) context.getAttribute(CAYENNE_RUNTIME_KEY);
+ public static Runtime getCayenneRuntime(ServletContext context) {
+ return (Runtime) context.getAttribute(CAYENNE_RUNTIME_KEY);
}
/**
- * Stores {@link CayenneRuntime} in the servlet context. It can be later retrieve via
+ * Stores {@link Runtime} in the servlet context. It can be later retrieve via
* {@link #getCayenneRuntime(ServletContext)}.
*/
- public static void setCayenneRuntime(ServletContext context, CayenneRuntime runtime) {
+ public static void setCayenneRuntime(ServletContext context, Runtime runtime) {
context.setAttribute(CAYENNE_RUNTIME_KEY, runtime);
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.java?rev=954012&r1=954011&r2=954012&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/ClientChannel.java Sat Jun 12 14:32:52 2010
@@ -64,15 +64,26 @@ public class ClientChannel implements Da
* Creates a new channel accessing remote server via provided connection. Channel
* created using this constructor will post no events of its own and provide its users
* with a multithreaded EventManager.
+ *
+ * @deprecated since 3.1 use
+ * {@link #ClientChannel(ClientConnection, boolean, EventManager, boolean)}
*/
public ClientChannel(ClientConnection connection) {
this(connection, false);
}
+ /**
+ * @deprecated since 3.1 use
+ * {@link #ClientChannel(ClientConnection, boolean, EventManager, boolean)}
+ */
public ClientChannel(ClientConnection connection, boolean channelEventsEnabled) {
this(connection, channelEventsEnabled, new DefaultEventManager(2));
}
+ /**
+ * @deprecated since 3.1 use
+ * {@link #ClientChannel(ClientConnection, boolean, EventManager, boolean)}
+ */
public ClientChannel(ClientConnection connection, boolean channelEventsEnabled,
EventManager eventManager) throws CayenneRuntimeException {
this(connection, channelEventsEnabled, eventManager, false);
@@ -105,6 +116,20 @@ public class ClientChannel implements Da
}
}
+ /**
+ * @since 3.1
+ */
+ public ClientConnection getConnection() {
+ return connection;
+ }
+
+ /**
+ * @since 3.1
+ */
+ public boolean isChannelEventsEnabled() {
+ return channelEventsEnabled;
+ }
+
public EventManager getEventManager() {
return eventManager;
}
@@ -171,13 +196,13 @@ public class ClientChannel implements Da
ObjectContext originatingContext,
GraphDiff changes,
int syncType) {
-
+
DataChannelSyncCallbackAction callbackAction = DataChannelSyncCallbackAction
- .getCallbackAction(
- getEntityResolver().getCallbackRegistry(),
- originatingContext.getGraphManager(),
- changes,
- syncType);
+ .getCallbackAction(
+ getEntityResolver().getCallbackRegistry(),
+ originatingContext.getGraphManager(),
+ changes,
+ syncType);
callbackAction.applyPreCommit();
changes = diffCompressor.compress(changes);
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntimeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntimeTest.java?rev=954012&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntimeTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientLocalRuntimeTest.java Sat Jun 12 14:32:52 2010
@@ -0,0 +1,91 @@
+/*****************************************************************
+ * 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.rop.client;
+
+import java.util.Collections;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.ObjectStore;
+import org.apache.cayenne.configuration.ObjectContextFactory;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.remote.ClientConnection;
+import org.apache.cayenne.remote.service.LocalConnection;
+
+public class ClientLocalRuntimeTest extends TestCase {
+
+ public void testDefaultConstructor() {
+
+ Module serverModule = new Module() {
+
+ public void configure(Binder binder) {
+ }
+ };
+
+ ClientLocalRuntime runtime = new ClientLocalRuntime(DIBootstrap
+ .createInjector(serverModule), Collections.EMPTY_MAP);
+ assertEquals(2, runtime.getModules().length);
+
+ Module m0 = runtime.getModules()[0];
+ assertTrue(m0 instanceof ClientModule);
+ }
+
+ public void testGetConnection() {
+
+ final DataChannel channel = new DataDomain("xMn2");
+
+ Module serverModule = new Module() {
+
+ public void configure(Binder binder) {
+ binder.bind(ObjectContextFactory.class).toInstance(
+ new ObjectContextFactory() {
+
+ public ObjectContext createContext(DataChannel parent) {
+ return null;
+ }
+
+ public ObjectContext createContext() {
+ return new DataContext(channel, new ObjectStore());
+ }
+ });
+ }
+ };
+
+ ClientLocalRuntime runtime = new ClientLocalRuntime(DIBootstrap
+ .createInjector(serverModule), Collections.EMPTY_MAP);
+
+ ClientConnection connection = runtime.getConnection();
+ assertNotNull(connection);
+ assertTrue(connection instanceof LocalConnection);
+
+ LocalConnection localConnection = (LocalConnection) connection;
+ assertTrue(localConnection.getChannel() instanceof ClientServerChannel);
+ ClientServerChannel clientServerChannel = (ClientServerChannel) localConnection
+ .getChannel();
+ assertSame(channel, ((DataContext) clientServerChannel.getParentChannel())
+ .getChannel());
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java?rev=954012&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientModuleTest.java Sat Jun 12 14:32:52 2010
@@ -0,0 +1,126 @@
+/*****************************************************************
+ * 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.rop.client;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.configuration.ObjectContextFactory;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.event.DefaultEventManager;
+import org.apache.cayenne.remote.ClientChannel;
+import org.apache.cayenne.remote.ClientConnection;
+import org.apache.cayenne.remote.MockClientConnection;
+import org.apache.cayenne.remote.hessian.HessianConnection;
+
+public class ClientModuleTest extends TestCase {
+
+ public void testClientConnection() {
+
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(ClientModule.ROP_SERVICE_URL, "http://localhost/YuM");
+ ClientModule module = new ClientModule(properties);
+
+ Injector injector = DIBootstrap.createInjector(module);
+
+ ClientConnection connection = injector.getInstance(ClientConnection.class);
+ assertNotNull(connection);
+ assertTrue(connection instanceof HessianConnection);
+
+ assertSame("Connection must be a singleton", connection, injector
+ .getInstance(ClientConnection.class));
+ }
+
+ public void testObjectContextFactory() {
+
+ Map<String, String> properties = new HashMap<String, String>();
+ ClientModule module = new ClientModule(properties) {
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+
+ // use a noop connection to prevent startup errors...
+ binder.bind(ClientConnection.class).to(MockClientConnection.class);
+ }
+ };
+
+ Injector injector = DIBootstrap.createInjector(module);
+
+ ObjectContextFactory factory = injector.getInstance(ObjectContextFactory.class);
+ assertNotNull(factory);
+ assertSame("ObjectContextFactory must be a singleton", factory, injector
+ .getInstance(ObjectContextFactory.class));
+ }
+
+ public void testDataChannel() {
+
+ Map<String, String> properties = new HashMap<String, String>();
+ ClientModule module = new ClientModule(properties) {
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+
+ // use a noop connection to prevent startup errors...
+ binder.bind(ClientConnection.class).to(MockClientConnection.class);
+ }
+ };
+
+ Injector injector = DIBootstrap.createInjector(module);
+
+ DataChannel channel = injector.getInstance(DataChannel.class);
+ assertNotNull(channel);
+ assertTrue(channel instanceof ClientChannel);
+ assertSame("DataChannel must be a singleton", channel, injector
+ .getInstance(DataChannel.class));
+
+ ClientChannel clientChannel = (ClientChannel) channel;
+ assertTrue(clientChannel.getConnection() instanceof MockClientConnection);
+ assertTrue(clientChannel.getEventManager() instanceof DefaultEventManager);
+ assertFalse(clientChannel.isChannelEventsEnabled());
+ }
+
+ public void testDataChannel_NoChannelEvents() {
+
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put(ClientModule.CHANNEL_EVENTS, "true");
+ ClientModule module = new ClientModule(properties) {
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+
+ // use a noop connection to prevent startup errors...
+ binder.bind(ClientConnection.class).to(MockClientConnection.class);
+ }
+ };
+
+ Injector injector = DIBootstrap.createInjector(module);
+
+ DataChannel channel = injector.getInstance(DataChannel.class);
+ ClientChannel clientChannel = (ClientChannel) channel;
+ assertTrue(clientChannel.isChannelEventsEnabled());
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeTest.java?rev=954012&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/rop/client/ClientRuntimeTest.java Sat Jun 12 14:32:52 2010
@@ -0,0 +1,169 @@
+/*****************************************************************
+ * 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.rop.client;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.CayenneContext;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.event.DefaultEventManager;
+import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.remote.ClientChannel;
+import org.apache.cayenne.remote.ClientConnection;
+import org.apache.cayenne.remote.MockClientConnection;
+
+public class ClientRuntimeTest extends TestCase {
+
+ public void testDefaultConstructor() {
+ ClientRuntime runtime = new ClientRuntime(Collections.EMPTY_MAP);
+ assertEquals(1, runtime.getModules().length);
+
+ Module m0 = runtime.getModules()[0];
+ assertTrue(m0 instanceof ClientModule);
+ }
+
+ public void testConstructor_Modules() {
+
+ final boolean[] configured = new boolean[2];
+
+ Module m1 = new Module() {
+
+ public void configure(Binder binder) {
+ configured[0] = true;
+ }
+ };
+
+ Module m2 = new Module() {
+
+ public void configure(Binder binder) {
+ configured[1] = true;
+ }
+ };
+
+ Map<String, String> properties = new HashMap<String, String>();
+
+ ClientRuntime runtime = new ClientRuntime(properties, m1, m2);
+ assertEquals(3, runtime.getModules().length);
+
+ assertTrue(configured[0]);
+ assertTrue(configured[1]);
+ }
+
+ public void testConstructor_ModulesCollection() {
+
+ final boolean[] configured = new boolean[2];
+
+ Collection<Module> modules = new ArrayList<Module>();
+
+ modules.add(new Module() {
+
+ public void configure(Binder binder) {
+ configured[0] = true;
+ }
+ });
+
+ modules.add(new Module() {
+
+ public void configure(Binder binder) {
+ configured[1] = true;
+ }
+ });
+
+ Map<String, String> properties = new HashMap<String, String>();
+
+ ClientRuntime runtime = new ClientRuntime(properties, modules);
+ assertEquals(3, runtime.getModules().length);
+
+ assertTrue(configured[0]);
+ assertTrue(configured[1]);
+ }
+
+ public void testGetObjectContext() {
+
+ Map<String, String> properties = new HashMap<String, String>();
+ ClientModule extraModule = new ClientModule(properties) {
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+
+ // use a noop connection to prevent startup errors...
+ binder.bind(ClientConnection.class).to(MockClientConnection.class);
+ }
+ };
+
+ ClientRuntime runtime = new ClientRuntime(properties, extraModule);
+
+ ObjectContext context = runtime.getContext();
+ assertNotNull(context);
+ assertTrue(context instanceof CayenneContext);
+ assertNotSame("ObjectContext must not be a singleton", context, runtime
+ .getContext());
+
+ CayenneContext clientContext = (CayenneContext) context;
+ assertNotNull(clientContext.getChannel());
+ assertSame(runtime.getChannel(), clientContext.getChannel());
+ }
+
+ public void testGetDataChannel() {
+
+ Map<String, String> properties = new HashMap<String, String>();
+
+ Module extraModule = new Module() {
+
+ public void configure(Binder binder) {
+
+ // use a noop connection to prevent hessian startup errors...
+ binder.bind(ClientConnection.class).to(MockClientConnection.class);
+ }
+ };
+
+ ClientRuntime runtime = new ClientRuntime(properties, extraModule);
+
+ DataChannel channel = runtime.getChannel();
+ assertNotNull(channel);
+ assertTrue(channel instanceof ClientChannel);
+ }
+
+ public void testShutdown() throws Exception {
+
+ Map<String, String> properties = new HashMap<String, String>();
+ ClientRuntime runtime = new ClientRuntime(properties);
+
+ // make sure objects to be shut down are resolved
+
+ EventManager em = runtime.getInjector().getInstance(EventManager.class);
+ assertNotNull(em);
+ assertTrue(em instanceof DefaultEventManager);
+ assertFalse(((DefaultEventManager) em).isStopped());
+
+ runtime.getInjector().shutdown();
+
+ assertTrue(((DefaultEventManager) em).isStopped());
+ }
+}
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=954012&r1=954011&r2=954012&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 Sat Jun 12 14:32:52 2010
@@ -20,9 +20,9 @@ package org.apache.cayenne.configuration
import junit.framework.TestCase;
-import org.apache.cayenne.configuration.CayenneRuntime;
+import org.apache.cayenne.configuration.Runtime;
import org.apache.cayenne.configuration.RuntimeProperties;
-import org.apache.cayenne.configuration.server.CayenneServerModule;
+import org.apache.cayenne.configuration.server.ServerModule;
import org.apache.cayenne.configuration.web.MockModule1;
import org.apache.cayenne.configuration.web.MockModule2;
import org.apache.cayenne.configuration.web.MockRequestHandler;
@@ -49,13 +49,13 @@ public class ROPHessianServletTest exten
assertNull(WebUtil.getCayenneRuntime(context));
servlet.init(config);
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ Runtime runtime = WebUtil.getCayenneRuntime(context);
assertNotNull(runtime);
assertEquals(
"cayenne-org.apache.cayenne.configuration.rop.server.test-config.xml",
runtime.getInjector().getInstance(RuntimeProperties.class).get(
- RuntimeProperties.CONFIGURATION_LOCATION));
+ ServerModule.CONFIGURATION_LOCATION));
}
public void testInitWithLocation() throws Exception {
@@ -71,13 +71,13 @@ public class ROPHessianServletTest exten
ROPHessianServlet servlet = new ROPHessianServlet();
servlet.init(config);
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ Runtime runtime = WebUtil.getCayenneRuntime(context);
assertNotNull(runtime);
assertEquals(location, runtime
.getInjector()
.getInstance(RuntimeProperties.class)
- .get(RuntimeProperties.CONFIGURATION_LOCATION));
+ .get(ServerModule.CONFIGURATION_LOCATION));
}
public void testInitWithStandardModules() throws Exception {
@@ -93,14 +93,14 @@ public class ROPHessianServletTest exten
ROPHessianServlet servlet = new ROPHessianServlet();
servlet.init(config);
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ Runtime runtime = WebUtil.getCayenneRuntime(context);
assertNotNull(runtime);
assertEquals(name + ".xml", runtime.getInjector().getInstance(
- RuntimeProperties.class).get(RuntimeProperties.CONFIGURATION_LOCATION));
+ RuntimeProperties.class).get(ServerModule.CONFIGURATION_LOCATION));
assertEquals(2, runtime.getModules().length);
- assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
- assertTrue(runtime.getModules()[1] instanceof CayenneROPServerModule);
+ assertTrue(runtime.getModules()[0] instanceof ServerModule);
+ assertTrue(runtime.getModules()[1] instanceof ROPServerModule);
assertTrue(RemoteService.class.equals(servlet.getAPIClass()));
}
@@ -121,13 +121,13 @@ public class ROPHessianServletTest exten
ROPHessianServlet servlet = new ROPHessianServlet();
servlet.init(config);
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ Runtime runtime = WebUtil.getCayenneRuntime(context);
assertNotNull(runtime);
assertEquals(4, runtime.getModules().length);
- assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
- assertTrue(runtime.getModules()[1] instanceof CayenneROPServerModule);
+ assertTrue(runtime.getModules()[0] instanceof ServerModule);
+ assertTrue(runtime.getModules()[1] instanceof ROPServerModule);
assertTrue(runtime.getModules()[2] instanceof MockModule1);
assertTrue(runtime.getModules()[3] instanceof MockModule2);
@@ -148,7 +148,7 @@ public class ROPHessianServletTest exten
ROPHessianServlet servlet = new ROPHessianServlet();
servlet.init(config);
- CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
+ Runtime runtime = WebUtil.getCayenneRuntime(context);
assertTrue(runtime.getModules()[2] instanceof ROPHessianServlet_ConfigModule);
assertTrue(RemoteService.class.equals(servlet.getAPIClass()));