cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r887668 - in /cayenne/main/trunk: framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ framework/cayenne-jdk1.5-unpublished...
Date Sun, 06 Dec 2009 11:23:21 GMT
Author: aadamchik
Date: Sun Dec  6 11:23:18 2009
New Revision: 887668

URL: http://svn.apache.org/viewvc?rev=887668&view=rev
Log:
CAY-1319 Switch Cayenne configuration loading to cayenne-di container

* DataContextProvider
* CayenneRuntime -> CayenneServerRuntime
* CayenneServerRuntime itests

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneServerModule.java
      - copied, changed from r887667, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DomainDataChannelProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntime.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataContextProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeTest.java
      - copied, changed from r887667, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneRuntimeTest.java
    cayenne/main/trunk/itests/cayenne-di-stack/
    cayenne/main/trunk/itests/cayenne-di-stack/.classpath
    cayenne/main/trunk/itests/cayenne-di-stack/.project
    cayenne/main/trunk/itests/cayenne-di-stack/.settings/
    cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.eclipse.jdt.core.prefs
    cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.maven.ide.eclipse.prefs
    cayenne/main/trunk/itests/cayenne-di-stack/pom.xml
      - copied, changed from r887667, cayenne/main/trunk/itests/pom.xml
    cayenne/main/trunk/itests/cayenne-di-stack/src/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/DefaultMap.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/Table1.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_DefaultMap.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_Table1.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntimeCase.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/RuntimeName.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/DefaultMap.map.xml
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/PoolingDSNode.driver.xml
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/cayenne-DEFAULT.xml
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/log4j.properties
    cayenne/main/trunk/itests/cayenne-di-stack/src/test/
    cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/
    cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/
    cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/
    cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/
    cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/
    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/CayenneModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneRuntimeTest.java
    cayenne/main/trunk/framework/cayenne-server/pom.properties
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/SAXNestedTagHandler.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/XMLDataChannelDescriptorLoaderAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneRuntime.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/DataDomainProviderTest.java
    cayenne/main/trunk/itests/pom.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java?rev=887668&r1=887667&r2=887668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/CreateIfNoSchemaStrategy.java Sun Dec  6 11:23:18 2009
@@ -42,7 +42,7 @@
     final static Log logger = LogFactory.getLog(CreateIfNoSchemaStrategy.class);
 
     @Override
-    public void processSchemaUpdate(DataNode dataNode) throws SQLException {
+    protected void processSchemaUpdate(DataNode dataNode) throws SQLException {
 
         Map<String, Boolean> nameTables = getNameTablesInDB(dataNode);
         Collection<DbEntity> entities = dataNode.getEntityResolver().getDbEntities();

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneServerModule.java (from r887667, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneModule.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneServerModule.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneServerModule.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneModule.java&r1=887667&r2=887668&rev=887668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneModule.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneServerModule.java Sun Dec  6 11:23:18 2009
@@ -19,9 +19,10 @@
 package org.apache.cayenne.configuration;
 
 import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
 import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
-import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.db2.DB2Sniffer;
 import org.apache.cayenne.dba.derby.DerbySniffer;
 import org.apache.cayenne.dba.frontbase.FrontBaseSniffer;
@@ -41,20 +42,21 @@
 import org.apache.cayenne.resource.ClassLoaderResourceLocator;
 import org.apache.cayenne.resource.ResourceLocator;
 import org.apache.cayenne.runtime.CayenneRuntime;
+import org.apache.cayenne.runtime.DataContextProvider;
 import org.apache.cayenne.runtime.DataDomainProvider;
 
 /**
- * A DI module containing all Cayenne runtime configurations. To customize Cayenne runtime
- * configuration, either extend this module, or supply an extra custom module when
+ * 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}.
  * 
  * @since 3.1
  */
-public class CayenneModule implements Module {
+public class CayenneServerModule implements Module {
 
     protected String runtimeName;
 
-    public CayenneModule(String runtimeName) {
+    public CayenneServerModule(String runtimeName) {
         this.runtimeName = runtimeName;
     }
 
@@ -68,7 +70,7 @@
         // configure known DbAdapter detectors in reverse order of popularity. Users can
         // add their own for their own to install custom adapters automatically
         binder
-                .bindList(DbAdapter.class)
+                .bindList(DbAdapterFactory.class)
                 .add(new OpenBaseSniffer())
                 .add(new FrontBaseSniffer())
                 .add(new IngresSniffer())
@@ -86,8 +88,13 @@
         binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class).in(
                 Scopes.SINGLETON);
 
-        // a service to provide the main stack DataChannel
-        binder.bind(DataChannel.class).toProvider(DataDomainProvider.class);
+        // a service to provide the main stack DataDomain
+        binder.bind(DataDomain.class).toProvider(DataDomainProvider.class).in(Scopes.SINGLETON);
+
+        // will return DataDomain for request for a DataChannel
+        binder.bind(DataChannel.class).toProvider(DomainDataChannelProvider.class).in(Scopes.SINGLETON);
+        
+        binder.bind(ObjectContext.class).toProvider(DataContextProvider.class);
 
         // a service to load project XML descriptors
         binder.bind(DataChannelDescriptorLoader.class).to(

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DomainDataChannelProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DomainDataChannelProvider.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DomainDataChannelProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DomainDataChannelProvider.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,41 @@
+/*****************************************************************
+ *   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;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.di.DIException;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+
+/**
+ * This is a default implementation of a DataChannel provider that simply returns a
+ * DataDomain for a given runtime.
+ * 
+ * @since 3.1
+ */
+public class DomainDataChannelProvider implements Provider<DataChannel> {
+
+    @Inject
+    protected DataDomain dataDomain;
+    
+    public DataChannel get() throws DIException {
+        return dataDomain;
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/SAXNestedTagHandler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/SAXNestedTagHandler.java?rev=887668&r1=887667&r2=887668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/SAXNestedTagHandler.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/SAXNestedTagHandler.java Sun Dec  6 11:23:18 2009
@@ -18,6 +18,10 @@
  ****************************************************************/
 package org.apache.cayenne.configuration;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.Locator;
@@ -68,6 +72,21 @@
         }
     }
 
+    protected String unexpectedTagMessage(String tagFound, String... tagsExpected) {
+
+        List<String> expected = tagsExpected != null
+                ? Arrays.asList(tagsExpected)
+                : Collections.<String> emptyList();
+
+        return String
+                .format(
+                        "tag <%s> is unexpected at [%d,%d]. The following tags are allowed here: %s",
+                        tagFound,
+                        locator.getColumnNumber(),
+                        locator.getLineNumber(),
+                        expected);
+    }
+
     protected ContentHandler createChildTagHandler(
             String namespaceURI,
             String localName,

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=887668&r1=887667&r2=887668&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 Sun Dec  6 11:23:18 2009
@@ -50,7 +50,10 @@
 
     public DataChannelDescriptor load(String runtimeName) throws CayenneRuntimeException {
 
-        logger.debug("starting configuration loading: " + runtimeName);
+        long t0 = System.currentTimeMillis();
+        if (logger.isDebugEnabled()) {
+            logger.debug("starting configuration loading: " + runtimeName);
+        }
 
         String resourceName = getResourceName(runtimeName);
         Collection<Resource> configurations = resourceLocator.findResources(resourceName);
@@ -73,11 +76,20 @@
         }
 
         DataChannelDescriptor descriptor = new XMLDataChannelDescriptorLoaderAction(
-                dataMapLoader).load(configurationResource);
+                dataMapLoader,
+                logger).load(configurationResource);
 
         descriptor.setName(runtimeName);
 
-        logger.debug("finished configuration loading: " + runtimeName);
+        long t1 = System.currentTimeMillis();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("finished configuration loading: "
+                    + runtimeName
+                    + " in "
+                    + (t1 - t0)
+                    + " ms.");
+        }
         return descriptor;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoaderAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoaderAction.java?rev=887668&r1=887667&r2=887668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoaderAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoaderAction.java Sun Dec  6 11:23:18 2009
@@ -27,7 +27,6 @@
 import org.apache.cayenne.resource.Resource;
 import org.apache.cayenne.util.Util;
 import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
@@ -41,9 +40,6 @@
  */
 class XMLDataChannelDescriptorLoaderAction {
 
-    private static Log logger = LogFactory
-            .getLog(XMLDataChannelDescriptorLoaderAction.class);
-
     static final String DOMAIN_TAG = "domain";
     static final String MAP_TAG = "map";
     static final String NODE_TAG = "node";
@@ -51,9 +47,11 @@
     static final String MAP_REF_TAG = "map-ref";
 
     private DataMapLoader mapLoader;
+    private Log logger;
 
-    XMLDataChannelDescriptorLoaderAction(DataMapLoader mapLoader) {
+    XMLDataChannelDescriptorLoaderAction(DataMapLoader mapLoader, Log logger) {
         this.mapLoader = mapLoader;
+        this.logger = logger;
     }
 
     DataChannelDescriptor load(Resource resource) {
@@ -118,6 +116,7 @@
                 return new DataChannelChildrenHandler(parser, this);
             }
 
+            logger.info(unexpectedTagMessage(localName, DOMAIN_TAG));
             return super.createChildTagHandler(namespaceURI, localName, name, atts);
         }
     }
@@ -172,9 +171,8 @@
                 String location = attributes.getValue("", "datasource");
                 nodeDescriptor.setLocation(location);
 
-                nodeDescriptor.setDataSourceFactoryType(attributes.getValue(
-                        "",
-                        "factory"));
+                nodeDescriptor.setDataSourceFactoryType(attributes
+                        .getValue("", "factory"));
                 nodeDescriptor.setSchemaUpdateStrategyType(attributes.getValue(
                         "",
                         "schema-update-strategy"));

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneRuntime.java?rev=887668&r1=887667&r2=887668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneRuntime.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneRuntime.java Sun Dec  6 11:23:18 2009
@@ -20,37 +20,24 @@
 
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.configuration.CayenneModule;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.Module;
 
 /**
- * Represents the main access point to a given Cayenne stack. Provides a default Cayenne
- * configuration as well as a way to customize this configuration via a built in
- * dependency injection container.
+ * 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.
  * 
  * @since 3.1
  */
-public class CayenneRuntime {
+public abstract class CayenneRuntime {
 
     protected String name;
     protected Injector injector;
     protected Module[] modules;
 
     /**
-     * Initializes Cayenne runtime instance with a default configuration provided by
-     * {@link CayenneModule}.
-     * 
-     * @param name Runtime name. By default a configuration file name contains a runtime
-     *            name in it, to allow multiple runtimes in a single JVM. E.g. a typical
-     *            config file name has the form of "cayenne-<name>.xml".
-     */
-    public CayenneRuntime(String name) {
-        this(name, new CayenneModule(name));
-    }
-
-    /**
      * Initializes Cayenne runtime with an array of DI modules.
      */
     public CayenneRuntime(String name, Module... modules) {
@@ -94,7 +81,7 @@
     /**
      * Creates and returns an ObjectContext based on the runtime DataChannel.
      */
-    public ObjectContext newObjectContext() {
+    public ObjectContext newContext() {
         return injector.getInstance(ObjectContext.class);
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntime.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntime.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntime.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,52 @@
+/*****************************************************************
+ *   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.runtime;
+
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.configuration.CayenneServerModule;
+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.
+ * 
+ * @since 3.1
+ */
+public class CayenneServerRuntime extends CayenneRuntime {
+
+    public CayenneServerRuntime(String name) {
+        super(name, new CayenneServerModule(name));
+    }
+
+    public CayenneServerRuntime(String name, Module... modules) {
+        super(name, modules);
+    }
+
+    /**
+     * Returns the main runtime DataDomain. Note that by default the returned DataDomain
+     * is the same as the main DataChannel returned by {@link #getDataChannel()}. Although
+     * users may redefine DataChannel provider in the DI registry, for instance to
+     * decorate this DataDomain with a custom wrapper.
+     */
+    public DataDomain getDataDomain() {
+        return injector.getInstance(DataDomain.class);
+    }
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataContextProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataContextProvider.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataContextProvider.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataContextProvider.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,40 @@
+/*****************************************************************
+ *   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.runtime;
+
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.di.DIException;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+
+/**
+ * @since 3.1
+ */
+public class DataContextProvider implements Provider<DataContext> {
+
+    @Inject
+    protected DataDomain dataDomain;
+
+    public DataContext get() throws DIException {
+        // TODO: andrus 12.5.2009 - deprecate 'createDataContext' in DataDomain and move
+        // it to this provider instead
+        return dataDomain.createDataContext();
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataDomainProvider.java?rev=887668&r1=887667&r2=887668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataDomainProvider.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataDomainProvider.java Sun Dec  6 11:23:18 2009
@@ -43,7 +43,7 @@
  * 
  * @since 3.1
  */
-public class DataDomainProvider implements Provider<DataChannel> {
+public class DataDomainProvider implements Provider<DataDomain> {
 
     @Inject
     protected DataChannelDescriptorLoader loader;
@@ -63,13 +63,13 @@
     @Inject
     protected AdhocObjectFactory objectFactory;
 
-    protected volatile DataChannel dataChannel;
+    protected volatile DataDomain dataDomain;
 
-    public DataChannel get() throws DIException {
+    public DataDomain get() throws DIException {
 
-        if (dataChannel == null) {
+        if (dataDomain == null) {
             synchronized (this) {
-                if (dataChannel == null) {
+                if (dataDomain == null) {
 
                     try {
                         createDataChannel();
@@ -85,7 +85,7 @@
             }
         }
 
-        return dataChannel;
+        return dataDomain;
     }
 
     protected void createDataChannel() throws Exception {
@@ -93,12 +93,12 @@
                 .get(RuntimeProperties.CAYENNE_RUNTIME_NAME);
         DataChannelDescriptor descriptor = loader.load(runtimeName);
 
-        DataDomain dataChannel = new DataDomain(descriptor.getName());
+        DataDomain dataDomain = new DataDomain(descriptor.getName());
 
-        dataChannel.initWithProperties(descriptor.getProperties());
+        dataDomain.initWithProperties(descriptor.getProperties());
 
         for (DataMap dataMap : descriptor.getDataMaps()) {
-            dataChannel.addMap(dataMap);
+            dataDomain.addMap(dataMap);
         }
 
         for (DataNodeDescriptor nodeDescriptor : descriptor.getDataNodeDescriptors()) {
@@ -138,13 +138,13 @@
 
             // DataMaps
             for (String dataMapName : nodeDescriptor.getDataMapNames()) {
-                dataNode.addDataMap(dataChannel.getMap(dataMapName));
+                dataNode.addDataMap(dataDomain.getMap(dataMapName));
             }
 
-            dataChannel.addNode(dataNode);
+            dataDomain.addNode(dataNode);
         }
 
-        this.dataChannel = dataChannel;
+        this.dataDomain = dataDomain;
     }
 
 }

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeTest.java (from r887667, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneRuntimeTest.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeTest.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeTest.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneRuntimeTest.java&r1=887667&r2=887668&rev=887668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneRuntimeTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeTest.java Sun Dec  6 11:23:18 2009
@@ -24,24 +24,23 @@
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.QueryResponse;
 import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.configuration.CayenneModule;
+import org.apache.cayenne.configuration.CayenneServerModule;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.event.EventManager;
 import org.apache.cayenne.graph.GraphDiff;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.runtime.CayenneRuntime;
 
-public class CayenneRuntimeTest extends TestCase {
+public class CayenneServerRuntimeTest extends TestCase {
 
     public void testDefaultConstructor() {
-        CayenneRuntime runtime = new CayenneRuntime("xxxx");
+        CayenneServerRuntime runtime = new CayenneServerRuntime("xxxx");
 
         assertEquals("xxxx", runtime.getName());
 
         assertEquals(1, runtime.getModules().length);
-        assertTrue(runtime.getModules()[0] instanceof CayenneModule);
+        assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
     }
 
     public void testConstructor_Modules() {
@@ -62,7 +61,7 @@
             }
         };
 
-        CayenneRuntime runtime = new CayenneRuntime("yyyy", m1, m2);
+        CayenneServerRuntime runtime = new CayenneServerRuntime("yyyy", m1, m2);
 
         assertEquals("yyyy", runtime.getName());
         assertEquals(2, runtime.getModules().length);
@@ -102,7 +101,7 @@
             }
         };
 
-        CayenneRuntime runtime = new CayenneRuntime("name", module);
+        CayenneServerRuntime runtime = new CayenneServerRuntime("name", module);
         assertSame(channel, runtime.getDataChannel());
     }
 
@@ -116,8 +115,8 @@
             }
         };
 
-        CayenneRuntime runtime = new CayenneRuntime("name", module);
-        assertSame(context, runtime.newObjectContext());
-        assertSame(context, runtime.newObjectContext());
+        CayenneServerRuntime runtime = new CayenneServerRuntime("name", module);
+        assertSame(context, runtime.newContext());
+        assertSame(context, runtime.newContext());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/DataDomainProviderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/DataDomainProviderTest.java?rev=887668&r1=887667&r2=887668&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/DataDomainProviderTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/DataDomainProviderTest.java Sun Dec  6 11:23:18 2009
@@ -18,8 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.runtime;
 
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
 import java.util.Collections;
 
 import javax.sql.DataSource;
@@ -38,14 +36,14 @@
 import org.apache.cayenne.configuration.DataChannelDescriptorLoader;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.DataSourceFactoryLoader;
+import org.apache.cayenne.configuration.DbAdapterFactory;
 import org.apache.cayenne.configuration.DefaultAdhocObjectFactory;
 import org.apache.cayenne.configuration.DefaultRuntimeProperties;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.configuration.mock.MockDataSourceFactory;
 import org.apache.cayenne.configuration.mock.MockDataSourceFactoryLoader;
-import org.apache.cayenne.dba.AutoAdapter;
 import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.DbAdapterFactory;
+import org.apache.cayenne.dba.MockDbAdapter;
 import org.apache.cayenne.dba.oracle.OracleAdapter;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.DIBootstrap;
@@ -53,8 +51,6 @@
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.map.DataMap;
 
-import com.mockrunner.mock.jdbc.MockDataSource;
-
 public class DataDomainProviderTest extends TestCase {
 
     public void testGet() {
@@ -109,14 +105,19 @@
                         new SkipSchemaUpdateStrategy());
                 binder.bind(DbAdapterFactory.class).toInstance(new DbAdapterFactory() {
 
-                    public DbAdapter createAdapter(DatabaseMetaData md)
-                            throws SQLException {
-                        throw new UnsupportedOperationException("TODO");
+                    public DbAdapter createAdapter(
+                            DataNodeDescriptor nodeDescriptor,
+                            DataSource dataSource) throws Exception {
+
+                        if (nodeDescriptor.getAdapterType() != null) {
+                            return (DbAdapter) Class.forName(
+                                    nodeDescriptor.getAdapterType()).newInstance();
+                        }
+
+                        return new MockDbAdapter();
                     }
                 });
 
-                binder.bind(DataSource.class).toInstance(new MockDataSource());
-                binder.bind(DbAdapter.class).to(AutoAdapter.class);
                 binder.bind(DataSourceFactoryLoader.class).toInstance(
                         new MockDataSourceFactoryLoader());
                 binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
@@ -183,6 +184,6 @@
                 .getName());
 
         assertNotNull(node2.getAdapter());
-        assertEquals(AutoAdapter.class, node2.getAdapter().getClass());
+        assertEquals(MockDbAdapter.class, node2.getAdapter().getClass());
     }
 }

Added: cayenne/main/trunk/itests/cayenne-di-stack/.classpath
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/.classpath?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/.classpath (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/.classpath Sun Dec  6 11:23:18 2009
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: cayenne/main/trunk/itests/cayenne-di-stack/.project
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/.project?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/.project (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/.project Sun Dec  6 11:23:18 2009
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cayenne-di-stack</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

Added: cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.eclipse.jdt.core.prefs?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.eclipse.jdt.core.prefs (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.eclipse.jdt.core.prefs Sun Dec  6 11:23:18 2009
@@ -0,0 +1,5 @@
+#Sat Dec 05 19:10:26 EET 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5

Added: cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.maven.ide.eclipse.prefs
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.maven.ide.eclipse.prefs?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.maven.ide.eclipse.prefs (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/.settings/org.maven.ide.eclipse.prefs Sun Dec  6 11:23:18 2009
@@ -0,0 +1,9 @@
+#Sat Dec 05 19:10:25 EET 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1

Copied: cayenne/main/trunk/itests/cayenne-di-stack/pom.xml (from r887667, cayenne/main/trunk/itests/pom.xml)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/pom.xml?p2=cayenne/main/trunk/itests/cayenne-di-stack/pom.xml&p1=cayenne/main/trunk/itests/pom.xml&r1=887667&r2=887668&rev=887668&view=diff
==============================================================================
--- cayenne/main/trunk/itests/pom.xml (original)
+++ cayenne/main/trunk/itests/cayenne-di-stack/pom.xml Sun Dec  6 11:23:18 2009
@@ -17,42 +17,56 @@
 	specific language governing permissions and limitations
 	under the License.   
 -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.cayenne.itests</groupId>
+		<artifactId>cayenne-itests-parent</artifactId>
+		<version>3.1-SNAPSHOT</version>
+	</parent>
+
+	<description>Integration Tests - Cayenne DI Stack</description>
+	<artifactId>cayenne-di-stack</artifactId>
+	<name>Integration Tests - Cayenne DI Stack</name>
+	<packaging>jar</packaging>
+
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>compile</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.cayenne.itests</groupId>
+			<artifactId>itest-common</artifactId>
+			<version>${version}</version>
+		</dependency>
+
+	</dependencies>
 
-<project
-    xmlns="http://maven.apache.org/POM/4.0.0"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-    
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-      <groupId>org.apache.cayenne</groupId>
-      <artifactId>cayenne-parent</artifactId>
-      <version>3.1-SNAPSHOT</version>
-    </parent>
-
-    <groupId>org.apache.cayenne.itests</groupId>
-    <artifactId>cayenne-itests-parent</artifactId>
-    <name>Cayenne Integration Tests Parent</name>
-    <packaging>pom</packaging>
-    
-    <modules>
-      <module>itest-common</module>
-      <module>jpa-chapter2</module>
-      <module>jpa-chapter3</module>
-      <module>jpa-chapter5</module>
-      <module>jpa-chapter6</module>
-      <module>jpa-chapter9</module>
-    </modules>
 	<build>
 		<plugins>
 			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+			
+			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-deploy-plugin</artifactId>
 				<configuration>
 					<skip>true</skip>
 				</configuration>
 			</plugin>
+
 		</plugins>
 	</build>
 </project>

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/DefaultMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/DefaultMap.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/DefaultMap.java (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/DefaultMap.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,18 @@
+package org.apache.cayenne.itest.di_stack;
+
+import org.apache.cayenne.itest.di_stack.auto._DefaultMap;
+
+public class DefaultMap extends _DefaultMap {
+
+    private static DefaultMap instance;
+
+    private DefaultMap() {}
+
+    public static DefaultMap getInstance() {
+        if(instance == null) {
+            instance = new DefaultMap();
+        }
+
+        return instance;
+    }
+}

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/Table1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/Table1.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/Table1.java (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/Table1.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,7 @@
+package org.apache.cayenne.itest.di_stack;
+
+import org.apache.cayenne.itest.di_stack.auto._Table1;
+
+public class Table1 extends _Table1 {
+
+}

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_DefaultMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_DefaultMap.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_DefaultMap.java (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_DefaultMap.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,12 @@
+package org.apache.cayenne.itest.di_stack.auto;
+
+
+
+/**
+ * This class was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public class _DefaultMap {
+}
\ No newline at end of file

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_Table1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_Table1.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_Table1.java (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/itest/di_stack/auto/_Table1.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,24 @@
+package org.apache.cayenne.itest.di_stack.auto;
+
+import org.apache.cayenne.CayenneDataObject;
+
+/**
+ * Class _Table1 was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public abstract class _Table1 extends CayenneDataObject {
+
+    public static final String NAME_PROPERTY = "name";
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public void setName(String name) {
+        writeProperty("name", name);
+    }
+    public String getName() {
+        return (String)readProperty("name");
+    }
+
+}

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntimeCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntimeCase.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntimeCase.java (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/CayenneServerRuntimeCase.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,69 @@
+package org.apache.cayenne.runtime;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy;
+import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
+import org.apache.cayenne.itest.ItestDBUtils;
+import org.apache.cayenne.itest.ItestTableUtils;
+
+public abstract class CayenneServerRuntimeCase extends TestCase {
+
+	static final Map<RuntimeName, CayenneServerRuntime> runtimeCache;
+
+	static {
+		runtimeCache = new HashMap<RuntimeName, CayenneServerRuntime>();
+	}
+
+	protected CayenneServerRuntime runtime;
+
+	@Override
+	protected void setUp() throws Exception {
+
+		RuntimeName name = getRuntimeName();
+		assertNotNull(name);
+
+		runtime = runtimeCache.get(name);
+		if (runtime == null) {
+			runtime = new CayenneServerRuntime(name.name());
+			runtimeCache.put(name, runtime);
+
+			// setup schema
+
+			// TODO: should that be drop/create?
+			SchemaUpdateStrategy dbCreator = new CreateIfNoSchemaStrategy();
+			dbCreator.updateSchema(getDataNode());
+		}
+	}
+
+	@Override
+	protected void tearDown() throws Exception {
+		runtime = null;
+	}
+
+	protected abstract RuntimeName getRuntimeName();
+
+	protected ItestDBUtils getDbUtils() {
+
+		return new ItestDBUtils(getDataNode().getDataSource());
+	}
+
+	protected ItestTableUtils getTableHelper(String tableName) {
+		return new ItestTableUtils(getDbUtils(), tableName);
+	}
+
+	private DataNode getDataNode() {
+		Collection<DataNode> nodes = runtime.getDataDomain().getDataNodes();
+		assertFalse("Can't find DataSource - no nodes configured", nodes
+				.isEmpty());
+		assertEquals("Can't find DataSource - multiple nodes found", 1, nodes
+				.size());
+
+		return nodes.iterator().next();
+	}
+}

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/RuntimeName.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/RuntimeName.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/RuntimeName.java (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/runtime/RuntimeName.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,6 @@
+package org.apache.cayenne.runtime;
+
+public enum RuntimeName {
+
+	DEFAULT
+}

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/DefaultMap.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/DefaultMap.map.xml?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/DefaultMap.map.xml (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/DefaultMap.map.xml Sun Dec  6 11:23:18 2009
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+  project-version="3.0.0.1">
+	<property name="defaultPackage" value="org.apache.cayenne.itest.di_stack"/>
+	<db-entity name="TABLE1">
+		<db-attribute name="ID" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="NAME" type="VARCHAR" length="255"/>
+	</db-entity>
+	<obj-entity name="Table1" className="org.apache.cayenne.itest.di_stack.Table1" dbEntityName="TABLE1">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+	</obj-entity>
+</data-map>

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/PoolingDSNode.driver.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/PoolingDSNode.driver.xml?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/PoolingDSNode.driver.xml (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/PoolingDSNode.driver.xml Sun Dec  6 11:23:18 2009
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<driver project-version="3.0.0.1" class="org.hsqldb.jdbcDriver">
+	<url value="jdbc:hsqldb:mem:DEFAULT"/>
+	<connectionPool min="1" max="1"/>
+	<login/>
+</driver>

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/cayenne-DEFAULT.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/cayenne-DEFAULT.xml?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/cayenne-DEFAULT.xml (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/cayenne-DEFAULT.xml Sun Dec  6 11:23:18 2009
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain name="DefaultDomain" project-version="3.0.0.1">
+	<map name="DefaultMap" location="DefaultMap.map.xml"/>
+
+	<node name="PoolingDSNode"
+		 datasource="PoolingDSNode.driver.xml"
+		 factory="org.apache.cayenne.configuration.XMLPoolingDataSourceFactory">
+			<map-ref name="DefaultMap"/>
+	 </node>
+</domain>

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/log4j.properties?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/log4j.properties (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/resources/log4j.properties Sun Dec  6 11:23:18 2009
@@ -0,0 +1,6 @@
+log4j.rootLogger=WARN, A1
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=[%d{dd/MMM/yyyy:HH:mm:ss}] %t %x %-5p %c{1}: %m%n
+
+log4j.logger.org.apache.cayenne=DEBUG
\ No newline at end of file

Added: cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java?rev=887668&view=auto
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java (added)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java Sun Dec  6 11:23:18 2009
@@ -0,0 +1,61 @@
+package org.apache.cayenne.runtime;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.itest.ItestDBUtils;
+import org.apache.cayenne.itest.di_stack.Table1;
+import org.apache.cayenne.query.SelectQuery;
+
+public class CayenneServerRuntimeIntegrationTest extends
+		CayenneServerRuntimeCase {
+
+	@Override
+	protected RuntimeName getRuntimeName() {
+		return RuntimeName.DEFAULT;
+	}
+
+	public void testGetDomain_singleton() {
+
+		DataDomain domain1 = runtime.getDataDomain();
+		assertNotNull(domain1);
+
+		DataDomain domain2 = runtime.getDataDomain();
+		assertNotNull(domain2);
+
+		assertSame(domain1, domain2);
+	}
+
+	public void testNewContext_notSingleton() {
+
+		ObjectContext context1 = runtime.newContext();
+		assertNotNull(context1);
+
+		ObjectContext context2 = runtime.newContext();
+		assertNotNull(context2);
+
+		assertNotSame(context1, context2);
+	}
+
+	public void testNewContext_separateObjects() throws Exception {
+		ItestDBUtils dbUtils = getDbUtils();
+		dbUtils.deleteAll("TABLE1");
+		dbUtils.insert("TABLE1", new String[] { "ID", "NAME" }, new Object[] {
+				1, "Abc" });
+
+		SelectQuery query = new SelectQuery(Table1.class);
+
+		ObjectContext context1 = runtime.newContext();
+		ObjectContext context2 = runtime.newContext();
+
+		Table1 o1 = (Table1) Cayenne.objectForQuery(context1, query);
+		Table1 o2 = (Table1) Cayenne.objectForQuery(context2, query);
+
+		assertNotNull(o1);
+		assertNotNull(o2);
+		assertEquals("Abc", o1.getName());
+		assertNotSame(o1, o2);
+		assertEquals(o1.getObjectId(), o2.getObjectId());
+
+	}
+}

Modified: cayenne/main/trunk/itests/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/pom.xml?rev=887668&r1=887667&r2=887668&view=diff
==============================================================================
--- cayenne/main/trunk/itests/pom.xml (original)
+++ cayenne/main/trunk/itests/pom.xml Sun Dec  6 11:23:18 2009
@@ -38,6 +38,7 @@
     
     <modules>
       <module>itest-common</module>
+      <module>cayenne-di-stack</module>
       <module>jpa-chapter2</module>
       <module>jpa-chapter3</module>
       <module>jpa-chapter5</module>



Mime
View raw message