Class InstanceKeyDataSource

java.lang.Object
org.apache.tomcat.dbcp.dbcp2.datasources.InstanceKeyDataSource
All Implemented Interfaces:
Serializable, AutoCloseable, Wrapper, Referenceable, CommonDataSource, DataSource
Direct Known Subclasses:
PerUserPoolDataSource, SharedPoolDataSource

public abstract class InstanceKeyDataSource extends Object implements DataSource, Referenceable, Serializable, AutoCloseable

The base class for SharedPoolDataSource and PerUserPoolDataSource. Many of the configuration properties are shared and defined here. This class is declared public in order to allow particular usage with commons-beanutils; do not make direct use of it outside of commons-dbcp2.

A J2EE container will normally provide some method of initializing the DataSource whose attributes are presented as bean getters/setters and then deploying it via JNDI. It is then available to an application as a source of pooled logical connections to the database. The pool needs a source of physical connections. This source is in the form of a ConnectionPoolDataSource that can be specified via the setDataSourceName(String) used to lookup the source via JNDI.

Although normally used within a JNDI environment, A DataSource can be instantiated and initialized as any bean. In this case the ConnectionPoolDataSource will likely be instantiated in a similar manner. This class allows the physical source of connections to be attached directly to this pool using the setConnectionPoolDataSource(ConnectionPoolDataSource) method.

The dbcp package contains an adapter, DriverAdapterCPDS, that can be used to allow the use of DataSource's based on this class with JDBC driver implementations that do not supply a ConnectionPoolDataSource, but still provide a Driver implementation.

The package documentation contains an example using Apache Tomcat and JNDI and it also contains a non-JNDI example.

Since:
2.0
See Also: