Save This Page
Home » commons-dbcp-1.2.2-src » org.apache.commons » dbcp » datasources » [javadoc | source]
org.apache.commons.dbcp.datasources
abstract public class: InstanceKeyDataSource [javadoc | source]
java.lang.Object
   org.apache.commons.dbcp.datasources.InstanceKeyDataSource

All Implemented Interfaces:
    DataSource, Referenceable, Serializable

Direct Known Subclasses:
    PerUserPoolDataSource, SharedPoolDataSource

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-dbcp.

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, org.apache.commons.dbcp.cpdsadapter.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 java.sql.Driver implementation.

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

Field Summary
protected static final  int UNKNOWN_TRANSACTIONISOLATION    Internal constant to indicate the level is not set. 
 Properties jndiEnvironment    Environment that may be used to set up a jndi initial context. 
protected  String instanceKey     
Constructor:
 public InstanceKeyDataSource() 
Method from org.apache.commons.dbcp.datasources.InstanceKeyDataSource Summary:
assertInitializationAllowed,   close,   getConnection,   getConnection,   getConnectionPoolDataSource,   getDataSourceName,   getDefaultTransactionIsolation,   getDescription,   getJndiEnvironment,   getLogWriter,   getLoginTimeout,   getMinEvictableIdleTimeMillis,   getNumTestsPerEvictionRun,   getPooledConnectionAndInfo,   getReference,   getTestOnBorrow,   getTestOnReturn,   getTestWhileIdle,   getTimeBetweenEvictionRunsMillis,   getValidationQuery,   isDefaultAutoCommit,   isDefaultReadOnly,   isRollbackAfterValidation,   isTestOnBorrow,   isTestOnReturn,   isTestWhileIdle,   setConnectionPoolDataSource,   setDataSourceName,   setDefaultAutoCommit,   setDefaultReadOnly,   setDefaultTransactionIsolation,   setDescription,   setJndiEnvironment,   setLogWriter,   setLoginTimeout,   setMinEvictableIdleTimeMillis,   setNumTestsPerEvictionRun,   setRollbackAfterValidation,   setTestOnBorrow,   setTestOnReturn,   setTestWhileIdle,   setTimeBetweenEvictionRunsMillis,   setValidationQuery,   setupDefaults,   testCPDS,   whenExhaustedAction
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.dbcp.datasources.InstanceKeyDataSource Detail:
 protected  void assertInitializationAllowed() throws IllegalStateException 
    Throws an IllegalStateException, if a PooledConnection has already been requested.
 abstract public  void close() throws Exception
    Close pool being maintained by this datasource.
 public Connection getConnection() throws SQLException 
    Attempt to establish a database connection.
 public Connection getConnection(String username,
    String password) throws SQLException 
    Attempt to establish a database connection.
 public ConnectionPoolDataSource getConnectionPoolDataSource() 
    Get the value of connectionPoolDataSource. This method will return null, if the backing datasource is being accessed via jndi.
 public String getDataSourceName() 
    Get the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the datasource from a jndi service provider.
 public int getDefaultTransactionIsolation() 
    Get the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setTransactionIsolation(int). If this method returns -1, the default is JDBC driver dependent.
 public String getDescription() 
    Get the description. This property is defined by jdbc as for use with GUI (or other) tools that might deploy the datasource. It serves no internal purpose.
 public String getJndiEnvironment(String key) 
    Get the value of jndiEnvironment which is used when instantiating a jndi InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource.
 public PrintWriter getLogWriter() 
    Get the value of logWriter.
 public int getLoginTimeout() 
    Get the value of loginTimeout.
 public int getMinEvictableIdleTimeMillis() 
    Returns the minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).
 public int getNumTestsPerEvictionRun() 
    Returns the number of objects to examine during each run of the idle object evictor thread (if any).
 abstract protected PooledConnectionAndInfo getPooledConnectionAndInfo(String username,
    String password) throws SQLException
 public Reference getReference() throws NamingException 
    Retrieves the Reference of this object. Note: InstanceKeyDataSource subclasses should override this method. The implementaion included below is not robust and will be removed at the next major version DBCP release.
 public boolean getTestOnBorrow() 
    When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned by the {*link #borrowObject} method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
 public boolean getTestOnReturn() 
    When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned to the pool within the {*link #returnObject}.
 public boolean getTestWhileIdle() 
    When true, objects will be {*link PoolableObjectFactory#validateObject validated} by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool.
 public int getTimeBetweenEvictionRunsMillis() 
    Returns the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.
 public String getValidationQuery() 
    The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row.
 public boolean isDefaultAutoCommit() 
    Get the value of defaultAutoCommit, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setAutoCommit(boolean). The default is true.
 public boolean isDefaultReadOnly() 
    Get the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setReadOnly(boolean). The default is false.
 public boolean isRollbackAfterValidation() 
    Whether a rollback will be issued after executing the SQL query that will be used to validate connections from this pool before returning them to the caller.
 public final boolean isTestOnBorrow() 
 public final boolean isTestOnReturn() 
 public final boolean isTestWhileIdle() 
 public  void setConnectionPoolDataSource(ConnectionPoolDataSource v) 
    Set the backend ConnectionPoolDataSource. This property should not be set if using jndi to access the datasource.
 public  void setDataSourceName(String v) 
    Set the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the datasource from a jndi service provider.
 public  void setDefaultAutoCommit(boolean v) 
    Set the value of defaultAutoCommit, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setAutoCommit(boolean). The default is true.
 public  void setDefaultReadOnly(boolean v) 
    Set the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setReadOnly(boolean). The default is false.
 public  void setDefaultTransactionIsolation(int v) 
    Set the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setTransactionIsolation(int). The default is JDBC driver dependent.
 public  void setDescription(String v) 
    Set the description. This property is defined by jdbc as for use with GUI (or other) tools that might deploy the datasource. It serves no internal purpose.
 public  void setJndiEnvironment(String key,
    String value) 
    Sets the value of the given JNDI environment property to be used when instantiating a JNDI InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource.
 public  void setLogWriter(PrintWriter v) 
    Set the value of logWriter.
 public  void setLoginTimeout(int v) 
    Set the value of loginTimeout.
 public  void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) 
    Sets the minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any). When non-positive, no objects will be evicted from the pool due to idle time alone.
 public  void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) 
    Sets the number of objects to examine during each run of the idle object evictor thread (if any).

    When a negative value is supplied, ceil({*link #numIdle})/abs({*link #getNumTestsPerEvictionRun}) tests will be run. I.e., when the value is -n, roughly one nth of the idle objects will be tested per run.

 public  void setRollbackAfterValidation(boolean rollbackAfterValidation) 
    Whether a rollback will be issued after executing the SQL query that will be used to validate connections from this pool before returning them to the caller. Default behavior is NOT to issue a rollback. The setting will only have an effect if a validation query is set
 public  void setTestOnBorrow(boolean testOnBorrow) 
    When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned by the {*link #borrowObject} method. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. For a true value to have any effect, the validationQuery property must be set to a non-null string.
 public  void setTestOnReturn(boolean testOnReturn) 
    When true, objects will be {*link PoolableObjectFactory#validateObject validated} before being returned to the pool within the {*link #returnObject}. For a true value to have any effect, the validationQuery property must be set to a non-null string.
 public  void setTestWhileIdle(boolean testWhileIdle) 
    When true, objects will be {*link PoolableObjectFactory#validateObject validated} by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool. For a true value to have any effect, the validationQuery property must be set to a non-null string.
 public  void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) 
    Sets the number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.
 public  void setValidationQuery(String validationQuery) 
    The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row. Default behavior is to test the connection when it is borrowed.
 abstract protected  void setupDefaults(Connection con,
    String username) throws SQLException
 protected ConnectionPoolDataSource testCPDS(String username,
    String password) throws SQLException, NamingException 
 protected byte whenExhaustedAction(int maxActive,
    int maxWait)