cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r553872 - in /cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl: ./ src/changes/ src/main/java/org/apache/cocoon/core/ src/main/java/org/apache/cocoon/core/container/ src/main/java/org/apache/cocoon/core/container/spring/ src/main/...
Date Fri, 06 Jul 2007 13:11:47 GMT
Author: gkossakowski
Date: Fri Jul  6 06:11:46 2007
New Revision: 553872

URL: http://svn.apache.org/viewvc?view=rev&rev=553872
Log:
COCOON-2083: Implemented bridge to allow database connections defined as Spring beans to be
used in Avalon components.
The bridge replaces standard Avalon's DataSourceSelector.

Added:
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SpringToAvalonDataSourceBridge.java
  (with props)
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/META-INF/cocoon/spring/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/META-INF/cocoon/spring/SpringToAvalonDataSourceBridge.xml
  (with props)
Modified:
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/pom.xml
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/changes/changes.xml
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/org/apache/cocoon/components/database/database.roles

Modified: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/pom.xml?view=diff&rev=553872&r1=553871&r2=553872
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/pom.xml (original)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/pom.xml Fri Jul  6 06:11:46
2007
@@ -62,6 +62,11 @@
       <groupId>org.apache.excalibur.components</groupId>
       <artifactId>excalibur-datasource</artifactId>    
     </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-jdbc</artifactId>
+      <version>2.0.6</version>
+    </dependency>    
   </dependencies>
   
   <profiles>

Modified: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/changes/changes.xml?view=diff&rev=553872&r1=553871&r2=553872
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/changes/changes.xml (original)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/changes/changes.xml Fri
Jul  6 06:11:46 2007
@@ -24,8 +24,10 @@
     +-->
 <document>
   <body>
-    <release version="1.0.0-RC1" date="2007-??-??" description="unreleased">
-      
+    <release version="1.0.0-RC2" date="2007-??-??" description="unreleased">
+      <action dev="gkossakowski" type="add" fixes-bug="COCOON-2083">
+      	Implemented bridge to allow database connections defined as Spring beans to be used
in Avalon components.
+      </action>
     </release>
     <release version="1.0.0-M1" date="2007-03-02" description="released">  
       <action dev="cziegeler" type="add">

Added: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SpringToAvalonDataSourceBridge.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SpringToAvalonDataSourceBridge.java?view=auto&rev=553872
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SpringToAvalonDataSourceBridge.java
(added)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SpringToAvalonDataSourceBridge.java
Fri Jul  6 06:11:46 2007
@@ -0,0 +1,77 @@
+package org.apache.cocoon.core.container.spring.avalon;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.apache.avalon.excalibur.datasource.DataSourceComponent;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceSelector;
+
+/**
+ * This class replaces standard Avalon's DataSourceSelector to provide access to database
connections
+ * defined as Spring beans.
+ *  
+ * @version $Id$
+ */
+public class SpringToAvalonDataSourceBridge implements ServiceSelector {
+    private ServiceSelector dataSourceSelector;
+    private Map springDataSources;
+
+    public boolean isSelectable(Object policy) {
+        return dataSourceSelector.isSelectable(policy) || springDataSources.containsKey(policy);
+    }
+
+    public void release(Object object) {
+        if (object instanceof DataSourceComponent)
+            dataSourceSelector.release(object);
+    }
+
+    public Object select(Object policy) throws ServiceException {
+        if (dataSourceSelector.isSelectable(policy))
+            return dataSourceSelector.select(policy);
+        else if (springDataSources.containsKey(policy))
+            return new SpringDataSourceWrapper((DataSource) springDataSources.get(policy));
+        else
+            return null;
+    }
+    
+    private class SpringDataSourceWrapper implements DataSourceComponent {
+        
+        private DataSource springDataSource;
+        
+        private SpringDataSourceWrapper(DataSource springDataSource) {
+            this.springDataSource = springDataSource;
+        }
+
+        public Connection getConnection() throws SQLException {
+            return springDataSource.getConnection();
+        }
+
+        public void configure(Configuration configuration) throws ConfigurationException
{
+            //do nothing   
+        }
+        
+    }
+
+    public Map getSpringDataSources() {
+        return springDataSources;
+    }
+
+    public void setSpringDataSources(Map springDataSources) {
+        this.springDataSources = springDataSources;
+    }
+
+    public ServiceSelector getDataSourceSelector() {
+        return dataSourceSelector;
+    }
+
+    public void setDataSourceSelector(ServiceSelector dataSourceSelector) {
+        this.dataSourceSelector = dataSourceSelector;
+    }
+
+}

Propchange: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SpringToAvalonDataSourceBridge.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SpringToAvalonDataSourceBridge.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/META-INF/cocoon/spring/SpringToAvalonDataSourceBridge.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/META-INF/cocoon/spring/SpringToAvalonDataSourceBridge.xml?view=auto&rev=553872
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/META-INF/cocoon/spring/SpringToAvalonDataSourceBridge.xml
(added)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/META-INF/cocoon/spring/SpringToAvalonDataSourceBridge.xml
Fri Jul  6 06:11:46 2007
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!-- SVN $Id$ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:configurator="http://cocoon.apache.org/schema/configurator"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+  http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.1.xsd">
+  
+  <bean id="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
+        class="org.apache.cocoon.core.container.spring.avalon.SpringToAvalonDataSourceBridge">
+    <property name="springDataSources">
+      <!-- FIXME: Type should be changed to javax.sql.DataSource -->
+      <configurator:bean-map type="org.springframework.jdbc.datasource.DriverManagerDataSource"/>
+    </property>
+    <property name="dataSourceSelector" ref="org.apache.avalon.excalibur.datasource.DataSourceComponentLegacySelector"/>
+  </bean>
+  
+</beans>
\ No newline at end of file

Propchange: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/META-INF/cocoon/spring/SpringToAvalonDataSourceBridge.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/META-INF/cocoon/spring/SpringToAvalonDataSourceBridge.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/org/apache/cocoon/components/database/database.roles
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/org/apache/cocoon/components/database/database.roles?view=diff&rev=553872&r1=553871&r2=553872
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/org/apache/cocoon/components/database/database.roles
(original)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/resources/org/apache/cocoon/components/database/database.roles
Fri Jul  6 06:11:46 2007
@@ -18,7 +18,7 @@
 <!-- $Id$ -->
 <role-list>
 
-  <role name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
+  <role name="org.apache.avalon.excalibur.datasource.DataSourceComponentLegacySelector"
         shorthand="datasources"
         default-class="org.apache.cocoon.core.container.DefaultServiceSelector">
 	<hint shorthand="jdbc" class="org.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource"/>



Mime
View raw message