org.apache.avalon.excalibur.datasource
Class JdbcDataSource
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.avalon.excalibur.datasource.JdbcDataSource
- All Implemented Interfaces:
- Component, Configurable, DataSourceComponent, Disposable, LogEnabled, ThreadSafe
- public class JdbcDataSource
- extends AbstractLogEnabled
- implements DataSourceComponent, Disposable
The Default implementation for DataSources in Avalon. This uses the
normal java.sql.Connection
object and
java.sql.DriverManager
.
Configuration Example:
<jdbc>
<pool-controller min="5" max="10" connection-class="my.overrided.ConnectionClass">
<keep-alive disable="false" age="5000">select 1</keep-alive>
</pool-controller>
<auto-commit>true</auto-commit>
<driver>com.database.jdbc.JdbcDriver</driver>
<dburl>jdbc:driver://host/mydb</dburl>
<user>username</user>
<password>password</password>
</jdbc>
Configuration Attributes:
- The
min
attribute is used to set the minimum size of the DataSource pool.
When the Data Source is first initialized, the DataSource will automatically create
this number of connections so they will be ready for use. (Defaults to "1")
- The
max
attribute is used to set the maximum number of connections which
will be opened. If more concurrent connections are requested, a
NoAvailableConnectionException will be thrown. (Defaults to "3")
- The
connection-class
attribute is used to override the Connection class returned
by the DataSource from calls to getConnection(). Set this to
"org.apache.avalon.excalibur.datasource.Jdbc3Connection" to gain access to JDBC3 features.
Jdbc3Connection does not exist if your JVM does not support JDBC3.
(Defaults to "org.apache.avalon.excalibur.datasource.JdbcConnection")
- The
keep-alive
element is used to override the query used to monitor the health
of connections. If a connection has not been used for 5 seconds then before returning the
connection from a call to getConnection(), the connection is first used to ping the database
to make sure that it is still alive. Setting the disable
attribute to true will
disable this feature. Setting the age
allows the 5 second age to be overridden.
(Defaults to a query of "SELECT 1" and being enabled)
- The
auto-commit
element is used to override the default (true
)
value of the auto-commit policy. It ensures that the database connection that is returned
to you is already in the proper mode. If you use transactions in your queries, you must
set this to false.
- The
driver
element is used to specify the driver to use when connecting to the
database. The specified class must be in the classpath. (Required)
- The
dburl
element is the JDBC connection string which will be used to connect to
the database. (Required)
- The
user
and password
attributes are used to specify the user and
password for connections to the database. (Required)
- Since:
- 4.0
- Version:
- CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:14 $
- Author:
- Avalon Development Team
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
m_pool
protected JdbcConnectionPool m_pool
JdbcDataSource
public JdbcDataSource()
configure
public void configure(Configuration configuration)
throws ConfigurationException
- Configure and set up DB connection. Here we set the connection
information needed to create the Connection objects. It must
be called only once.
- Specified by:
configure
in interface Configurable
- Parameters:
configuration
- the class configurations. Must not be null
.
- Throws:
ConfigurationException
getConnection
public java.sql.Connection getConnection()
throws java.sql.SQLException
- Get the database connection
- Specified by:
getConnection
in interface DataSourceComponent
- Returns:
- Connection a valid connection for you to use
- Throws:
java.sql.SQLException
dispose
public void dispose()
- Dispose properly of the pool
- Specified by:
dispose
in interface Disposable
Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.