Author: ate
Date: Wed Dec 5 03:22:35 2007
New Revision: 601298
URL: http://svn.apache.org/viewvc?rev=601298&view=rev
Log:
Applying patch from Joachim Müller for JS2-809: Add table schema aware
datasource proxy
See: https://issues.apache.org/jira/browse/JS2-809
Added:
portals/jetspeed-2/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/SchemaAwareDataSourceProxy.java
(with props)
Modified:
portals/jetspeed-2/trunk/etc/import/assembly/repository-datasource-spring.xml
portals/jetspeed-2/trunk/jetspeed-portal-resources/src/main/resources/webapp/WEB-INF/assembly/boot/datasource.xml
Added:
portals/jetspeed-2/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/SchemaAwareDataSourceProxy.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/SchemaAwareDataSourceProxy.java?rev=601298&view=auto
==============================================================================
---
portals/jetspeed-2/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/SchemaAwareDataSourceProxy.java
(added)
+++
portals/jetspeed-2/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/SchemaAwareDataSourceProxy.java
Wed Dec 5 03:22:35 2007
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.jetspeed.components.datasource;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
+
+/**
+ * The SchemaAwareDataSourceProxy optionally injects a schema selection into an
+ * existing database connection. It proxies a DataSource and executes an
+ * injected sql statement on every getConnection() call.
+ *
+ * Inspired by http://forum.springframework.org/showthread.php?t=10728, runtime
+ * schema switching was stripped.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Joachim Müller</a>
+ * @version $Id$
+ */
+public class SchemaAwareDataSourceProxy extends TransactionAwareDataSourceProxy
+{
+ private static final Log log =
LogFactory.getLog(SchemaAwareDataSourceProxy.class);
+
+ private String schemaSql = null;
+
+ public void setSchemaSql(String schemaSql)
+ {
+ this.schemaSql = schemaSql;
+ }
+
+ public Connection getConnection() throws SQLException
+ {
+ Connection con = super.getConnection();
+
+ if (schemaSql != null)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Setting schema by executing sql '" + schemaSql + "'
on connection " + con);
+ }
+
+ Statement stmt = con.createStatement();
+ try
+ {
+ // database specific SQL.
+ stmt.execute(schemaSql);
+ }
+ catch (Exception e)
+ {
+ log.error("Error executing table schema setting sql: '" +
schemaSql + "'.", e);
+ }
+ finally
+ {
+ stmt.close();
+ }
+ }
+
+ return con;
+ }
+}
Propchange:
portals/jetspeed-2/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/SchemaAwareDataSourceProxy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/SchemaAwareDataSourceProxy.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/datasource/SchemaAwareDataSourceProxy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
portals/jetspeed-2/trunk/etc/import/assembly/repository-datasource-spring.xml
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/etc/import/assembly/repository-datasource-spring.xml?rev=601298&r1=601297&r2=601298&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/etc/import/assembly/repository-datasource-spring.xml
(original)
+++
portals/jetspeed-2/trunk/etc/import/assembly/repository-datasource-spring.xml
Wed Dec 5 03:22:35 2007
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?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
@@ -15,48 +15,88 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
-<beans>
-
- <!-- datasource bean -->
-<!-- <bean id="JetspeedDS"
class="org.apache.jetspeed.components.rdbms.ojb.ConnectionRepositoryEntry"> -->
- <bean id="JetspeedDS" class="org.apache.commons.dbcp.BasicDataSource">
- <property name="driverClassName">
- <value>${org.apache.jetspeed.database.driver}</value>
- </property>
- <property name="url">
- <value>${org.apache.jetspeed.database.url}</value>
- </property>
- <property name="username">
- <value>${org.apache.jetspeed.database.user}</value>
- </property>
- <property name="password">
- <value>${org.apache.jetspeed.database.password}</value>
- </property>
- </bean>
-
- <bean id="ojbConfigurer"
class="org.springframework.orm.ojb.support.LocalOjbConfigurer"/>
-
- <!--
- Dynamically configures Database Platform for OJB by looking at the
connection string
- and figuring out the OJB platform using an OJB metadata utility
- Its important to get this right otherwise you will be sending the
wrong (most likely HSQL)
- flavor of SQL statements to the backend database.
- -->
- <bean id="PlatformConfigurator"
-
class="org.apache.jetspeed.components.rdbms.ojb.DatabasePlatformConfigurator"
- init-method="init"
- >
- <constructor-arg index='0'>
- <ref bean="JetspeedDS"/>
- </constructor-arg>
- <!-- JNDI Name -->
- <constructor-arg index='1'>
- <value>JetspeedDS</value>
- </constructor-arg>
- </bean>
-
- <!-- properties configurer used to pick up system properties -->
- <bean id="propertiesConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
-
-</beans>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
+<beans>
+
+ <!-- datasource bean -->
+<!-- <bean id="JetspeedDS"
class="org.apache.jetspeed.components.rdbms.ojb.ConnectionRepositoryEntry"> -->
+ <bean id="JetspeedDS" class="org.apache.commons.dbcp.BasicDataSource">
+ <property name="driverClassName">
+ <value>${org.apache.jetspeed.database.driver}</value>
+ </property>
+ <property name="url">
+ <value>${org.apache.jetspeed.database.url}</value>
+ </property>
+ <property name="username">
+ <value>${org.apache.jetspeed.database.user}</value>
+ </property>
+ <property name="password">
+ <value>${org.apache.jetspeed.database.password}</value>
+ </property>
+ </bean>
+
+ <bean id="ojbConfigurer"
class="org.springframework.orm.ojb.support.LocalOjbConfigurer"/>
+
+ <!--
+ Dynamically configures Database Platform for OJB by looking at the
connection string
+ and figuring out the OJB platform using an OJB metadata utility
+ Its important to get this right otherwise you will be sending the
wrong (most likely HSQL)
+ flavor of SQL statements to the backend database.
+ -->
+ <bean id="PlatformConfigurator"
+
class="org.apache.jetspeed.components.rdbms.ojb.DatabasePlatformConfigurator"
+ init-method="init"
+ >
+ <constructor-arg index='0'>
+ <ref bean="JetspeedDS"/>
+ </constructor-arg>
+ <!-- JNDI Name -->
+ <constructor-arg index='1'>
+ <value>JetspeedDS</value>
+ </constructor-arg>
+ </bean>
+
+ <!-- properties configurer used to pick up system properties -->
+ <bean id="propertiesConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+ <!--
+ Optional configuration for table schema aware datasource.
+
+ The way to inject the schema switching is database specific. Here only the
DB2 way
+ is shown (set current schema = xx). Oracle statement might
+ be: "alter session set current_schema=xx", PostGres
+ may look like this: "SET search_path TO xx"
+
+ The idea was taken from
http://forum.springframework.org/showthread.php?t=10728
+
+ The runtime schema switching support was dropped because it is not needed
here.
+ -->
+ <!--
+ <bean id="JetspeedDS"
+
class="org.apache.jetspeed.components.datasource.SchemaAwareDataSourceProxy">
+ <property name="targetDataSource">
+ <ref local="dataSourceTarget" />
+ </property>
+ <property name="schemaSql">
+ <value>set current schema = xx</value>
+ </property>
+ </bean>
+
+ <bean id="dataSourceTarget"
+ class="org.apache.commons.dbcp.BasicDataSource">
+ <property name="driverClassName">
+ <value>${org.apache.jetspeed.database.driver}</value>
+ </property>
+ <property name="url">
+ <value>${org.apache.jetspeed.database.url}</value>
+ </property>
+ <property name="username">
+ <value>${org.apache.jetspeed.database.user}</value>
+ </property>
+ <property name="password">
+ <value>${org.apache.jetspeed.database.password}</value>
+ </property>
+ </bean>
+ -->
+
+</beans>
Modified:
portals/jetspeed-2/trunk/jetspeed-portal-resources/src/main/resources/webapp/WEB-INF/assembly/boot/datasource.xml
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/jetspeed-portal-resources/src/main/resources/webapp/WEB-INF/assembly/boot/datasource.xml?rev=601298&r1=601297&r2=601298&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/jetspeed-portal-resources/src/main/resources/webapp/WEB-INF/assembly/boot/datasource.xml
(original)
+++
portals/jetspeed-2/trunk/jetspeed-portal-resources/src/main/resources/webapp/WEB-INF/assembly/boot/datasource.xml
Wed Dec 5 03:22:35 2007
@@ -48,6 +48,40 @@
</constructor-arg>
</bean>
+ <!--
+ Optional configuration for table schema aware
datasource.
+
+ The way to inject the schema switching is database
specific. Here only the DB2 way
+ is shown (set current schema = xx). Oracle statement
might
+ be: "alter session set current_schema=xx", PostGres
+ may look like this: "SET search_path TO xx"
+
+ The idea was taken from
http://forum.springframework.org/showthread.php?t=10728
+
+ The runtime schema switching support was dropped
because it is not needed here.
+ -->
+ <!--
+ <bean id="JetspeedDS"
+
class="org.apache.jetspeed.components.datasource.SchemaAwareDataSourceProxy">
+ <property name="targetDataSource">
+ <ref local="dataSourceTarget" />
+ </property>
+ <property name="schemaSql">
+ <value>set current schema = xx</value>
+ </property>
+ </bean>
+
+ <bean id="dataSourceTarget"
+ class="org.springframework.jndi.JndiObjectFactoryBean">
+ <property name="resourceRef">
+ <value>false</value>
+ </property>
+ <property name="jndiName">
+ <value>java:comp/env/jdbc/jetspeed</value>
+ </property>
+ </bean>
+ -->
+
<!--
Creates a JNDI-based datasource bean name "JetspeedDS". The information
provided here is merged with the basic configuration for the
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]