org.apache.torque.dsfactory
Class AbstractDataSourceFactory

java.lang.Object
  extended by org.apache.torque.dsfactory.AbstractDataSourceFactory
All Implemented Interfaces:
DataSourceFactory
Direct Known Subclasses:
JndiDataSourceFactory, PerUserPoolDataSourceFactory, SharedPoolDataSourceFactory

public abstract class AbstractDataSourceFactory
extends java.lang.Object
implements DataSourceFactory

A class that contains common functionality of the factories in this package.

Version:
$Id: AbstractDataSourceFactory.java 473821 2006-11-11 22:37:25Z tv $
Author:
John McNally, Henning P. Schmiedehausen

Field Summary
static java.lang.String CONNECTION_KEY
          "connection" Key for the configuration
static java.lang.String DEFAULT_CONNECTION_KEY
          "defaults.connection" Key for the configuration
static java.lang.String DEFAULT_POOL_KEY
          "defaults.pool" Key for the configuration
static java.lang.String DEFAULT_SCHEMA_KEY
          default schema name for the configuration
static java.lang.String DEFAULTS_KEY
          "defaults" Key for the configuration
static java.lang.String POOL_KEY
          "pool" Key for the configuration
static java.lang.String SCHEMA_KEY
          "schema" Key for the configuration
 
Fields inherited from interface org.apache.torque.dsfactory.DataSourceFactory
DSFACTORY_KEY, FACTORY_KEY
 
Constructor Summary
AbstractDataSourceFactory()
           
 
Method Summary
protected  void applyConfiguration(org.apache.commons.configuration.Configuration c, java.lang.Object o)
          Iterate over a Configuration subset and apply all properties to a passed object which must contain Bean setter and getter
abstract  javax.sql.DataSource getDataSource()
           
 java.lang.String getSchema()
          Deprecated. use DatabaseInfo.setSchema() instead. Will be removed in a future version of Torque.
protected  javax.sql.ConnectionPoolDataSource initCPDS(org.apache.commons.configuration.Configuration configuration)
          Initializes the ConnectionPoolDataSource.
 void initialize(org.apache.commons.configuration.Configuration configuration)
          Initialize the factory.
protected  void setProperty(java.lang.String property, org.apache.commons.configuration.Configuration c, java.lang.Object ds)
          Encapsulates setting configuration properties on DataSource objects.
 void setSchema(java.lang.String schema)
          Sets the current schema for the database connection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.torque.dsfactory.DataSourceFactory
close
 

Field Detail

POOL_KEY

public static final java.lang.String POOL_KEY
"pool" Key for the configuration

See Also:
Constant Field Values

CONNECTION_KEY

public static final java.lang.String CONNECTION_KEY
"connection" Key for the configuration

See Also:
Constant Field Values

SCHEMA_KEY

public static final java.lang.String SCHEMA_KEY
"schema" Key for the configuration

See Also:
Constant Field Values

DEFAULTS_KEY

public static final java.lang.String DEFAULTS_KEY
"defaults" Key for the configuration

See Also:
Constant Field Values

DEFAULT_POOL_KEY

public static final java.lang.String DEFAULT_POOL_KEY
"defaults.pool" Key for the configuration

See Also:
Constant Field Values

DEFAULT_CONNECTION_KEY

public static final java.lang.String DEFAULT_CONNECTION_KEY
"defaults.connection" Key for the configuration

See Also:
Constant Field Values

DEFAULT_SCHEMA_KEY

public static final java.lang.String DEFAULT_SCHEMA_KEY
default schema name for the configuration

See Also:
Constant Field Values
Constructor Detail

AbstractDataSourceFactory

public AbstractDataSourceFactory()
Method Detail

setProperty

protected void setProperty(java.lang.String property,
                           org.apache.commons.configuration.Configuration c,
                           java.lang.Object ds)
                    throws java.lang.Exception
Encapsulates setting configuration properties on DataSource objects.

Parameters:
property - the property to read from the configuration
c - the configuration to read the property from
ds - the DataSource instance to write the property to
Throws:
java.lang.Exception - if anything goes wrong

applyConfiguration

protected void applyConfiguration(org.apache.commons.configuration.Configuration c,
                                  java.lang.Object o)
                           throws TorqueException
Iterate over a Configuration subset and apply all properties to a passed object which must contain Bean setter and getter

Parameters:
c - The configuration subset
o - The object to apply the properties to
Throws:
TorqueException - if a property set fails

initCPDS

protected javax.sql.ConnectionPoolDataSource initCPDS(org.apache.commons.configuration.Configuration configuration)
                                               throws TorqueException
Initializes the ConnectionPoolDataSource.

Parameters:
configuration - where to read the settings from
Returns:
a configured ConnectionPoolDataSource
Throws:
TorqueException - if a property set fails

setSchema

public void setSchema(java.lang.String schema)
Sets the current schema for the database connection

Specified by:
setSchema in interface DataSourceFactory
Parameters:
schema - The current schema name

getSchema

public java.lang.String getSchema()
Deprecated. use DatabaseInfo.setSchema() instead. Will be removed in a future version of Torque.

This method returns the current schema for the database connection

Specified by:
getSchema in interface DataSourceFactory
Returns:
The current schema name. Null means, no schema has been set.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getDataSource

public abstract javax.sql.DataSource getDataSource()
                                            throws TorqueException
Specified by:
getDataSource in interface DataSourceFactory
Returns:
the DataSource configured by the factory.
Throws:
TorqueException - if the source can't be returned

initialize

public void initialize(org.apache.commons.configuration.Configuration configuration)
                throws TorqueException
Initialize the factory.

Specified by:
initialize in interface DataSourceFactory
Parameters:
configuration - where to load the factory settings from
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.