cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1072546 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/configuration/server/ test/java/org/apache/cayenne/configuration/mock/ test/java/org/apache/cayenne/configuration/server/
Date Sun, 20 Feb 2011 10:23:01 GMT
Author: aadamchik
Date: Sun Feb 20 10:23:01 2011
New Revision: 1072546

URL: http://svn.apache.org/viewvc?rev=1072546&view=rev
Log:
CAY-1542 DI container is not shutting down Cayenne-managed connection pool

preliminary refactoring - shortening the chain of objects not managed by DI that participate
in creation of DataSource. Now DataSourceFactory is bound in the DI container directly.

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DelegatingDataSourceFactory.java
      - copied, changed from r1072439, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoader.java
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataSourceFactoryLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/mock/MockDataSourceFactoryLoader.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoaderTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java?rev=1072546&r1=1072545&r2=1072546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
Sun Feb 20 10:23:01 2011
@@ -77,7 +77,7 @@ public class DataDomainProvider implemen
     protected DbAdapterFactory adapterFactory;
 
     @Inject
-    protected DataSourceFactoryLoader dataSourceFactoryLoader;
+    protected DataSourceFactory dataSourceFactory;
 
     @Inject
     protected AdhocObjectFactory objectFactory;
@@ -179,9 +179,6 @@ public class DataDomainProvider implemen
 
             dataNode.setDataSourceLocation(nodeDescriptor.getParameters());
 
-            DataSourceFactory dataSourceFactory = dataSourceFactoryLoader
-                    .getDataSourceFactory(nodeDescriptor);
-
             DataSource dataSource = dataSourceFactory.getDataSource(nodeDescriptor);
 
             dataNode.setDataSourceFactory(nodeDescriptor.getDataSourceFactoryType());

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DelegatingDataSourceFactory.java
(from r1072439, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoader.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DelegatingDataSourceFactory.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DelegatingDataSourceFactory.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoader.java&r1=1072439&r2=1072546&rev=1072546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoader.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DelegatingDataSourceFactory.java
Sun Feb 20 10:23:01 2011
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.configuration.server;
 
+import javax.sql.DataSource;
+
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.configuration.AdhocObjectFactory;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
@@ -26,27 +28,31 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * A {@link DataSourceFactoryLoader} that loads factories explicitly configured in the
- * {@link DataNodeDescriptor}. If the factory class is not explicitly configured, and the
- * descriptor has a configuration resource attached to it,
- * {@link XMLPoolingDataSourceFactory} is returned.
+ * A {@link DataSourceFactory} that delegates DataSource creation to another factory,
+ * which is determined dynamically per DataNodeDescriptor. The delegate class may be
+ * explicitly defined in the {@link DataNodeDescriptor}. If not, and if the descriptor has
+ * a configuration resource attached to it, {@link XMLPoolingDataSourceFactory} is used.
  * <p>
  * If the environment contains properties <em>cayenne.jdbc.url.domain_name.node_name</em>
  * (or <em>cayenne.jdbc.url</em>) and <em>cayenne.jdbc.driver.domain_name.node_name</em>
- * (or <em>cayenne.jdbc.driver</em>), any DataSourceFactory configured in the
project is
- * ignored, and the {@link PropertyDataSourceFactory} is returned.
+ * (or <em>cayenne.jdbc.driver</em>), any DataSourceFactory configured in the
+ * DataNodeDescriptor is ignored, and the {@link PropertyDataSourceFactory} is used.
  * 
  * @since 3.1
  */
-public class DefaultDataSourceFactoryLoader implements DataSourceFactoryLoader {
+public class DelegatingDataSourceFactory implements DataSourceFactory {
 
     private static final Log logger = LogFactory
-            .getLog(DefaultDataSourceFactoryLoader.class);
+            .getLog(DelegatingDataSourceFactory.class);
 
     @Inject
     protected AdhocObjectFactory objectFactory;
 
-    public DataSourceFactory getDataSourceFactory(DataNodeDescriptor nodeDescriptor) {
+    public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Exception {
+        return getDataSourceFactory(nodeDescriptor).getDataSource(nodeDescriptor);
+    }
+
+    protected DataSourceFactory getDataSourceFactory(DataNodeDescriptor nodeDescriptor) {
         String typeName = null;
 
         if (shouldConfigureDataSourceFromProperties(nodeDescriptor)) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java?rev=1072546&r1=1072545&r2=1072546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
Sun Feb 20 10:23:01 2011
@@ -145,9 +145,10 @@ public class ServerModule implements Mod
         // a global properties object
         binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
 
-        // a service to load DataSourceFactories
-        binder.bind(DataSourceFactoryLoader.class).to(
-                DefaultDataSourceFactoryLoader.class);
+        // a service to load DataSourceFactories. DelegatingDataSourceFactory will attempt
+        // to find the actual worker factory dynamically on each call depending on
+        // DataNodeDescriptor data and the environment
+        binder.bind(DataSourceFactory.class).to(DelegatingDataSourceFactory.class);
 
         // a default SchemaUpdateStrategy (used when no explicit strategy is specified in
         // XML)

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java?rev=1072546&r1=1072545&r2=1072546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
Sun Feb 20 10:23:01 2011
@@ -44,8 +44,6 @@ import org.apache.cayenne.configuration.
 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.configuration.server.DataDomainProvider;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.MockDbAdapter;
 import org.apache.cayenne.dba.oracle.OracleAdapter;
@@ -143,8 +141,8 @@ public class DataDomainProviderTest exte
                     }
                 });
 
-                binder.bind(DataSourceFactoryLoader.class).toInstance(
-                        new MockDataSourceFactoryLoader());
+                binder.bind(DataSourceFactory.class).toInstance(
+                        new MockDataSourceFactory());
                 binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
             }
         };

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoaderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoaderTest.java?rev=1072546&r1=1072545&r2=1072546&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoaderTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DefaultDataSourceFactoryLoaderTest.java
Sun Feb 20 10:23:01 2011
@@ -29,7 +29,7 @@ import org.apache.cayenne.configuration.
 import org.apache.cayenne.configuration.DefaultAdhocObjectFactory;
 import org.apache.cayenne.configuration.mock.MockDataSourceFactory1;
 import org.apache.cayenne.configuration.server.DataSourceFactory;
-import org.apache.cayenne.configuration.server.DefaultDataSourceFactoryLoader;
+import org.apache.cayenne.configuration.server.DelegatingDataSourceFactory;
 import org.apache.cayenne.configuration.server.PropertyDataSourceFactory;
 import org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory;
 import org.apache.cayenne.conn.DataSourceInfo;
@@ -58,7 +58,7 @@ public class DefaultDataSourceFactoryLoa
 
         Injector injector = DIBootstrap.createInjector(testModule);
 
-        DefaultDataSourceFactoryLoader factoryLoader = new DefaultDataSourceFactoryLoader();
+        DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
         injector.injectMembers(factoryLoader);
 
         DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
@@ -82,7 +82,7 @@ public class DefaultDataSourceFactoryLoa
 
         Injector injector = DIBootstrap.createInjector(testModule);
 
-        DefaultDataSourceFactoryLoader factoryLoader = new DefaultDataSourceFactoryLoader();
+        DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
         injector.injectMembers(factoryLoader);
 
         DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
@@ -117,7 +117,7 @@ public class DefaultDataSourceFactoryLoa
 
         properties.put(PropertyDataSourceFactory.JDBC_DRIVER_PROPERTY, "x");
         properties.put(PropertyDataSourceFactory.JDBC_URL_PROPERTY, "y");
-        DefaultDataSourceFactoryLoader factoryLoader = new DefaultDataSourceFactoryLoader()
{
+        DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory() {
 
             @Override
             protected String getProperty(String key) {



Mime
View raw message