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 2009/11/30 18:00:42 UTC

svn commit: r885498 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/configuration/ main/java/org/apache/cayenne/dba/ main/java/org/apache/cayenne/runtime/ test/java/org/apache/cayenne/configuration/ test/...

Author: aadamchik
Date: Mon Nov 30 17:00:41 2009
New Revision: 885498

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

* DataDomainProvider - user classes created via injection
* alt DataSourceFactory

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataSourceFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DriverDataSourceFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/JNDIDataSourceFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory1.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory2.java
Modified:
    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/DataNodeDescriptor.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/dba/AutoAdapter.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/configuration/XMLDataChannelDescriptorLoaderTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/DataDomainProviderTest.java

Modified: 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/CayenneModule.java?rev=885498&r1=885497&r2=885498&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/CayenneModule.java Mon Nov 30 17:00:41 2009
@@ -19,6 +19,10 @@
 package org.apache.cayenne.configuration;
 
 import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
+import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
+import org.apache.cayenne.dba.AutoAdapter;
+import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
 import org.apache.cayenne.di.Scopes;
@@ -26,6 +30,8 @@
 import org.apache.cayenne.resource.ResourceLocator;
 import org.apache.cayenne.runtime.CayenneRuntime;
 import org.apache.cayenne.runtime.DataDomainProvider;
+import org.apache.cayenne.runtime.DataSourceFactory;
+import org.apache.cayenne.runtime.DriverDataSourceFactory;
 
 /**
  * A DI module containing all Cayenne runtime configurations. To customize Cayenne runtime
@@ -66,5 +72,17 @@
         // a global properties object
         binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class).in(
                 Scopes.SINGLETON);
+
+        // a default SchemaUpdateStrategy (used when no explicit strategy is specified in
+        // XML)
+        binder.bind(SchemaUpdateStrategy.class).to(SkipSchemaUpdateStrategy.class);
+
+        // a default DBAdapter (used when no explicit adapter is set in XML)
+
+        // TODO: andrus 11.30.2009: missing dependencies: DataSource, DbAdapterFactory
+        binder.bind(DbAdapter.class).to(AutoAdapter.class);
+
+        // a service to find or create DataSources
+        binder.bind(DataSourceFactory.class).to(DriverDataSourceFactory.class);
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DataNodeDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DataNodeDescriptor.java?rev=885498&r1=885497&r2=885498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DataNodeDescriptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/DataNodeDescriptor.java Mon Nov 30 17:00:41 2009
@@ -35,9 +35,9 @@
     protected Collection<String> dataMapNames;
 
     protected String location;
-    protected String adapterClass;
-    protected String dataSourceFactoryClass;
-    protected String schemaUpdateStrategyClass;
+    protected String adapterType;
+    protected String dataSourceFactoryType;
+    protected String schemaUpdateStrategyType;
 
     protected Resource configurationResource;
 
@@ -65,20 +65,20 @@
         this.location = location;
     }
 
-    public String getAdapterClass() {
-        return adapterClass;
+    public String getAdapterType() {
+        return adapterType;
     }
 
-    public void setAdapterClass(String adapter) {
-        this.adapterClass = adapter;
+    public void setAdapterType(String adapter) {
+        this.adapterType = adapter;
     }
 
-    public String getDataSourceFactoryClass() {
-        return dataSourceFactoryClass;
+    public String getDataSourceFactoryType() {
+        return dataSourceFactoryType;
     }
 
-    public void setDataSourceFactoryClass(String dataSourceFactory) {
-        this.dataSourceFactoryClass = dataSourceFactory;
+    public void setDataSourceFactoryType(String dataSourceFactory) {
+        this.dataSourceFactoryType = dataSourceFactory;
     }
 
     public Resource getConfigurationResource() {
@@ -89,11 +89,11 @@
         this.configurationResource = descriptorResource;
     }
 
-    public String getSchemaUpdateStrategyClass() {
-        return schemaUpdateStrategyClass;
+    public String getSchemaUpdateStrategyType() {
+        return schemaUpdateStrategyType;
     }
 
-    public void setSchemaUpdateStrategyClass(String schemaUpdateStrategyClass) {
-        this.schemaUpdateStrategyClass = schemaUpdateStrategyClass;
+    public void setSchemaUpdateStrategyType(String schemaUpdateStrategyClass) {
+        this.schemaUpdateStrategyType = schemaUpdateStrategyClass;
     }
 }

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=885498&r1=885497&r2=885498&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 Mon Nov 30 17:00:41 2009
@@ -166,16 +166,16 @@
                 descriptor.getDataNodeDescriptors().add(nodeDescriptor);
 
                 nodeDescriptor.setName(nodeName);
-                nodeDescriptor.setAdapterClass(attributes.getValue("", "adapter"));
+                nodeDescriptor.setAdapterType(attributes.getValue("", "adapter"));
 
                 // TODO: andrus, 11.29.2009 : should we rename that to "location"??
                 String location = attributes.getValue("", "datasource");
                 nodeDescriptor.setLocation(location);
 
-                nodeDescriptor.setDataSourceFactoryClass(attributes.getValue(
+                nodeDescriptor.setDataSourceFactoryType(attributes.getValue(
                         "",
                         "factory"));
-                nodeDescriptor.setSchemaUpdateStrategyClass(attributes.getValue(
+                nodeDescriptor.setSchemaUpdateStrategyType(attributes.getValue(
                         "",
                         "schema-update-strategy"));
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java?rev=885498&r1=885497&r2=885498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/AutoAdapter.java Mon Nov 30 17:00:41 2009
@@ -48,6 +48,7 @@
 import org.apache.cayenne.dba.sqlite.SQLiteSniffer;
 import org.apache.cayenne.dba.sqlserver.SQLServerSniffer;
 import org.apache.cayenne.dba.sybase.SybaseSniffer;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
@@ -125,7 +126,8 @@
      * Creates an AutoAdapter with specified adapter factory and DataSource. If
      * adapterFactory is null, default factory is used.
      */
-    public AutoAdapter(DbAdapterFactory adapterFactory, DataSource dataSource) {
+    public AutoAdapter(@Inject DbAdapterFactory adapterFactory,
+            @Inject DataSource dataSource) {
         // sanity check
         if (dataSource == null) {
             throw new CayenneRuntimeException("Null dataSource");

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=885498&r1=885497&r2=885498&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 Mon Nov 30 17:00:41 2009
@@ -39,7 +39,8 @@
     protected Module[] modules;
 
     /**
-     * Initializes a configuration with a default CayenneModule.
+     * 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
@@ -50,7 +51,7 @@
     }
 
     /**
-     * Initializes a configuration with an array of DI modules.
+     * Initializes Cayenne runtime with an array of DI modules.
      */
     public CayenneRuntime(String name, Module... modules) {
 

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=885498&r1=885497&r2=885498&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 Mon Nov 30 17:00:41 2009
@@ -18,19 +18,22 @@
  ****************************************************************/
 package org.apache.cayenne.runtime;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
-import org.apache.cayenne.conf.DriverDataSourceFactory;
+import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataChannelDescriptorLoader;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.di.DIException;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.Provider;
 import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.util.Util;
 
 /**
  * A {@link DataChannel} provider that provides a single instance of DataDomain configured
@@ -46,6 +49,18 @@
     @Inject
     protected RuntimeProperties configurationProperties;
 
+    @Inject
+    protected SchemaUpdateStrategy defaultSchemaUpdateStrategy;
+
+    @Inject
+    protected DbAdapter defaultAdapter;
+
+    @Inject
+    protected DataSourceFactory defaultDataSourceFactory;
+
+    @Inject
+    protected Injector injector;
+
     protected volatile DataChannel dataChannel;
 
     public DataChannel get() throws DIException {
@@ -74,24 +89,55 @@
             dataChannel.addMap(dataMap);
         }
 
-        for (DataNodeDescriptor dataNodeDescriptor : descriptor.getDataNodeDescriptors()) {
-            DataNode dataNode = new DataNode(dataNodeDescriptor.getName());
+        for (DataNodeDescriptor nodeDescriptor : descriptor.getDataNodeDescriptors()) {
+            DataNode dataNode = new DataNode(nodeDescriptor.getName());
+
+            dataNode.setDataSourceLocation(nodeDescriptor.getLocation());
 
-            String dataSourceFactoryClass = dataNodeDescriptor
-                    .getDataSourceFactoryClass() != null ? dataNodeDescriptor
-                    .getDataSourceFactoryClass() : DriverDataSourceFactory.class
-                    .getName();
-            dataNode.setDataSourceFactory(dataSourceFactoryClass);
-
-            dataNode.setDataSourceLocation(dataNodeDescriptor.getLocation());
-
-            String schemaUpdateStrategyName = dataNodeDescriptor
-                    .getSchemaUpdateStrategyClass() != null ? dataNodeDescriptor
-                    .getSchemaUpdateStrategyClass() : SkipSchemaUpdateStrategy.class
-                    .getName();
-            dataNode.setSchemaUpdateStrategyName(schemaUpdateStrategyName);
+            String dataSourceFactoryType = nodeDescriptor.getDataSourceFactoryType();
+            if (dataSourceFactoryType == null) {
+                dataNode.setDataSourceFactory(defaultDataSourceFactory
+                        .getClass()
+                        .getName());
+                dataNode.setDataSource(defaultDataSourceFactory
+                        .getDataSource(nodeDescriptor));
+            }
+            else {
+                dataNode.setDataSourceFactory(dataSourceFactoryType);
+                DataSourceFactory factory = newInstance(
+                        DataSourceFactory.class,
+                        dataSourceFactoryType);
+                dataNode.setDataSource(factory.getDataSource(nodeDescriptor));
+            }
 
-            for (String dataMapName : dataNodeDescriptor.getDataMapNames()) {
+            // schema update strategy
+            String schemaUpdateStrategyType = nodeDescriptor
+                    .getSchemaUpdateStrategyType();
+
+            if (schemaUpdateStrategyType == null) {
+                dataNode.setSchemaUpdateStrategy(defaultSchemaUpdateStrategy);
+                dataNode.setSchemaUpdateStrategyName(defaultSchemaUpdateStrategy
+                        .getClass()
+                        .getName());
+            }
+            else {
+                dataNode.setSchemaUpdateStrategyName(schemaUpdateStrategyType);
+                dataNode.setSchemaUpdateStrategy(newInstance(
+                        SchemaUpdateStrategy.class,
+                        schemaUpdateStrategyType));
+            }
+
+            // DbAdapter
+            String adapterType = nodeDescriptor.getAdapterType();
+            if (adapterType == null) {
+                dataNode.setAdapter(defaultAdapter);
+            }
+            else {
+                dataNode.setAdapter(newInstance(DbAdapter.class, adapterType));
+            }
+
+            // DataMaps
+            for (String dataMapName : nodeDescriptor.getDataMapNames()) {
                 dataNode.addDataMap(dataChannel.getMap(dataMapName));
             }
 
@@ -100,4 +146,33 @@
 
         this.dataChannel = dataChannel;
     }
+
+    private <T> T newInstance(Class<? extends T> interfaceType, String className) {
+
+        Class<? extends T> type;
+        try {
+            type = (Class<? extends T>) Util.getJavaClass(className);
+        }
+        catch (ClassNotFoundException e) {
+            throw new CayenneRuntimeException(
+                    "Invalid class %s of type %s",
+                    e,
+                    className,
+                    interfaceType.getName());
+        }
+        T instance;
+        try {
+            instance = type.newInstance();
+        }
+        catch (Exception e) {
+            throw new CayenneRuntimeException(
+                    "Error creating instance of class %s of type %s",
+                    e,
+                    className,
+                    interfaceType.getName());
+        }
+
+        injector.injectMembers(instance);
+        return instance;
+    }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataSourceFactory.java?rev=885498&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataSourceFactory.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DataSourceFactory.java Mon Nov 30 17:00:41 2009
@@ -0,0 +1,36 @@
+/*****************************************************************
+ *   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 javax.sql.DataSource;
+
+import org.apache.cayenne.configuration.DataNodeDescriptor;
+
+/**
+ * Provides instances of {@link DataSource} for DataNodes.
+ * 
+ * @since 3.1
+ */
+public interface DataSourceFactory {
+
+    /**
+     * Returns a DataSource for a given {@link DataNodeDescriptor} configuration object.
+     */
+    DataSource getDataSource(DataNodeDescriptor nodeDescriptor);
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DriverDataSourceFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DriverDataSourceFactory.java?rev=885498&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DriverDataSourceFactory.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/DriverDataSourceFactory.java Mon Nov 30 17:00:41 2009
@@ -0,0 +1,34 @@
+/*****************************************************************
+ *   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 javax.sql.DataSource;
+
+import org.apache.cayenne.configuration.DataNodeDescriptor;
+
+/**
+ * @since 3.1
+ */
+public class DriverDataSourceFactory implements DataSourceFactory {
+
+    public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) {
+        throw new UnsupportedOperationException("TODO");
+    }
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/JNDIDataSourceFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/JNDIDataSourceFactory.java?rev=885498&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/JNDIDataSourceFactory.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/runtime/JNDIDataSourceFactory.java Mon Nov 30 17:00:41 2009
@@ -0,0 +1,66 @@
+/*****************************************************************
+ *   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 javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.access.QueryLogger;
+import org.apache.cayenne.configuration.DataNodeDescriptor;
+
+/**
+ * @since 3.1
+ */
+public class JNDIDataSourceFactory implements DataSourceFactory {
+
+    public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) {
+        try {
+            return loadViaJNDI(nodeDescriptor.getLocation());
+        }
+        catch (NamingException e) {
+            QueryLogger.logConnectFailure(e);
+            throw new CayenneRuntimeException(
+                    "Error loading DataSource from JNDI for location '%s'",
+                    e,
+                    nodeDescriptor.getLocation());
+        }
+    }
+
+    DataSource loadViaJNDI(String location) throws NamingException {
+        QueryLogger.logConnect(location);
+
+        Context context = new InitialContext();
+        DataSource dataSource;
+        try {
+            Context envCtx = (Context) context.lookup("java:comp/env");
+            dataSource = (DataSource) envCtx.lookup(location);
+        }
+        catch (NamingException namingEx) {
+            // try looking up the location directly...
+            dataSource = (DataSource) context.lookup(location);
+        }
+
+        QueryLogger.logConnectSuccess();
+        return dataSource;
+    }
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoaderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoaderTest.java?rev=885498&r1=885497&r2=885498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoaderTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/XMLDataChannelDescriptorLoaderTest.java Mon Nov 30 17:00:41 2009
@@ -236,11 +236,11 @@
                 .getConfigurationResource()
                 .getURL());
 
-        assertEquals("org.example.test.Adapter", node1.getAdapterClass());
+        assertEquals("org.example.test.Adapter", node1.getAdapterType());
         assertEquals("org.example.test.DataSourceFactory", node1
-                .getDataSourceFactoryClass());
+                .getDataSourceFactoryType());
         assertEquals("org.example.test.SchemaUpdateStartegy", node1
-                .getSchemaUpdateStrategyClass());
+                .getSchemaUpdateStrategyType());
         assertNotNull(node1.getDataMapNames());
 
         assertEquals(1, node1.getDataMapNames().size());

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=885498&r1=885497&r2=885498&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 Mon Nov 30 17:00:41 2009
@@ -18,23 +18,29 @@
  ****************************************************************/
 package org.apache.cayenne.runtime;
 
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
 import java.util.Collections;
 
+import javax.sql.DataSource;
+
 import junit.framework.TestCase;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataChannel;
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.DataNode;
+import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
 import org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy;
 import org.apache.cayenne.access.dbsync.ThrowOnPartialOrCreateSchemaStrategy;
-import org.apache.cayenne.conf.DriverDataSourceFactory;
-import org.apache.cayenne.conf.JNDIDataSourceFactory;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataChannelDescriptorLoader;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.configuration.DefaultRuntimeProperties;
 import org.apache.cayenne.configuration.RuntimeProperties;
+import org.apache.cayenne.dba.AutoAdapter;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.dba.DbAdapterFactory;
 import org.apache.cayenne.dba.oracle.OracleAdapter;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.DIBootstrap;
@@ -42,6 +48,8 @@
 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() {
@@ -59,11 +67,11 @@
         DataNodeDescriptor nodeDescriptor1 = new DataNodeDescriptor();
         nodeDescriptor1.setName("node1");
         nodeDescriptor1.getDataMapNames().add("map1");
-        nodeDescriptor1.setAdapterClass(OracleAdapter.class.getName());
-        nodeDescriptor1.setDataSourceFactoryClass(JNDIDataSourceFactory.class.getName());
+        nodeDescriptor1.setAdapterType(OracleAdapter.class.getName());
+        nodeDescriptor1.setDataSourceFactoryType(MockDataSourceFactory1.class.getName());
         nodeDescriptor1.setLocation("jdbc/testDataNode1");
         nodeDescriptor1
-                .setSchemaUpdateStrategyClass(ThrowOnPartialOrCreateSchemaStrategy.class
+                .setSchemaUpdateStrategyType(ThrowOnPartialOrCreateSchemaStrategy.class
                         .getName());
         testDescriptor.getDataNodeDescriptors().add(nodeDescriptor1);
 
@@ -92,6 +100,20 @@
             public void configure(Binder binder) {
                 binder.bind(RuntimeProperties.class).toInstance(testProperties);
                 binder.bind(DataChannelDescriptorLoader.class).toInstance(testLoader);
+                binder.bind(SchemaUpdateStrategy.class).toInstance(
+                        new SkipSchemaUpdateStrategy());
+                binder.bind(DbAdapterFactory.class).toInstance(new DbAdapterFactory() {
+
+                    public DbAdapter createAdapter(DatabaseMetaData md)
+                            throws SQLException {
+                        throw new UnsupportedOperationException("TODO");
+                    }
+                });
+
+                binder.bind(DataSource.class).toInstance(new MockDataSource());
+                binder.bind(DbAdapter.class).to(AutoAdapter.class);
+                binder.bind(DataSourceFactory.class).toInstance(
+                        new MockDataSourceFactory2());
             }
         };
 
@@ -122,27 +144,40 @@
         assertEquals(1, node1.getDataMaps().size());
         assertSame(map1, node1.getDataMaps().iterator().next());
         assertSame(node1, domain.lookupDataNode(map1));
-        assertEquals(nodeDescriptor1.getDataSourceFactoryClass(), node1
+        assertEquals(nodeDescriptor1.getDataSourceFactoryType(), node1
                 .getDataSourceFactory());
+        assertNotNull(node1.getDataSource());
         assertEquals(nodeDescriptor1.getLocation(), node1.getDataSourceLocation());
-        assertEquals(nodeDescriptor1.getSchemaUpdateStrategyClass(), node1
+
+        assertEquals(nodeDescriptor1.getSchemaUpdateStrategyType(), node1
                 .getSchemaUpdateStrategyName());
+        assertNotNull(node1.getSchemaUpdateStrategy());
+        assertEquals(nodeDescriptor1.getSchemaUpdateStrategyType(), node1
+                .getSchemaUpdateStrategy()
+                .getClass()
+                .getName());
 
-        // assertNotNull(node1.getAdapter());
-        // assertEquals(OracleAdapter.class, node1.getAdapter().getClass());
+        assertNotNull(node1.getAdapter());
+        assertEquals(OracleAdapter.class, node1.getAdapter().getClass());
 
         DataNode node2 = domain.getNode("node2");
         assertNotNull(node2);
         assertEquals(1, node2.getDataMaps().size());
         assertSame(map2, node2.getDataMaps().iterator().next());
         assertSame(node2, domain.lookupDataNode(map2));
-        assertEquals(DriverDataSourceFactory.class.getName(), node2
+        assertEquals(MockDataSourceFactory2.class.getName(), node2
                 .getDataSourceFactory());
+        assertNotNull(node2.getDataSource());
         assertEquals(nodeDescriptor2.getLocation(), node2.getDataSourceLocation());
         assertEquals(SkipSchemaUpdateStrategy.class.getName(), node2
                 .getSchemaUpdateStrategyName());
-        // assertNotNull(node2.getAdapter());
-        // assertEquals(AutoAdapter.class, node2.getAdapter().getClass());
+        assertNotNull(node2.getSchemaUpdateStrategy());
+        assertEquals(SkipSchemaUpdateStrategy.class.getName(), node2
+                .getSchemaUpdateStrategy()
+                .getClass()
+                .getName());
 
+        assertNotNull(node2.getAdapter());
+        assertEquals(AutoAdapter.class, node2.getAdapter().getClass());
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory1.java?rev=885498&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory1.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory1.java Mon Nov 30 17:00:41 2009
@@ -0,0 +1,32 @@
+/*****************************************************************
+ *   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 javax.sql.DataSource;
+
+import org.apache.cayenne.configuration.DataNodeDescriptor;
+
+import com.mockrunner.mock.jdbc.MockDataSource;
+
+public class MockDataSourceFactory1 implements DataSourceFactory {
+
+    public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) {
+        return new MockDataSource();
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory2.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory2.java?rev=885498&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory2.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/runtime/MockDataSourceFactory2.java Mon Nov 30 17:00:41 2009
@@ -0,0 +1,33 @@
+/*****************************************************************
+ *   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 javax.sql.DataSource;
+
+import org.apache.cayenne.configuration.DataNodeDescriptor;
+
+import com.mockrunner.mock.jdbc.MockDataSource;
+
+public class MockDataSourceFactory2 implements DataSourceFactory {
+
+    public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) {
+        return new MockDataSource();
+    }
+
+}