public class JdbcDataSource extends org.apache.avalon.framework.logger.AbstractLogEnabled implements DataSourceComponent, org.apache.avalon.framework.activity.Disposable
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:
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")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")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")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)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.driver element is used to specify the driver to use when connecting to the
database. The specified class must be in the classpath. (Required)dburl element is the JDBC connection string which will be used to connect to
the database. (Required)user and password attributes are used to specify the user and
password for connections to the database. (Required)| Modifier and Type | Field and Description |
|---|---|
protected JdbcConnectionPool |
m_pool |
ROLE| Constructor and Description |
|---|
JdbcDataSource() |
| Modifier and Type | Method and Description |
|---|---|
void |
configure(org.apache.avalon.framework.configuration.Configuration configuration)
Configure and set up DB connection.
|
void |
dispose()
Dispose properly of the pool
|
java.sql.Connection |
getConnection()
Get the database connection
|
protected JdbcConnectionPool m_pool
public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
throws org.apache.avalon.framework.configuration.ConfigurationException
configure in interface org.apache.avalon.framework.configuration.Configurableconf - The Configuration object needed to describe the
connection.org.apache.avalon.framework.configuration.ConfigurationExceptionpublic java.sql.Connection getConnection()
throws java.sql.SQLException
getConnection in interface DataSourceComponentNoValidConnectionException - when there is no valid Connection wrapper
available in the classloader.NoAvailableConnectionException - when there are no more available
Connections in the pool.java.sql.SQLExceptionpublic void dispose()
dispose in interface org.apache.avalon.framework.activity.Disposable