You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2004/03/16 14:37:38 UTC
cvs commit: avalon-components/cornerstone/datasources/impl/src/java/org/apache/avalon/cornerstone/blocks/datasources DefaultDataSourceSelector-schema.xml DefaultDataSourceSelector.java DefaultDataSourceSelector.xinfo package.html
mcconnell 2004/03/16 05:37:38
Added: cornerstone/datasources/api .cvsignore project.xml
cornerstone/datasources/api/src/java/org/apache/avalon/cornerstone/services/datasources
DataSourceSelector.java package.html
cornerstone/datasources/impl .cvsignore maven.xml
project.properties project.xml
cornerstone/datasources/impl/conf block.xml config.xml
cornerstone/datasources/impl/src/java/org/apache/avalon/cornerstone/blocks/datasources
DefaultDataSourceSelector-schema.xml
DefaultDataSourceSelector.java
DefaultDataSourceSelector.xinfo package.html
Log:
Migrate datasources to use the avalon tags (while maintaining phoenix legacy). Bumped impl version reflecting shift in dependency from deprecated excalibur versions to clean excalibur versions.
Revision Changes Path
1.1 avalon-components/cornerstone/datasources/api/.cvsignore
Index: .cvsignore
===================================================================
maven.log
velocity.log
build.properties
target
maven.log
1.1 avalon-components/cornerstone/datasources/api/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<extend>${basedir}/../../project.xml</extend>
<groupId>cornerstone-datasources</groupId>
<id>cornerstone-datasources-api</id>
<name>Cornerstone Datasources API</name>
<currentVersion>1.0</currentVersion>
<package>org.apache.avalon.cornerstone.services.datasources</package>
<inceptionYear>2001</inceptionYear>
<shortDescription>Cornerstone Datasources API</shortDescription>
<dependencies>
<!-- avalon dependencies -->
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.1.5</version>
</dependency>
</dependencies>
</project>
1.1 avalon-components/cornerstone/datasources/api/src/java/org/apache/avalon/cornerstone/services/datasources/DataSourceSelector.java
Index: DataSourceSelector.java
===================================================================
/*
* Copyright 1999-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.avalon.cornerstone.services.datasources;
import org.apache.avalon.framework.service.ServiceSelector;
/**
* DataSourceSelector
*
* @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a>
*/
public interface DataSourceSelector
extends ServiceSelector
{
String ROLE = DataSourceSelector.class.getName();
}
1.1 avalon-components/cornerstone/datasources/api/src/java/org/apache/avalon/cornerstone/services/datasources/package.html
Index: package.html
===================================================================
<body>
Defintion of the datasources service.
</body>
1.1 avalon-components/cornerstone/datasources/impl/.cvsignore
Index: .cvsignore
===================================================================
maven.log
velocity.log
build.properties
target
maven.log
1.1 avalon-components/cornerstone/datasources/impl/maven.xml
Index: maven.xml
===================================================================
<project default="jar:install-snapshot">
<postGoal name="java:prepare-filesystem">
<attainGoal name="avalon:meta"/>
</postGoal>
</project>
1.1 avalon-components/cornerstone/datasources/impl/project.properties
Index: project.properties
===================================================================
#
# set the meta-info postfix to xtype so we pick up classic avalon
# ahead of phoneix legacy content
#
avalon.meta.type.postfix=xtype
1.1 avalon-components/cornerstone/datasources/impl/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<extend>${basedir}/../../project.xml</extend>
<groupId>cornerstone-datasources</groupId>
<id>cornerstone-datasources-impl</id>
<name>Cornerstone Datasource</name>
<!-- candidate 2.0 due to excalibur dependencies -->
<currentVersion>SNAPSHOT</currentVersion>
<package>org.apache.avalon.cornerstone.blocks.datasources</package>
<inceptionYear>2001</inceptionYear>
<shortDescription>Cornerstone Datasource Selector Implementation</shortDescription>
<dependencies>
<!-- cornerstone dependencies -->
<dependency>
<groupId>cornerstone-datasources</groupId>
<artifactId>cornerstone-datasources-api</artifactId>
<version>1.0</version>
</dependency>
<!-- excalibur dependencies -->
<dependency>
<groupId>excalibur-pool</groupId>
<artifactId>excalibur-pool-api</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<groupId>excalibur-pool</groupId>
<artifactId>excalibur-pool-impl</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<groupId>excalibur-datasource</groupId>
<artifactId>excalibur-datasource</artifactId>
<version>1.1.1</version>
</dependency>
<!-- avalon dependencies -->
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.1.5</version>
</dependency>
<!-- pre JDK 1.4 dependencies -->
<dependency>
<id>xml-apis</id>
<version>1.0.b2</version>
<url>http://xml.apache.org/xerces2-j/</url>
</dependency>
<dependency>
<id>xerces</id>
<version>2.2.1</version>
<url>http://xml.apache.org/xerces2-j/</url>
</dependency>
</dependencies>
</project>
1.1 avalon-components/cornerstone/datasources/impl/conf/block.xml
Index: block.xml
===================================================================
<!--
Thread Block deployment directive.
-->
<container name="datasources">
<services>
<service type="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector">
<source>manager</source>
</service>
</services>
<classloader>
<classpath>
<repository>
<resource id="excalibur-pool:excalibur-pool" version="1.2"/>
<resource id="excalibur-datasource:excalibur-datasource" version="1.1.1"/>
<resource id="cornerstone-datasources:cornerstone-datasources-api" version="1.0"/>
<resource id="cornerstone-datasources:cornerstone-datasources-impl" version="1.0"/>
</repository>
</classpath>
</classloader>
<component name="manager"
class="org.apache.avalon.cornerstone.blocks.datasources.DefaultDataSourceSelector"
activation="true">
</component>
</container>
1.1 avalon-components/cornerstone/datasources/impl/conf/config.xml
Index: config.xml
===================================================================
<targets>
<target path="/datasources/manager">
<configuration>
<!-- add datasources configs here -->
</configuration>
</target>
</targets>
1.1 avalon-components/cornerstone/datasources/impl/src/java/org/apache/avalon/cornerstone/blocks/datasources/DefaultDataSourceSelector-schema.xml
Index: DefaultDataSourceSelector-schema.xml
===================================================================
<?xml version="1.0"?>
<grammar
xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
xmlns:a="http://jakarta.apache.org/phoenix/schema-annotations/1.0"
>
<start>
<element name="root">
<choice>
<element name="data-sources">
<oneOrMore>
<ref name="datasource"/>
</oneOrMore>
</element>
<oneOrMore>
<ref name="datasource"/>
</oneOrMore>
</choice>
</element>
</start>
<define name="datasource" combine="choice">
<a:description>JDBC Data Source</a:description>
<element name="data-source">
<attribute name="name"/>
<attribute name="class"><value>org.apache.avalon.excalibur.datasource.JdbcDataSource</value></attribute>
<interleave>
<element name="pool-controller">
<attribute name="min">
<data type="integer">
<param name="minInclusive">1</param>
</data>
</attribute>
<attribute name="max">
<data type="integer">
<param name="minInclusive">1</param>
</data>
</attribute>
<optional>
<attribute name="connection-class"/>
<element name="keep-alive"><text/></element>
</optional>
</element>
<element name="auto-commit"><data type="boolean"/></element>
<element name="driver"><text/></element>
<element name="dburl"><text/></element>
<optional>
<element name="user"><text/></element>
<element name="password"><text/></element>
</optional>
</interleave>
</element>
</define>
</grammar>
1.1 avalon-components/cornerstone/datasources/impl/src/java/org/apache/avalon/cornerstone/blocks/datasources/DefaultDataSourceSelector.java
Index: DefaultDataSourceSelector.java
===================================================================
/*
* Copyright 1999-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.avalon.cornerstone.blocks.datasources;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
import org.apache.avalon.excalibur.datasource.DataSourceComponent;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.service.ServiceException;
/**
* A default implementation for DataSourceSelector.
* The Configuration is like this:
*
* <pre>
* <myBlock>
* <data-source name="<i>default</i>"
* class="<i>org.apache.avalon.excalibur.datasource.JdbcDataSource</i>">
* <!-- configuration for JdbcDataSource -->
* <pool-controller min="<i>5</i>" max="<i>10</i>" connection-class="<i>my.overrided.ConnectionClass</i>">
* <keep-alive>select 1</keep-alive>
* </pool-controller>
* <driver><i>com.database.jdbc.JdbcDriver</i></driver>
* <dburl><i>jdbc:driver://host/mydb</i></dburl>
* <user><i>username</i></user>
* <password><i>password</i></password>
* </data-source>
* </myBlock>
* </pre>
*
* @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a>
* @avalon.component name="data-source-selector" lifestyle="singleton"
* @avalon.service type="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector"
*/
public class DefaultDataSourceSelector
extends AbstractLogEnabled
implements DataSourceSelector, Contextualizable, Configurable, Initializable, Disposable
{
private Configuration m_configuration;
private Map m_dataSources;
private String m_blockName;
/**
* Contextualization of the component by the container.
* @param context the supplied context object
* @avalon.entry key="urn:avalon:name"
*/
public void contextualize( final Context context )
throws ContextException
{
try
{
m_blockName = (String) context.get( "urn:avalon:name" );
}
catch( Throwable e )
{
// handle legacy scenario
try
{
m_blockName = (String)context.get( "block.name" );
}
catch( Throwable ee )
{
m_blockName = "DataSourceSelector/" + System.identityHashCode( this );
}
}
}
/**
* @avalon.configuration schema="relax-ng"
*/
public void configure( final Configuration configuration )
{
m_configuration = configuration;
}
public void initialize()
throws Exception
{
m_dataSources = new HashMap();
Configuration[] dataSourceConfs = getDataSourceConfig();
for( int i = 0; i < dataSourceConfs.length; i++ )
{
final Configuration dataSourceConf = dataSourceConfs[ i ];
final String name = dataSourceConf.getAttribute( "name" );
final String clazz = dataSourceConf.getAttribute( "class" );
final String driver = dataSourceConf.getChild( "driver", true ).getValue( "" );
final ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
DataSourceComponent component = null;
if( null == classLoader )
{
if( !"".equals( driver ) )
{
Class.forName( driver, true, Thread.currentThread().getContextClassLoader() );
}
component = (DataSourceComponent)Class.forName( clazz ).newInstance();
}
else
{
if( !"".equals( driver ) )
{
classLoader.loadClass( driver );
}
component = (DataSourceComponent)classLoader.loadClass( clazz ).newInstance();
}
if( component instanceof LogEnabled )
{
setupLogger( component, name );
}
component.configure( dataSourceConf );
m_dataSources.put( name, component );
if( getLogger().isInfoEnabled() )
{
getLogger().info( "DataSource " + name + " ready" );
}
}
}
private Configuration[] getDataSourceConfig()
{
final Configuration head =
m_configuration.getChild( "data-sources" );
if( 0 != head.getChildren().length )
{
final String message =
"WARNING: Child node <data-sources/> in " +
"configuration of component named " + m_blockName +
" has been deprecated. Please put <data-source/> elements" +
" in root configuration element";
getLogger().warn( message );
System.out.println( message );
return head.getChildren( "data-source" );
}
else
{
return m_configuration.getChildren( "data-source" );
}
}
public void dispose()
{
if( getLogger().isDebugEnabled() )
{
getLogger().debug( "disposal" );
}
final Iterator keys = m_dataSources.keySet().iterator();
while( keys.hasNext() )
{
final DataSourceComponent dsc =
(DataSourceComponent)m_dataSources.get( keys.next() );
if( dsc instanceof Disposable )
{
( (Disposable)dsc ).dispose();
}
}
}
public boolean isSelectable( final Object hint )
{
return m_dataSources.containsKey( hint );
}
public Object select( final Object hint )
throws ServiceException
{
final Object component = m_dataSources.get( hint );
if( null == component )
{
throw new ServiceException( hint.toString(), "Unable to provide DataSourceComponent for " + hint );
}
return component;
}
public void release( final Object component )
{
//do nothing
}
}
1.1 avalon-components/cornerstone/datasources/impl/src/java/org/apache/avalon/cornerstone/blocks/datasources/DefaultDataSourceSelector.xinfo
Index: DefaultDataSourceSelector.xinfo
===================================================================
<?xml version="1.0"?>
<!DOCTYPE blockinfo PUBLIC "-//PHOENIX/Block Info DTD Version 1.0//EN"
"http://jakarta.apache.org/avalon/dtds/phoenix/blockinfo_1_0.dtd">
<blockinfo>
<block>
<version>1.0</version>
<schema-type>relax-ng</schema-type>
</block>
<services>
<service name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector"/>
</services>
</blockinfo>
1.1 avalon-components/cornerstone/datasources/impl/src/java/org/apache/avalon/cornerstone/blocks/datasources/package.html
Index: package.html
===================================================================
<body>
Default implementation of a datasource manager.
</body>
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org