cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r485621 - in /cocoon/trunk/blocks/cocoon-databases: cocoon-databases-impl/src/main/java/org/apache/cocoon/components/database/ cocoon-databases-impl/src/main/java/org/apache/cocoon/components/language/ cocoon-databases-impl/src/main/java/or...
Date Mon, 11 Dec 2006 11:28:44 GMT
Author: cziegeler
Date: Mon Dec 11 03:28:35 2006
New Revision: 485621

URL: http://svn.apache.org/viewvc?view=rev&rev=485621
Log:
Add support for iBatis to use configured Excalibur data sources in iBatis.

Added:
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/ibatis/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/ibatis/ExcaliburDataSourceFactory.java
  (with props)
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/datasource/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/datasource/DataSourceFactory.java
  (with props)
Removed:
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/components/database/
    cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/components/language/

Added: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/ibatis/ExcaliburDataSourceFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/ibatis/ExcaliburDataSourceFactory.java?view=auto&rev=485621
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/ibatis/ExcaliburDataSourceFactory.java
(added)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/ibatis/ExcaliburDataSourceFactory.java
Mon Dec 11 03:28:35 2006
@@ -0,0 +1,110 @@
+/*
+ * 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.cocoon.databases.ibatis;
+
+import java.io.PrintWriter;
+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.CascadingRuntimeException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.environment.internal.EnvironmentHelper;
+
+import com.ibatis.sqlmap.engine.datasource.DataSourceFactory;
+
+/**
+ * This is an implementation if iBatis DataSourceFactory allowing to use
+ * a reference to an excalibur data source in the iBatis configuration.
+ * The configuration in the iBatis sqlMapConfig looks like this:
+ * <dataSource type="org.apache.cocoon.databases.ibatis.ExcaliburDataSourceFactory">
+ *   <property name="connection" value="Name of the Excalibur data source from the
cocoon.xconf"/>
+ * </dataSource>
+ *
+ * @version $Id$
+ * @since 2.1.10
+ */
+public class ExcaliburDataSourceFactory implements DataSourceFactory {
+
+    protected DataSourceComponent datasource;
+
+    public DataSource getDataSource() {
+        return new DataSourceWrapper(this.datasource);
+    }
+
+    /**
+     * @see com.ibatis.sqlmap.engine.datasource.DataSourceFactory#initialize(java.util.Map)
+     */
+    public void initialize(Map values) {
+        final String connection = (String)values.get("connection");
+        if ( connection == null ) {
+            throw new RuntimeException("Connection configuration is missing for " + this.getClass().getName()
+ "." +
+                    " Have a look at the iBatis sqlMapConfig and check the 'connection' property
for the data source.");
+        }
+        // get the component manager
+        final ServiceManager manager = EnvironmentHelper.getSitemapServiceManager();
+        if ( manager == null ) {
+            throw new RuntimeException("Cocoon sitemap service manager is not available for
" + this.getClass().getName() + "." +
+            " Make sure that you're initializing iBatis during an active request and not
on startup.");            
+        }
+        try {
+            this.datasource = (DataSourceComponent)manager.lookup(DataSourceComponent.ROLE
+ '/' + connection);
+        } catch (ServiceException e) {
+            throw new CascadingRuntimeException("Unable to lookup data source with name "
+ connection + "." +
+                    " Check the cocoon.xconf and the iBatis sqlMapConfig.", e);         
      
+        }
+    }
+
+    protected static final class DataSourceWrapper implements DataSource {
+
+        protected final DataSourceComponent datasource;
+        protected PrintWriter writer = new PrintWriter(System.out);
+        protected int timeout = 0;
+
+        public DataSourceWrapper(DataSourceComponent d) {
+            this.datasource = d;
+        }
+
+        public Connection getConnection() throws SQLException {
+            return this.datasource.getConnection();
+        }
+
+        public Connection getConnection(String username, String password) throws SQLException
{
+            return null;
+        }
+
+        public int getLoginTimeout() throws SQLException {
+            return this.timeout;
+        }
+
+        public PrintWriter getLogWriter() throws SQLException {
+            return this.writer;
+        }
+
+        public void setLoginTimeout(int seconds) throws SQLException {
+            this.timeout = seconds;
+        }
+
+        public void setLogWriter(PrintWriter out) throws SQLException {
+            this.writer = out;
+        }       
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/ibatis/ExcaliburDataSourceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-impl/src/main/java/org/apache/cocoon/databases/ibatis/ExcaliburDataSourceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/datasource/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/datasource/DataSourceFactory.java?view=auto&rev=485621
==============================================================================
--- cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/datasource/DataSourceFactory.java
(added)
+++ cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/datasource/DataSourceFactory.java
Mon Dec 11 03:28:35 2006
@@ -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 com.ibatis.sqlmap.engine.datasource;
+
+import javax.sql.DataSource;
+import java.util.Map;
+
+/**
+ * Mock class providing the declarations required to compile the Cocoon code when
+ * the actual library is not present.
+ *
+ * @version $Id$
+ * @since 2.1.10
+ */
+public interface DataSourceFactory {
+
+    void initialize(Map map);
+
+    DataSource getDataSource();
+}

Propchange: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/datasource/DataSourceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-databases/cocoon-databases-mocks/src/main/java/com/ibatis/sqlmap/engine/datasource/DataSourceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message