You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2003/01/16 19:09:37 UTC
cvs commit: avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/impl JavaxDataSource.java SimpleDataSourceManager.java
bloritsch 2003/01/16 10:09:37
Modified: datasource build.xml default.properties
datasource/src/java/org/apache/excalibur/datasource/impl
SimpleDataSourceManager.java
Added: datasource/src/java/org/apache/excalibur/datasource
DataSource.java
datasource/src/java/org/apache/excalibur/datasource/impl
JavaxDataSource.java
Log:
Try to simplify things. The DataSourceManager will become a 'container' for DataSource components...provide a decent wrapper for javax.sql.DataSource components
Revision Changes Path
1.2 +3 -16 avalon-sandbox/datasource/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/datasource/build.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- build.xml 24 Dec 2002 19:44:57 -0000 1.1
+++ build.xml 16 Jan 2003 18:09:37 -0000 1.2
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<project name="Excalibur Info" default="main" basedir=".">
+<project name="AvalonDataSource" default="main" basedir=".">
<property file="${user.home}/build.properties"/>
<property file="${basedir}/../ant.properties"/>
@@ -35,22 +35,9 @@
<target name="main" depends="jar" description="Build the project"/>
<target name="rebuild" depends="clean,main" description="Rebuild the project"/>
- <target name="dependencies" description="Check dependencies" unless="skip.dependencies">
- <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkCommon"/>
- <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkFramework"/>
- <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkI18N"/>
- </target>
-
- <target name="dependencies-test" depends="dist-jar, dependencies"
- description="Check unit test dependencies" unless="skip.dependencies">
- <!-- Need the jar to prevent recursive deps. -->
-
- <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkJUnit"/>
- </target>
-
<!-- Compiles the source code -->
- <target name="compile" depends="dependencies" description="Compiles the source code">
+ <target name="compile" description="Compiles the source code">
<mkdir dir="${build.classes}"/>
@@ -76,7 +63,7 @@
</target>
<!-- Compiles the unit test source code -->
- <target name="compile-test" depends="compile, dependencies-test" description="Compiles the source code">
+ <target name="compile-test" depends="compile" description="Compiles the source code">
<mkdir dir="${build.testsrc}"/>
<!-- Copy over all of the tests applying test filters -->
1.2 +7 -17 avalon-sandbox/datasource/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/avalon-sandbox/datasource/default.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- default.properties 24 Dec 2002 19:44:57 -0000 1.1
+++ default.properties 16 Jan 2003 18:09:37 -0000 1.2
@@ -5,29 +5,21 @@
# Overridden by ../default.properties and all ant.properties
# Not user-editable; use ant.properties files instead
-name=excalibur-info
-Name=Excalibur Info
-dir-name=info
+name=avalon-datasource
+Name=Avalon Datasource
+dir-name=datasource
version=1.0a
package-version=0.99
-year=2000-2002
+year=2002-2003
# --------------------------------------------------
# REQUIRED LIBRARIES
# --------------------------------------------------
-# ----- Avalon Framework, version 4.1 or later -----
-avalon-framework.home=${basedir}/../../jakarta-avalon
-avalon-framework.lib=${avalon-framework.home}/target/lib
-avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
-
-# ----- Excalibur i18n, version 1.0 or later -----
-excalibur-i18n.home=${basedir}/../i18n/dist
-excalibur-i18n.lib=${excalibur-i18n.home}
-excalibur-i18n.jar=${excalibur-i18n.lib}/excalibur-i18n-1.0.jar
+avalon-framework.jar=${basedir}/../../jakarta-avalon/target/lib/avalon-framework.jar
# ----- jakarta-site CVS module, latest version (Anakia) -----
-jakarta-site.dir=${basedir}/../../jakarta-site
+jakarta-site.dir=${basedir}/../../jakarta-avalon-site
# --------------------------------------------------
@@ -54,7 +46,7 @@
java.dir = ${src.dir}/java
conf.dir = ${src.dir}/conf
test.dir = ${src.dir}/test
-xdocs.dir = src/xdocs
+xdocs.dir = ${src.dir}/xdocs
# Set the properties for distribution directories
dist.dir = dist
@@ -68,6 +60,4 @@
# property indicating directory where all distribution archives are placed
dist.base = distributions
-
-depchecker.prefix=.
1.1 avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/DataSource.java
Index: DataSource.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.datasource;
import java.sql.Connection;
import java.sql.SQLException;
/**
* The DataSource is the abstraction we use for a single database connection
* in an Avalon application. The {@link SimpleDataSourceManager} will know how to
* work with both <code>javax.sql.DataSource</code> implementations and
* components of this class.
*/
public interface DataSource
{
/**
* Get the named connection. Please note that the DataSourceManager merely
* looks up the connection by a name. If the name does not exist, or there
* is a problem creating your connection, you will receive an exception.
* This variation is used when there are no credentials, or you will set up
* the credentials at the server.
*
* @throws SQLException if there is a problem with the connection, or if
* there is no connection bound to that name.
*
* @return The <code>java.sql.Connection</code> object.
*/
Connection getConnection() throws SQLException;
/**
* Get the named connection using the credentials passed in. Please note
* that the DataSourceManager merely looks up the connection by a name. If
* the name does not exist, or there is a problem creating your connection,
* you will receive an exception. This variation is used when you are using
* credentials supplied by the application.
*
* <p>
* <strong>TIP:</strong> If you obtain your username/password from the
* user of your application, you might want to encrypt the password while
* it is in memory. The pasword is sent to this object in the clear--so
* do take pains to ensure that the container you use does not allow
* someone to intercept calls to your DataSourceManager. If every client
* of the DataSourceManager receives its own proxy (like in Phoenix) of
* the component, then you are done. Otherwise, throw a
* <code>UnsupportedOperationException</code>.
* <p>
*
* @param user The user name to connect with.
* @param passwd The password used to connect with.
*
* @throws SQLException if there is a problem with the connection, or if
* there is no connection bound to that name.
* @throws UnsupportedOperationException if the implementation does not
* support client supplied credentials.
*
* @return The <code>java.sql.Connection</code> object.
*/
Connection getConnection( String user, String passwd )
throws SQLException;
/**
* Determines whether the implementation of this DataSourceManager supports
* user supplied credentials.
*
* @return <code>true</code> if it does, <code>false</code> if not.
*/
boolean supportsClientCredentials();
}
1.2 +8 -10 avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/impl/SimpleDataSourceManager.java
Index: SimpleDataSourceManager.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/impl/SimpleDataSourceManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SimpleDataSourceManager.java 24 Dec 2002 19:44:57 -0000 1.1
+++ SimpleDataSourceManager.java 16 Jan 2003 18:09:37 -0000 1.2
@@ -51,13 +51,13 @@
import java.sql.*;
import java.util.*;
-import javax.sql.*;
+import org.apache.excalibur.datasource.DataSource;
+import org.apache.excalibur.datasource.DataSourceManager;
+import org.apache.excalibur.datasource.util.*;
import org.apache.avalon.framework.activity.*;
import org.apache.avalon.framework.configuration.*;
import org.apache.avalon.framework.parameters.*;
-import org.apache.excalibur.datasource.*;
-import org.apache.excalibur.datasource.util.*;
/**
* The <code>SimpleDataSourceManager</code> manages all the connections via
@@ -155,9 +155,8 @@
* <pre>
* <![CDATA[
* <datasource-manager>
- * <connection name="foo" class="com.dbvendor.driver.VendorDataSource">
- * <parameter name="dbUrl" value="jdbc:dbvendor://server:port/foodb"/>
- * <parameter name="user" value="example"/>
+ * <connection name="foo" type="org.apache.excalibur.datasource.impl.ApacheDataSource">
+ * <!-- Set up the datasource according to the proper types. -->
* </connection>
* </datasource-manager>
* ]]>
@@ -174,9 +173,8 @@
for ( int i = 0; i < dataSources.length; i++ )
{
- Parameters props = Parameters.fromConfiguration(dataSources[i]);
m_datasources.put( dataSources[i].getAttribute("name"),
- setupDataSource( dataSources[i].getAttribute("type"), props )
+ setupDataSource( dataSources[i].getAttribute("type"), dataSources[i] )
);
}
}
@@ -193,7 +191,7 @@
* @throws ConfigurationException if there is a problem with the datasource
* at all.
*/
- private DataSource setupDataSource( String classname, Parameters connectionProps )
+ private DataSource setupDataSource( String classname, Configuration connectionProps )
throws ConfigurationException
{
if ( null == classname ) throw new NullPointerException("classname");
@@ -204,7 +202,7 @@
try
{
datasource = (DataSource)Thread.currentThread().getContextClassLoader().loadClass(classname).newInstance();
- BeanUtil.setBeanParameters(datasource, connectionProps);
+ //BeanUtil.setBeanParameters(datasource, connectionProps);
}
catch (Exception e)
{
1.1 avalon-sandbox/datasource/src/java/org/apache/excalibur/datasource/impl/JavaxDataSource.java
Index: JavaxDataSource.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.datasource.impl;
import org.apache.excalibur.datasource.DataSource;
import org.apache.excalibur.datasource.util.*;
import org.apache.avalon.framework.activity.*;
import org.apache.avalon.framework.configuration.*;
import org.apache.avalon.framework.parameters.*;
import java.sql.Connection;
import java.sql.SQLException;
/**
* The DataSource is the abstraction we use for a single database connection
* in an Avalon application. The {@link SimpleDataSourceManager} will know how to
* work with both <code>javax.sql.DataSource</code> implementations and
* components of this class.
*/
public class JavaxDataSource implements DataSource, Configurable
{
private javax.sql.DataSource m_datasource = null;
/**
* This will configure the <code>javax.sql.DataSource</code> from the
* database vendor's JDBC driver. Since all of those drivers follow
* the JavaBeans approach for configuration, we have provided a way to
* automatically map Parameters to that class. You can make any
* configuration settings that your vendor supports--even proprietary
* ones. The configuration snippet is similar to this:
*
* <pre>
* <datasource name="datasourceName" type="com.oracle.driver.OracleDataSource">
* <parameter name="Url" value="jdbc:oracle:thin:@host:1521:tiger"/>
* <parameter name="User" value="scott"/>
* <parameter name="Password" value="tiger1"/>
* </datasource>
* </pre>
*
* <p>
* As you can see, you only need to add a "parameter" element for each
* configuration element you want to set on the
* <code>javax.sql.DataSource</code>.
* </p>
*/
public void configure( Configuration config )
throws ConfigurationException
{
String className = config.getAttribute( "type", null );
try
{
Class klass =
Thread.currentThread().getContextClassLoader().loadClass(className);
m_datasource = (javax.sql.DataSource) klass.newInstance();
Parameters params = Parameters.fromConfiguration( config );
BeanUtil.setBeanParameters(m_datasource, params);
}
catch (Exception e)
{
throw new ConfigurationException( "Invalid DataSource", e );
}
}
/**
* Get the named connection. Please note that the DataSourceManager merely
* looks up the connection by a name. If the name does not exist, or there
* is a problem creating your connection, you will receive an exception.
* This variation is used when there are no credentials, or you will set up
* the credentials at the server.
*
* @throws SQLException if there is a problem with the connection, or if
* there is no connection bound to that name.
*
* @return The <code>java.sql.Connection</code> object.
*/
public Connection getConnection() throws SQLException
{
return m_datasource.getConnection();
}
/**
* Get the named connection using the credentials passed in. Please note
* that the DataSourceManager merely looks up the connection by a name. If
* the name does not exist, or there is a problem creating your connection,
* you will receive an exception. This variation is used when you are using
* credentials supplied by the application.
*
* @param user The user name to connect with.
* @param passwd The password used to connect with.
*
* @throws SQLException if there is a problem with the connection, or if
* there is no connection bound to that name.
* @throws UnsupportedOperationException if the implementation does not
* support client supplied credentials.
*
* @return The <code>java.sql.Connection</code> object.
*/
public Connection getConnection( String user, String passwd )
throws SQLException
{
return m_datasource.getConnection( user, passwd );
}
/**
* Determines whether the implementation of this DataSourceManager supports
* user supplied credentials.
*
* @return <code>true</code> if it does, <code>false</code> if not.
*/
public boolean supportsClientCredentials()
{
return true;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>